Skip to content

feat: defaultOptions for NuqsAdapter#1066

Merged
franky47 merged 3 commits into47ng:nextfrom
TkDodo:feature/adapter-default-values
Aug 14, 2025
Merged

feat: defaultOptions for NuqsAdapter#1066
franky47 merged 3 commits into47ng:nextfrom
TkDodo:feature/adapter-default-values

Conversation

@TkDodo
Copy link
Contributor

@TkDodo TkDodo commented Aug 14, 2025

This PR adds defaultOptions to <NuqsAdapter>, which allows to override the globally specified defaults.

As a first step, only shallow?: boolean can be provided, but it can be extended to more default values.

@vercel
Copy link

vercel bot commented Aug 14, 2025

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

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Aug 14, 2025

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

Project Deployment Preview Comments Updated (UTC)
nuqs Ready Preview Comment Aug 14, 2025 1:52pm

@franky47 franky47 added feature New feature or request deploy:preview Deploy a preview version of this PR on pkg.pr.new labels Aug 14, 2025
@franky47 franky47 added this to the 🪵 Backlog milestone Aug 14, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 14, 2025

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

commit: a070303

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, it looks good, I'd be more generic about the AdapterDefaultOptions type to allow extending it in the future with other props passed via the adapter (like a callback function to process URLSearchParams after applying updates for alphabetical sorting).

I don't think it's an issue, but could passing an object from the render body cause re-renders? I guess as long as the parent component of <NuqsAdapter> isn't re-rendered it shouldn't be an issue, and that would cause the whole app to re-render anyway (as adapters are placed high in the tree).

function RootLayout({ children }) {
  return (
    <NuqsAdapter defaultOptions={{ shallow: false })>
      {children}
    </NuqsAdapter>
  )
}

import type { AdapterInterface, UseAdapterHook } from './defs'

export type AdapterContext = {
export type AdapterDefaultOptions = {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: There are other things we could pass through that Context from adapter props, so this type could be more generically named AdapterProps, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that makes a lot of sense. AdapterDefaultOptions is actually the defaultOptions object inside the AdapterProps 👍

5025028

@TkDodo
Copy link
Contributor Author

TkDodo commented Aug 14, 2025

@franky47 regarding re-renders: currently, the context value is not memoized - it’s a new object with useAdapter inside:

{ ...props, value: { useAdapter } },

so that alone could cause re-renders. However, that’s only a concern IF the RootLayout in your example would render “from within itself”, because then children would be stable.

If there’s a top-down render, children will be new and will therefore always re-render the whole tree downwards.

@franky47 franky47 enabled auto-merge (squash) August 14, 2025 13:46
@franky47 franky47 merged commit 15bdc68 into 47ng:next Aug 14, 2025
26 checks passed
@TkDodo TkDodo deleted the feature/adapter-default-values branch August 14, 2025 14:18
@github-actions
Copy link

🎉 This PR is included in version 2.5.0-beta.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@franky47 franky47 removed this from the 🚀 Shipping next milestone Aug 22, 2025
@franky47 franky47 mentioned this pull request Aug 25, 2025
@Multiply
Copy link
Contributor

Multiply commented Sep 1, 2025

(like a callback function to process URLSearchParams after applying updates for alphabetical sorting).

Is this feature planned? We're definitely looking for this feature specifically. (alphabetical sorting of parameters)
Edit: or a callback where we can do it ourselves.

@franky47
Copy link
Member

franky47 commented Sep 1, 2025

@Multiply would you like to try your hand at a PR?

@Multiply
Copy link
Contributor

Multiply commented Sep 1, 2025

@Multiply would you like to try your hand at a PR?

Was already looking into the recent introduction of global default config.
Do you have a preference for where the middleware should be called?

@franky47
Copy link
Member

franky47 commented Sep 1, 2025

Let's continue the discussion in #1109.

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

Labels

deploy:preview Deploy a preview version of this PR on pkg.pr.new feature New feature or request released on @beta released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants