-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
nuqs/server
requires react
#804
Comments
Yeah unfortunately the Since it's a breaking change, it's unlikely to happen soon though, but we could do it the other way around: provide imports for individual server-side features, like: import { createSerializer } from 'nuqs/server/serializer'
import { parseAsStringLiteral } from 'nuqs/server/parsers' What do you think? |
That would be perfect for my use-case! |
That solution I proposed has been implemented in #805, could you give it a go and let me know if it works please?
Note: those imports are temporary until v3 lands (no date planned at the moment). In v3, the cache will have been moved to it's own import ( |
@boredland I tested the imports and I'm seeing some issues with TypeScript not resolving the contents of |
Thank you for the super quick implementation! I didn't yet have the chance to test before my Christmas break, but will surely do it as the first thing next year! |
Hey, happy new year! Just as a heads-up, I've merged all the non-react-based exports under a single one, renamed to make it more obvious that it's temporary: import { createSerializer, parseAsInteger, ... } from 'nuqs/server/temporary-react-agnostic' It's available here:
|
Hey y'all, if the dependency on React is not an issue (this package is, after all, a library for React), but the
Then in your code, as it was initially: // Import from 'nuqs/server' to skip the "use client" directive in Next.js app router server code.
// Note: other frameworks don't need this and can import straight from 'nuqs'.
import { createLoader, createSerializer, parseAsInteger /* etc..*/ } from 'nuqs/server' This doesn't solve wanting to, say, parse search params in an isolated, React-free JS backend web framework (like Fastify, Hono, Express etc), but I feel like this kind of use-case might be a tangent that #805 could focus on, rather than requiring everyone else to rewrite their imports. |
I'm trying to run some tests in nextjs14 using vitest, I've tried the latest fix
but am getting an error from
|
@alylim thanks for the feedback, you'll need to mock that cache function in tests, as even if you can import it (using React canary), I doubt it would behave the right way in a testing environment. Here's how I did it on my end, let me know if it works for you: nuqs/packages/nuqs/src/cache.test.ts Lines 6 to 17 in da5ee6c
|
@franky47 Appreciate the quick response! It still does not work on my end but I reckon it's probably something to do with how I've implemented the tests rather than an issue with nuqs. |
@alylim if the issue isn't related to the cache import not being found, feel free to open a dedicated issue or discussion with more details. |
Having `import { cache } from 'react'` caused issues when using React 18 or 19 GA, because the `cache` function is only exported in canary builds (which the Next.js app router uses internally, regardless of what's in your app's package.json). This meant importing from `'nuqs/server'` caused an import error when done from non app-router code, like the pages router, or API route definitions, which would fallback to the version of React defined in the package.json (and likely a stable one). Changing the import to `import * as React from 'react'` is what is being highlighted in the React docs themselves, and allows to only call the cache function when actually creating a cache object. Closes #804, and supersedes #805.
🎉 This issue has been resolved in version 2.4.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Context
What's your version of
nuqs
?What framework are you using?
Which version of your framework are you using?
Description
Apart from Frontend usage, I wanted to use my nuqs parsers to generate URLs on the server-side to be sent in emails.
For that I am trying to use a serializer on an API Route like so:
But sadly my Next.js-build fails, telling me:
Is there a trick to it? As I see it, this module is required for the cache feature, that I don't need. Would splitting up the path to allow direct imports of parsers/serializer help?
The text was updated successfully, but these errors were encountered: