From dd5b513590c28170957dc8678d0a981a9aeb49b0 Mon Sep 17 00:00:00 2001 From: Mohamadzadeh <7796733@gmail.com> Date: Mon, 26 Oct 2026 15:03:44 +0330 Subject: [PATCH] uikit-v1.2.6-query-param-provider-cjs-fixed --- ROUTER_QUERY_PARAM_CJS_FIX_1.2.6.md | 13 +++++ dist/chunks/resolve-next-adapter-DK8qNoX5.js | 17 ------- .../resolve-query-param-provider-CtTON3yT.js | 30 +++++++++++ dist/next-app-router.js | 16 +++--- dist/next-pages-router.js | 14 ++--- package.json | 2 +- src/internal/resolve-query-param-provider.js | 19 +++++++ src/next-app-router/index.jsx | 5 +- src/next-pages-router/index.jsx | 5 +- tests/query-param-provider-cjs.test.mjs | 51 +++++++++++++++++++ 10 files changed, 137 insertions(+), 35 deletions(-) create mode 100644 ROUTER_QUERY_PARAM_CJS_FIX_1.2.6.md delete mode 100644 dist/chunks/resolve-next-adapter-DK8qNoX5.js create mode 100644 dist/chunks/resolve-query-param-provider-CtTON3yT.js create mode 100644 src/internal/resolve-query-param-provider.js create mode 100644 tests/query-param-provider-cjs.test.mjs diff --git a/ROUTER_QUERY_PARAM_CJS_FIX_1.2.6.md b/ROUTER_QUERY_PARAM_CJS_FIX_1.2.6.md new file mode 100644 index 0000000..8507b59 --- /dev/null +++ b/ROUTER_QUERY_PARAM_CJS_FIX_1.2.6.md @@ -0,0 +1,13 @@ +# UI Kit 1.2.6 — fix CJS/ESM `use-query-params` import in Next.js + +`use-query-params` can be loaded as a CommonJS module by Node.js when Next.js executes the server-side dependency graph. Named ESM imports from this package may fail at module-link time with: + +`SyntaxError: The requested module 'use-query-params' does not provide an export named 'QueryParamProvider'`. + +Both `uikit/next-pages-router` and `uikit/next-app-router` now load the module as a namespace and resolve `QueryParamProvider` through compatible CJS/ESM export layers, as the legacy `uikit/core` already did. + +**No destination changes needed:** continue using `` (defaults: `shallow: true`, `enableBatching: true`). The `pages/_app.js` file does not need another `QueryParamProvider`. + +The same change is reflected in old `uikit/provider/next-{pages,app}-router` aliases. The existing adapter resolution, query options, all other providers, and legacy core are unchanged. + +This is a targeted compatibility patch built from v1.2.5. Test with actual Next.js runtime before deployment; a full Vite build was not available in this environment. diff --git a/dist/chunks/resolve-next-adapter-DK8qNoX5.js b/dist/chunks/resolve-next-adapter-DK8qNoX5.js deleted file mode 100644 index 79109b5..0000000 --- a/dist/chunks/resolve-next-adapter-DK8qNoX5.js +++ /dev/null @@ -1,17 +0,0 @@ -function u(f, n) { - const r = /* @__PURE__ */ new Set(); - let e = f; - for (let o = 0; o < 6 && e != null && !r.has(e); o += 1) { - if (typeof e == "function") return e; - if (typeof e != "object") break; - r.add(e); - const t = e[n]; - if (typeof t == "function") return t; - if (t && typeof t.default == "function") return t.default; - e = e.default; - } - throw new Error(`uikit: Unable to resolve ${n} from next-query-params.`); -} -export { - u as r -}; diff --git a/dist/chunks/resolve-query-param-provider-CtTON3yT.js b/dist/chunks/resolve-query-param-provider-CtTON3yT.js new file mode 100644 index 0000000..8843472 --- /dev/null +++ b/dist/chunks/resolve-query-param-provider-CtTON3yT.js @@ -0,0 +1,30 @@ +function u(f, r) { + const o = /* @__PURE__ */ new Set(); + let e = f; + for (let t = 0; t < 6 && e != null && !o.has(e); t += 1) { + if (typeof e == "function") return e; + if (typeof e != "object") break; + o.add(e); + const n = e[r]; + if (typeof n == "function") return n; + if (n && typeof n.default == "function") return n.default; + e = e.default; + } + throw new Error(`uikit: Unable to resolve ${r} from next-query-params.`); +} +function a(f) { + let r = f; + const o = /* @__PURE__ */ new Set(); + for (let e = 0; e < 6 && r != null && !o.has(r) && !(typeof r != "object" && typeof r != "function"); e += 1) { + o.add(r); + const t = r.QueryParamProvider; + if (typeof t == "function" || t && typeof t == "object" && t.$$typeof) + return t; + r = r.default; + } + throw new Error("uikit: Unable to resolve QueryParamProvider from use-query-params."); +} +export { + u as a, + a as r +}; diff --git a/dist/next-app-router.js b/dist/next-app-router.js index e1f0bfa..d79eca9 100644 --- a/dist/next-app-router.js +++ b/dist/next-app-router.js @@ -1,15 +1,15 @@ "use client"; import { jsx as t } from "react/jsx-runtime"; import "react"; -import * as p from "next-query-params/app"; -import { QueryParamProvider as o } from "use-query-params"; +import * as o from "next-query-params/app"; +import * as p from "use-query-params"; import { d as a } from "./chunks/feature-registry-B2iuEiEx.js"; -import { r as m } from "./chunks/resolve-next-adapter-DK8qNoX5.js"; -const A = m(p, "NextAdapterApp"); -function d({ children: r, ...e }) { - return /* @__PURE__ */ t(o, { adapter: A, ...e, children: r }); +import { r as m, a as s } from "./chunks/resolve-query-param-provider-CtTON3yT.js"; +const d = m(p), u = s(o, "NextAdapterApp"); +function i({ children: r, ...e }) { + return /* @__PURE__ */ t(d, { adapter: u, ...e, children: r }); } -const u = a("NextAppRouter", 30, d); +const N = a("NextAppRouter", 30, i); export { - u as NextAppRouter + N as NextAppRouter }; diff --git a/dist/next-pages-router.js b/dist/next-pages-router.js index d3fbcbc..6066a1d 100644 --- a/dist/next-pages-router.js +++ b/dist/next-pages-router.js @@ -2,16 +2,16 @@ import { jsx as e } from "react/jsx-runtime"; import "react"; import * as p from "next-query-params/pages"; -import { QueryParamProvider as i } from "use-query-params"; +import * as u from "use-query-params"; import { d as m } from "./chunks/feature-registry-B2iuEiEx.js"; -import { r as d } from "./chunks/resolve-next-adapter-DK8qNoX5.js"; -const r = d(p, "NextAdapterPages"); -function u({ children: t, shallow: a = !0, options: o = {}, ...s }) { - return /* @__PURE__ */ e(i, { adapter: a ? r : function(n) { +import { r as d, a as i } from "./chunks/resolve-query-param-provider-CtTON3yT.js"; +const P = d(u), r = i(p, "NextAdapterPages"); +function l({ children: t, shallow: a = !0, options: o = {}, ...s }) { + return /* @__PURE__ */ e(P, { adapter: a ? r : function(n) { return /* @__PURE__ */ e(r, { ...n, shallow: !1 }); }, options: { enableBatching: !0, ...o }, ...s, children: t }); } -const A = m("NextPagesRouter", 30, u); +const v = m("NextPagesRouter", 30, l); export { - A as NextPagesRouter + v as NextPagesRouter }; diff --git a/package.json b/package.json index 714bbf9..945455e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uikit", - "version": "1.2.5", + "version": "1.2.6", "type": "module", "main": "./dist/index.js", "module": "./dist/index.js", diff --git a/src/internal/resolve-query-param-provider.js b/src/internal/resolve-query-param-provider.js new file mode 100644 index 0000000..d852654 --- /dev/null +++ b/src/internal/resolve-query-param-provider.js @@ -0,0 +1,19 @@ +"use client"; + +// use-query-params may be exposed as an ESM namespace or as a CommonJS +// `default` object when loaded by Node.js/Next.js on the server. +// Do not use a named ESM import, which fails during module linking for CJS. +export function resolveQueryParamProvider(module) { + let current = module; + const seen = new Set(); + for (let depth = 0; depth < 6 && current != null && !seen.has(current); depth += 1) { + if (typeof current !== "object" && typeof current !== "function") break; + seen.add(current); + const provider = current.QueryParamProvider; + if (typeof provider === "function" || (provider && typeof provider === "object" && provider.$$typeof)) { + return provider; + } + current = current.default; + } + throw new Error("uikit: Unable to resolve QueryParamProvider from use-query-params."); +} diff --git a/src/next-app-router/index.jsx b/src/next-app-router/index.jsx index d78cafa..234dd0b 100644 --- a/src/next-app-router/index.jsx +++ b/src/next-app-router/index.jsx @@ -2,9 +2,12 @@ import React from "react"; import * as nextAdapterAppModule from "next-query-params/app"; -import { QueryParamProvider } from "use-query-params"; +import * as useQueryParamsModule from "use-query-params"; import { defineFeature } from "../internal/feature-registry.jsx"; import { resolveNextAdapter } from "../internal/resolve-next-adapter.js"; +import { resolveQueryParamProvider } from "../internal/resolve-query-param-provider.js"; + +const QueryParamProvider = resolveQueryParamProvider(useQueryParamsModule); const NextAdapterApp = resolveNextAdapter(nextAdapterAppModule, "NextAdapterApp"); diff --git a/src/next-pages-router/index.jsx b/src/next-pages-router/index.jsx index d982510..a1c8f6a 100644 --- a/src/next-pages-router/index.jsx +++ b/src/next-pages-router/index.jsx @@ -2,9 +2,12 @@ import React from "react"; import * as nextAdapterPagesModule from "next-query-params/pages"; -import { QueryParamProvider } from "use-query-params"; +import * as useQueryParamsModule from "use-query-params"; import { defineFeature } from "../internal/feature-registry.jsx"; import { resolveNextAdapter } from "../internal/resolve-next-adapter.js"; +import { resolveQueryParamProvider } from "../internal/resolve-query-param-provider.js"; + +const QueryParamProvider = resolveQueryParamProvider(useQueryParamsModule); const NextAdapterPages = resolveNextAdapter(nextAdapterPagesModule, "NextAdapterPages"); diff --git a/tests/query-param-provider-cjs.test.mjs b/tests/query-param-provider-cjs.test.mjs new file mode 100644 index 0000000..08bd5a0 --- /dev/null +++ b/tests/query-param-provider-cjs.test.mjs @@ -0,0 +1,51 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +import os from 'node:os'; +import path from 'node:path'; +import {pathToFileURL} from 'node:url'; +const root=process.cwd(); +const {resolveQueryParamProvider}=await import(pathToFileURL(path.join(root,'src/internal/resolve-query-param-provider.js'))); +const C=()=>{}; +for(const item of [{QueryParamProvider:C},{default:{QueryParamProvider:C}},{default:{default:{QueryParamProvider:C}}},{QueryParamProvider:{$$typeof:Symbol.for('react.forward_ref')}},]) assert.ok(resolveQueryParamProvider(item)); +assert.throws(()=>resolveQueryParamProvider({default:{}}),/Unable to resolve/); +async function scenario(mode){ + const temp=await fs.mkdtemp(path.join(os.tmpdir(),`uikit-query-param-${mode}-`)); + const write=async(p,data)=>{await fs.mkdir(path.dirname(p),{recursive:true});await fs.writeFile(p,data)}; + try { + await write(path.join(temp,'package.json'),'{"type":"module"}'); + for(const name of ['next-pages-router.js','provider-next-pages-router.js','next-app-router.js','provider-next-app-router.js','chunks/_shared-DHh79jO9.js']) await fs.copyFile(path.join(root,'dist',name),path.join(temp,name)).catch(async(e)=>{if(e.code==='ENOENT') {await fs.mkdir(path.dirname(path.join(temp,name)),{recursive:true});await fs.copyFile(path.join(root,'dist',name),path.join(temp,name))}else throw e}); + const pkg=async(name,files,config)=>{ + const dir=path.join(temp,'node_modules',name); + await write(path.join(dir,'package.json'),JSON.stringify({...config,name})); + for (const [f,content] of Object.entries(files)) await write(path.join(dir,f),content); + }; + await pkg('react',{ + 'index.js':`const React={isValidElement:()=>false};export default React;`, + 'jsx-runtime.js':`export function jsx(type, props){return {type,props}};export {jsx as jsxs};` + },{type:'module',exports:{'.':'./index.js','./jsx-runtime':'./jsx-runtime.js'}}); + await pkg('next-query-params',{ + 'pages.js':`export default {default: function PagesAdapter(){}};`, + 'app.js':`export const NextAdapterApp = function AppAdapter(){};` + },{type:'module',exports:{'./pages':'./pages.js','./app':'./app.js'}}); + if (mode==='cjs') await pkg('use-query-params',{'index.cjs':`const x={}; x['Query'+'ParamProvider'] = function QueryParamProvider(){}; module.exports=x;`},{type:'commonjs',exports:{'.':'./index.cjs'}}); + else if(mode==='nested') await pkg('use-query-params',{'index.js':`const QueryParamProvider = function QueryParamProvider(){}; export default { default: { QueryParamProvider } };`},{type:'module',exports:{'.':'./index.js'}}); + else await pkg('use-query-params',{'index.js':`export function QueryParamProvider() {}`},{type:'module',exports:{'.':'./index.js'}}); + const symbol=Symbol.for('uikit.provider.feature.v1'); + for (const file of ['next-pages-router.js','provider-next-pages-router.js','next-app-router.js','provider-next-app-router.js']) { + const mod=await import(pathToFileURL(path.join(temp,file))); + const pages=file.includes('pages'); + const comp=mod[pages?'NextPagesRouter':'NextAppRouter']; + const layer=comp[symbol].Provider; + const result=layer({children:'content'}); + assert.equal(result.type.name,'QueryParamProvider'); + assert.equal(typeof result.props.adapter,'function'); + if(pages){ + assert.equal(result.props.options.enableBatching,true); + assert.equal(layer({children:'x',options:{enableBatching:false,skipNull:true}}).props.options.enableBatching,false); + assert.equal(layer({children:'x',shallow:false}).props.adapter({}).props.shallow,false); + } + } + console.log('PASS',mode,'all four dist paths, proper QueryParamProvider, custom options'); + }finally {await fs.rm(temp,{recursive:true,force:true})} +} +for(const mode of ['cjs','esm','nested']) await scenario(mode);