Skip to content

Conversation

@franky47
Copy link
Member

@franky47 franky47 commented Nov 15, 2025

TBC if this method causes problems elsewhere (maybe running loaders when not needed?)

Also fixes persistence of custom history.state properties.

Closes #1215.

@franky47 franky47 added the adapters/tanstack-router Uses the TanStack Router adapter label Nov 15, 2025
@franky47 franky47 added this to the 🪵 Backlog milestone Nov 15, 2025
@vercel
Copy link

vercel bot commented Nov 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
nuqs Ready Ready Preview Comment Nov 21, 2025 10:33am

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 15, 2025

pnpm add https://pkg.pr.new/nuqs@1217

commit: d4694dd

Copy link

@SeanCassiere SeanCassiere left a comment

Choose a reason for hiding this comment

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

The removal of from should be fine, since Tanner made some changes in router-core, during the big devinxi rewrite, to do more inference of the from value in router.buildLocation.

Its definitely weird that it is busting through the default of never for the trailingSlash option.


On the testing side of things, I'd make sure that your e2e testing covers the Router running at.

  1. At the apex - localhost:3000?foo=bar
  2. On a subpath - localhost:3000/basepath?foo=bar
  3. Using hash routing - localhost:3000/#/?foo=bar

This testing might even make sense to be applied to the other adapters.

// Note: we need to specify pathname + search here to avoid TSR appending
// a trailing slash to the pathname, see https://github.com/47ng/nuqs/issues/1215
from: '/',
to: location.pathname + renderQueryString(search),

Choose a reason for hiding this comment

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

You might want to pull the pathname out using useLocation. I'd use a selector in there, for fine-grained subscriptions.

@franky47
Copy link
Member Author

franky47 commented Nov 21, 2025

Thanks for your review @SeanCassiere (and good luck with the move!) 🫶

I doesn't work on the apex route indeed, and even this causes TSR to emit a trailing slash:

navigate({ href: 'https://example.com?foo=bar' })
// navigates to https://example.com/?foo=bar

I'll look into the TSR code to see if this can be fixed upstream, even if we're not following the intended use of the API, trailingSlash should be respected.

Edit: actually it doesn't seem possible to not have a trailing slash for the apex, even this adds one:

history.replaceState(null, '', 'https://example.com?foo=bar')
// navigates to https://example.com/?foo=bar

@franky47 franky47 enabled auto-merge (squash) November 21, 2025 10:31
@franky47 franky47 merged commit 3b856e6 into next Nov 21, 2025
31 checks passed
@franky47 franky47 deleted the fix/tanstack-router-trailing-slash branch November 21, 2025 10:40
@andreastande
Copy link

Edit: actually it doesn't seem possible to not have a trailing slash for the apex, even this adds one:

Weird, do you think that is a bug with TSR? Should be possible

@github-actions
Copy link

🎉 This PR is included in version 2.8.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47
Copy link
Member Author

franky47 commented Nov 21, 2025

Weird, do you think that is a bug with TSR? Should be possible

No, this happens on https://example.com if you type history.replaceState(null, '', 'https://example.com?foo=bar'), so it's not related to any framework, it's a limitation of the web platform.

Actually even loading https://example.com?foo=bar in the browser gives you https://example.com/?foo=bar

@github-actions github-actions bot removed this from the 🚀 Shipping next milestone Nov 21, 2025
@andreastande
Copy link

TIL

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

Labels

adapters/tanstack-router Uses the TanStack Router adapter released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useQueryState causes a navigation to trailing slash with search param w/ TanStack Router

4 participants