QuiiBz / next-international

Type-safe internationalization (i18n) for Next.js
https://next-international.vercel.app
MIT License
1.26k stars 59 forks source link

Storing searchParams after changing the language by useChangeLocale stopped working #200

Closed slowwriter closed 11 months ago

slowwriter commented 11 months ago

Storing searchParams after changing the language by useChangeLocale stopped working. I implemented all the changes from the release 1.0.0 description.

QuiiBz commented 11 months ago

I had to remove this to support Static Rendering. We could add it again but that means users will have to wrap components using useChangeLocale in a Suspense boundary, which reduces the usefulness of Static Rendering: https://nextjs.org/docs/app/api-reference/functions/use-search-params#static-rendering

slowwriter commented 11 months ago

Is it possible to make this optional? Suspense wrapping only required for people who want to maintain searchParams?

QuiiBz commented 11 months ago

You'll have to wrap with Suspense if you want Static Rendering, but unfortunately, we can't call hooks conditionally.

What's your use case?

slowwriter commented 11 months ago

Maybe the best solution is to create an additional language change hook with useSearchParams inside to keep full static rendering usability in the current useChangeLocale hook.

My use case: I mainly have dynamic routes. I keep the entire application state in the url using: https://www.npmjs.com/package/next-usequerystate

QuiiBz commented 11 months ago

I've published next-international@1.1.0-rc.2 that introduces a new preserveSearchParams option in useChangeLocale.

You'll manually have to wrap the component using this hook in a Suspense boundary to prevent opting out the entire page from Static Rendering. See the documentation here: https://next-international-git-feat-110-quiibz.vercel.app/docs/app-get-change-locale#preserving-search-params

It will be released officially in #205