uikit-v1.2.6-query-param-provider-cjs-fixed
All checks were successful
Build and Deploy Next.js + Nginx Docker Image / build-and-deploy (push) Successful in 52s
Build and Deploy Next.js + Nginx Docker Image / deploy (push) Successful in 7s

This commit is contained in:
Mohamadzadeh 2026-10-26 15:03:44 +03:30
parent 4730057b3f
commit dd5b513590
10 changed files with 137 additions and 35 deletions

View File

@ -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 `<NextPagesRouter />` (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.

View File

@ -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
};

View File

@ -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
};

View File

@ -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
};

View File

@ -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
};

View File

@ -1,6 +1,6 @@
{
"name": "uikit",
"version": "1.2.5",
"version": "1.2.6",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",

View File

@ -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.");
}

View File

@ -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");

View File

@ -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");

View File

@ -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);