Public
Like
nuqs-demo
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
main.tsx
https://stevekrouse--d379fda2513311f08c18f69ea79377d9.web.val.run
This val was created to repro the bug getting started with nuqs.
Github issue: https://github.com/47ng/nuqs/issues/1024#issuecomment-3001766923
ValTown uses esm.sh to import third party libraries, which does bundle them by default. Since we have two exports (one for the nuqs hooks and one for the React adapter), they are both bundled separately, causing the Context reference that powers adapters to be duplicated, and therefore not being able to connect (causing the NUQS-404 and NUQS-303 errors).
We need to tell esm.sh not to bundle nuqs, as it's already ESM, so it can resolve the same Context
reference for the adapters to work. This is done by passing a bundle=false
search param (got to love URL state 😍)
to all nuqs imports:
import { NuqsAdapter } from "https://esm.sh/nuqs/adapters/react?deps=react@18.2.0,react-dom@18.2.0&bundle=false";
import { useQueryState } from "https://esm.sh/nuqs?deps=react@18.2.0,react-dom@18.2.0&bundle=false";