Skip to content

perf(history): intern parseHref and skip sanitize on simple paths - #8089

Open
anonrig wants to merge 1 commit into
TanStack:mainfrom
anonrig:perf/parse-href-fast-path
Open

perf(history): intern parseHref and skip sanitize on simple paths#8089
anonrig wants to merge 1 commit into
TanStack:mainfrom
anonrig:perf/parse-href-fast-path

Conversation

@anonrig

@anonrig anonrig commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Split out of #8085 so bundle size and performance can be measured independently.

Repeated pushes of the same href reuse the last split. Paths that start with a single slash and have no query, hash, or control characters skip the sanitize regex. Open-redirect cases still go through sanitizePath.

Also treats query/hash markers at offset 0 as delimiters, so ?tab=one and #section stay out of the pathname.

Test plan

  • packages/history/tests/parseHref.test.ts

Summary by CodeRabbit

  • Bug Fixes

    • Fixed handling of query-only, hash-only, and query-plus-hash links so their path remains empty while query and hash values are preserved.
    • Improved history link processing for more consistent navigation behavior.
  • Performance

    • Optimized repeated parsing of identical links for faster history updates.

Repeated pushes of the same href reuse the last split. Paths that start
with a single slash and have no query, hash, or control characters skip
the sanitize regex. Query-only and hash-only hrefs keep those markers
out of the pathname.
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b02a8fe1-60b1-44cd-846d-95447f3a84b0

📥 Commits

Reviewing files that changed from the base of the PR and between f97188f and fa7b7fd.

📒 Files selected for processing (2)
  • packages/history/src/index.ts
  • packages/history/tests/parseHref.test.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The history package now caches parsed href components, uses a fast path for simple paths, centralizes history-state creation, and adds tests for query-only and hash-only href parsing.

Changes

History href parsing

Layer / File(s) Summary
History state and parsing cache
packages/history/src/index.ts
parseHref caches repeated hrefs, uses a fast path for simple absolute paths, and centralizes default history-state creation.
Sanitized parsing and component validation
packages/history/src/index.ts, packages/history/tests/parseHref.test.ts
Sanitized parsing caches parsed components and separates pathname, search, and hash values for query-only, hash-only, and ?# hrefs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to fa7b7

This is a localized history URL parsing optimization with targeted test updates, and no actionable merge-blocking risk remains beyond normal checks and review.

Possibly related PRs

  • TanStack/router#8085: Both changes modify parseHref with caching, fast-path parsing, and shared history-state handling.

Suggested labels: package: history

Suggested reviewers: sheraff

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main parseHref performance changes in the history package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant