Skip to content

Conversation

@tannerlinsley
Copy link
Member

@tannerlinsley tannerlinsley commented Aug 27, 2025

Summary by CodeRabbit

  • New Features
    • Location objects now include a URL object and fullPath; internal links use url.href.
    • Added optional URL rewrite hooks for reading and writing locations.
    • Browser and hash histories now parse from full href and generate absolute URLs.
    • Improved URL parsing with safe fallbacks for malformed/relative inputs.
    • Reload navigations derive href from location.url.href for accurate reload behavior.

@nx-cloud
Copy link

nx-cloud bot commented Aug 27, 2025

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 2174cd8

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 6m 3s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 18s View ↗

☁️ Nx Cloud last updated this comment at 2025-08-27 21:07:14 UTC

@TanStack TanStack deleted a comment from coderabbitai bot Aug 27, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds URL-centric location handling across history and routers: locations now carry a URL object and fullPath; parsing uses full href; hash/browser histories generate absolute URLs; link components use location.url.href; router introduces rewrite hooks (toURL/fromURL) and derives reload href from location.url.href.

Changes

Cohort / File(s) Summary
History: URL-aware parsing and href generation
packages/history/src/index.ts
Adds url: URL to ParsedPath/HistoryLocation; parseHref now builds/stores URL with fallbacks; browser history parses from full window.location.href; hash history createHref returns absolute URLs; minor typing rename for createHref param.
Router-core: Location shape expansion
packages/router-core/src/location.ts
Extends ParsedLocation with url: URL, fullPath, search, searchStr, state, hash, maskedLocation?, unmaskOnReload?. Updates comments noting href deprecation path. No runtime logic here.
Router-core: Rewrite hooks and URL flow
packages/router-core/src/router.ts
Adds RouterOptions.rewrite with toURL/fromURL hooks; parse/build propagate url and fullPath; href set to fullPath; navigate() uses location.url.href for reloadDocument when href absent; applies rewrite on read/write paths.
React bindings: Link href sourcing from URL
packages/react-router/src/link.tsx
useLinkProps now uses next.maskedLocation.url.href or next.url.href directly, removing router.history.createHref for internal links.
Solid bindings: Link href sourcing from URL
packages/solid-router/src/link.tsx
useLinkProps returns maskedLocation.url.href or nextLocation?.url.href, no longer calling router.history.createHref for internal links.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant B as Browser
  participant H as History (parseHref)
  participant R as Router (parse/build)
  participant RW as Rewrite Hooks
  participant L as Link Components

  Note over B,H: Initial parse on load/navigation
  B->>H: parseHref(href)
  H->>H: new URL(href | fallback)
  H-->>R: HistoryLocation { url, pathname, search, hash, state }

  Note over R,RW: Optional URL rewrite (toURL)
  R->>RW: toURL({ url })
  alt toURL returns URL/string
    RW-->>R: rewritten URL
    R->>R: derive pathname/search/hash/fullPath from rewritten URL
  else no rewrite
    RW-->>R: undefined (no change)
  end
  R-->>R: ParsedLocation { url, fullPath, href=fullPath, ... }

  Note over R,RW: Build/navigation with optional rewrite (fromURL)
  R->>R: build next URL from location intent
  R->>RW: fromURL({ url })
  alt fromURL returns URL/string
    RW-->>R: rewritten URL
  else
    RW-->>R: undefined (no change)
  end
  R-->>H: absolute href via URL.href
  H-->>B: push/replaceState(href)

  Note over L: Link rendering
  R-->>L: next/masked ParsedLocation with url
  L->>L: href = masked?.url.href : next.url.href
Loading
sequenceDiagram
  autonumber
  participant U as User
  participant R as Router.navigate
  participant B as Browser

  U->>R: navigate({ reloadDocument: true, location without href })
  R->>R: derive href from location.url.href
  R-->>B: window.location.assign(href)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • schiller-manuel
  • SeanCassiere

Poem

I hop through paths where URLs bloom,
Full href moons dispel old gloom.
A mask unmasked, a rewrite’s twist,
Links now shine with absolute gist.
With whiskered joy I test and zoom—
From hash to core, I boop the DOM. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/url-rewrites

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 27, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5029

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5029

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5029

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5029

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5029

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5029

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5029

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5029

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5029

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5029

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5029

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5029

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5029

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5029

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5029

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5029

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5029

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5029

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5029

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5029

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5029

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5029

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5029

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5029

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5029

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5029

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5029

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5029

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5029

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5029

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5029

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5029

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5029

commit: 2174cd8

@tannerlinsley
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/history/src/index.ts (1)

299-302: Consider documenting the parameter type change from path to href.

While the implementation preserves backward compatibility by using the same pass-through behavior, the parameter name change from path to href in the default createHref function could be confusing. Consider adding a comment or documentation to clarify this change.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d56aa42 and 2174cd8.

📒 Files selected for processing (5)
  • packages/history/src/index.ts (4 hunks)
  • packages/react-router/src/link.tsx (1 hunks)
  • packages/router-core/src/location.ts (1 hunks)
  • packages/router-core/src/router.ts (4 hunks)
  • packages/solid-router/src/link.tsx (1 hunks)
🔇 Additional comments (11)
packages/router-core/src/location.ts (2)

27-32: LGTM! Good deprecation strategy for pathname property.

The deprecation notice for pathname provides clear guidance to use location.url.pathname instead, maintaining backward compatibility while directing users toward the new URL-centric approach.


33-57: LGTM! Well-structured location properties.

The new properties (search, searchStr, state, hash, maskedLocation, unmaskOnReload) are properly documented with JSDoc comments that clearly explain their purpose.

packages/solid-router/src/link.tsx (1)

391-396: LGTM! Consistent URL-centric href resolution.

The change to use location.url.href directly instead of router.history.createHref() aligns well with the PR's goal of URL-centric location handling and maintains consistency with the React implementation.

packages/react-router/src/link.tsx (1)

351-356: LGTM! URL-centric href resolution implemented correctly.

The change to use location.url.href directly instead of router.history.createHref() is consistent with the overall URL-centric approach and matches the implementation in the Solid router.

packages/history/src/index.ts (3)

46-52: LGTM! Clean addition of URL property to ParsedPath interface.

The addition of the url: URL property to the ParsedPath interface is well-placed and properly documented by being included as the first property.


560-565: LGTM! Proper absolute URL construction for hash history.

The change to use new URL() to construct absolute URLs with the origin is correct and ensures consistent URL handling across different history types.


619-652: Solid URL parsing implementation with good fallback handling.

The parseHref function properly handles both absolute and relative URLs with a sensible fallback to http://localhost for relative paths. The URL object is correctly added to the returned HistoryLocation.

packages/router-core/src/router.ts (4)

439-454: LGTM! Well-structured URL rewrite hooks.

The new rewrite option with fromURL and toURL hooks is properly documented and provides a clean API for URL transformations. The JSDoc comments clearly explain the purpose and behavior of each hook.


1053-1087: LGTM! Clean implementation of URL rewriting in parseLocation.

The URL rewriting logic is properly integrated:

  1. toURL hook is applied before extracting pathname, search, and hash
  2. URL properties are correctly derived from the transformed URL
  3. fullPath is properly calculated by removing the origin
  4. The TODO comment correctly notes the future change for href in v2

1866-1870: LGTM! Correct use of location.url.href for reload navigation.

The change to use location.url.href when reloadDocument is true and no explicit href is provided ensures the full URL is used for the reload, which is correct behavior.


1642-1669: Verify URL rewriting sequence in buildLocation

I didn’t find any existing tests or documentation that cover how your rewrite.toURL hook interacts with history.createHref. Please manually confirm that invoking createHref after applying the rewrite hook doesn’t reverse or conflict with the URL modifications your hook produces.

• File: packages/router-core/src/router.ts
• Lines: 1642–1669

@github-actions github-actions bot added the documentation Everything documentation related label Aug 30, 2025
@tannerlinsley tannerlinsley deleted the feat/url-rewrites branch September 23, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants