Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for TanStack Router #953

Open
wants to merge 13 commits into
base: next
Choose a base branch
from

Conversation

ahmedrowaihi
Copy link

No description provided.

Copy link

vercel bot commented Mar 31, 2025

@ahmedrowaihi is attempting to deploy a commit to the 47ng Team on Vercel.

A member of the Team first needs to authorize it.

@ahmedrowaihi
Copy link
Author

the nuqs DX is unbeatable, let's make it work everywhere

Copy link
Member

@franky47 franky47 left a comment

Choose a reason for hiding this comment

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

Thank you for this! 🙌

I see the adapter is based on the next/app one, have you tried it in a TSR app? My main concern would be shallow routing support.

Also, you'll need to add the new entry points to the files list in package.json (otherwise they won't land on NPM).

@ahmedrowaihi
Copy link
Author

@franky47

I see the adapter is based on the next/app one, have you tried it in a TSR app? My main concern would be shallow routing support.

Yes, I am using it on my TSR app, it's doing the thing pretty good
the shallowing is not doing different effect for now since the app is SPA, and it's just doing optimistic set

Also, you'll need to add the new entry points to the files list in package.json (otherwise they won't land on NPM).

updated

@ahmedrowaihi
Copy link
Author

oh wait, I just found a bug when shallow is true xD
let me fix it

@ahmedrowaihi
Copy link
Author

@franky47 I fixed it, I reused the TSR router to navigate and this is working now

@ahmedrowaihi ahmedrowaihi requested a review from franky47 March 31, 2025 16:38
Copy link

vercel bot commented Mar 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuqs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 2, 2025 9:10pm

No need for an impl file here, it made sense in Next.js for the
agnostic adapter to import both app & pages router implementations.
Copy link
Member

@franky47 franky47 left a comment

Choose a reason for hiding this comment

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

Thanks, I took the liberty of flattening the TSR adapter code, the impl file was mostly needed for Next.js to have the agnostic adapter pull out implementations from both app & pages adapters.

Looks good for a start, since TSR is mostly for SPAs, I'll add an e2e test environment on this PR tomorrow to see how it behaves. Then there's the question of how to handle the shallow: false option in TanStack Start for SSR, but we can deal with that later.

@franky47 franky47 added the deploy:preview Deploy a preview version of this PR on pkg.pr.new label Mar 31, 2025
Copy link

pkg-pr-new bot commented Mar 31, 2025

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

commit: 1e22fbc

@franky47 franky47 added the adapters/tanstack-router Uses the TanStack Router adapter label Apr 2, 2025
@franky47 franky47 changed the title feat: support tanstack router feat: Add support for TanStack Router Apr 2, 2025
@franky47
Copy link
Member

franky47 commented Apr 2, 2025

The initial porting of the shared e2e test suite looks pretty good!

This is likely to be only the tip of the iceberg though, the real value in a TSR adapter would be to connect nuqs search params definition objects (the ones you feed to useQueryStates, create{Loader,Serializer} etc) to TSR's route definitions for seamless integration with type-safe routing (getting nuqs' search params in TSR's <Link> components, and having it use custom serialisation in the URL when doing so).

- Use a scoped location subscribing only to search params updates
- Use the useNavigate hook for navigation (don't need the whole router)
- Handle native search params arrays (for later)
- Add comments to keep track of why we made these choices
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 deploy:preview Deploy a preview version of this PR on pkg.pr.new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants