gt-next 11.2.1 → 11.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -7
- package/dist/config.js.map +1 -1
- package/dist/config.mjs +4 -9
- package/dist/config.mjs.map +1 -1
- package/dist/errors/createErrors.d.ts +0 -1
- package/dist/errors/createErrors.d.ts.map +1 -1
- package/dist/errors/createErrors.js +0 -2
- package/dist/errors/createErrors.js.map +1 -1
- package/dist/errors/createErrors.mjs +1 -2
- package/dist/errors/createErrors.mjs.map +1 -1
- package/dist/middleware-dir/createNextMiddleware.d.ts +6 -1
- package/dist/middleware-dir/createNextMiddleware.d.ts.map +1 -1
- package/dist/middleware-dir/createNextMiddleware.js +51 -21
- package/dist/middleware-dir/createNextMiddleware.js.map +1 -1
- package/dist/middleware-dir/createNextMiddleware.mjs +52 -22
- package/dist/middleware-dir/createNextMiddleware.mjs.map +1 -1
- package/dist/middleware-dir/utils.d.ts +1 -1
- package/dist/middleware-dir/utils.d.ts.map +1 -1
- package/dist/middleware-dir/utils.js +8 -13
- package/dist/middleware-dir/utils.js.map +1 -1
- package/dist/middleware-dir/utils.mjs +8 -13
- package/dist/middleware-dir/utils.mjs.map +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/middleware.d.ts.map +1 -1
- package/dist/plugin/constants.d.ts +1 -0
- package/dist/plugin/constants.d.ts.map +1 -1
- package/dist/plugin/constants.js +2 -0
- package/dist/plugin/constants.js.map +1 -1
- package/dist/plugin/constants.mjs +2 -1
- package/dist/plugin/constants.mjs.map +1 -1
- package/dist/plugin/getStableNextVersionInfo.d.ts +1 -0
- package/dist/plugin/getStableNextVersionInfo.d.ts.map +1 -1
- package/dist/plugin/getStableNextVersionInfo.js +2 -0
- package/dist/plugin/getStableNextVersionInfo.js.map +1 -1
- package/dist/plugin/getStableNextVersionInfo.mjs +3 -2
- package/dist/plugin/getStableNextVersionInfo.mjs.map +1 -1
- package/dist/provider/GTProvider.d.ts.map +1 -1
- package/dist/provider/GTProvider.js +10 -5
- package/dist/provider/GTProvider.js.map +1 -1
- package/dist/provider/GTProvider.mjs +10 -5
- package/dist/provider/GTProvider.mjs.map +1 -1
- package/dist/request/localeValidation.js +2 -2
- package/dist/request/localeValidation.js.map +1 -1
- package/dist/request/localeValidation.mjs +2 -2
- package/dist/request/localeValidation.mjs.map +1 -1
- package/dist/utils/client-boundary.d.ts +4 -1
- package/dist/utils/client-boundary.d.ts.map +1 -1
- package/dist/utils/client-boundary.js +14 -10
- package/dist/utils/client-boundary.js.map +1 -1
- package/dist/utils/client-boundary.mjs +14 -10
- package/dist/utils/client-boundary.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -8,7 +8,8 @@ const ROOT_PARAM_STABILITY = {
|
|
|
8
8
|
stable: "16.3.0"
|
|
9
9
|
};
|
|
10
10
|
const STABLE_TURBO_CONFIG_VERSION = "15.3.0";
|
|
11
|
+
const LOCALE_REFRESH_SUPPORT = "16.1.0";
|
|
11
12
|
//#endregion
|
|
12
|
-
export { BABEL_PLUGIN_SUPPORT, ROOT_PARAM_STABILITY, STABLE_TURBO_CONFIG_VERSION, SWC_PLUGIN_SUPPORT };
|
|
13
|
+
export { BABEL_PLUGIN_SUPPORT, LOCALE_REFRESH_SUPPORT, ROOT_PARAM_STABILITY, STABLE_TURBO_CONFIG_VERSION, SWC_PLUGIN_SUPPORT };
|
|
13
14
|
|
|
14
15
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/plugin/constants.ts"],"sourcesContent":["export const BABEL_PLUGIN_SUPPORT = '17.0.0';\n\nexport const SWC_PLUGIN_SUPPORT = '16.1.0';\n\n// Minimum Next versions for feature-specific plugin behavior.\nexport const ROOT_PARAM_STABILITY = {\n unsupported: '0.0.0',\n unstable: '15.2.0',\n experimental: '15.5.0',\n stable: '16.3.0',\n};\n\nexport const STABLE_TURBO_CONFIG_VERSION = '15.3.0';\n"],"mappings":";AAAA,MAAa,uBAAuB;AAEpC,MAAa,qBAAqB;AAGlC,MAAa,uBAAuB;CAClC,aAAa;CACb,UAAU;CACV,cAAc;CACd,QAAQ;CACT;AAED,MAAa,8BAA8B"}
|
|
1
|
+
{"version":3,"file":"constants.mjs","names":[],"sources":["../../src/plugin/constants.ts"],"sourcesContent":["export const BABEL_PLUGIN_SUPPORT = '17.0.0';\n\nexport const SWC_PLUGIN_SUPPORT = '16.1.0';\n\n// Minimum Next versions for feature-specific plugin behavior.\nexport const ROOT_PARAM_STABILITY = {\n unsupported: '0.0.0',\n unstable: '15.2.0',\n experimental: '15.5.0',\n stable: '16.3.0',\n};\n\nexport const STABLE_TURBO_CONFIG_VERSION = '15.3.0';\n\nexport const LOCALE_REFRESH_SUPPORT = '16.1.0';\n"],"mappings":";AAAA,MAAa,uBAAuB;AAEpC,MAAa,qBAAqB;AAGlC,MAAa,uBAAuB;CAClC,aAAa;CACb,UAAU;CACV,cAAc;CACd,QAAQ;CACT;AAED,MAAa,8BAA8B;AAE3C,MAAa,yBAAyB"}
|
|
@@ -14,4 +14,5 @@ export declare function getRootParamStability(nextVersion: string): RootParam;
|
|
|
14
14
|
export declare const rootParamStability: RootParam;
|
|
15
15
|
export declare const swcPluginCompatible: boolean;
|
|
16
16
|
export declare const babelPluginCompatible: boolean;
|
|
17
|
+
export declare const localeRefreshSupported: boolean;
|
|
17
18
|
//# sourceMappingURL=getStableNextVersionInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStableNextVersionInfo.d.ts","sourceRoot":"","sources":["../../src/plugin/getStableNextVersionInfo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getStableNextVersionInfo.d.ts","sourceRoot":"","sources":["../../src/plugin/getStableNextVersionInfo.ts"],"names":[],"mappings":"AA0EA;;;GAGG;AACH,eAAO,MAAM,iBAAiB,SAG7B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,cAAc,GAAG,QAAQ,CAAC;AAE/E;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAepE;AAED,eAAO,MAAM,kBAAkB,WAA0C,CAAC;AAE1E,eAAO,MAAM,mBAAmB,SAG/B,CAAC;AAGF,eAAO,MAAM,qBAAqB,SAGjC,CAAC;AAIF,eAAO,MAAM,sBAAsB,SAGlC,CAAC"}
|
|
@@ -70,9 +70,11 @@ function getRootParamStability(nextVersion) {
|
|
|
70
70
|
const rootParamStability = getRootParamStability(getNextVersion());
|
|
71
71
|
const swcPluginCompatible = comparePackageVersion(getNextVersion(), require_plugin_constants.SWC_PLUGIN_SUPPORT);
|
|
72
72
|
const babelPluginCompatible = comparePackageVersion(getReactVersion(), require_plugin_constants.BABEL_PLUGIN_SUPPORT);
|
|
73
|
+
const localeRefreshSupported = comparePackageVersion(getNextVersion(), require_plugin_constants.LOCALE_REFRESH_SUPPORT);
|
|
73
74
|
//#endregion
|
|
74
75
|
exports.babelPluginCompatible = babelPluginCompatible;
|
|
75
76
|
exports.getRootParamStability = getRootParamStability;
|
|
77
|
+
exports.localeRefreshSupported = localeRefreshSupported;
|
|
76
78
|
exports.rootParamStability = rootParamStability;
|
|
77
79
|
exports.swcPluginCompatible = swcPluginCompatible;
|
|
78
80
|
exports.turboConfigStable = turboConfigStable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStableNextVersionInfo.js","names":["createUnresolvedNextVersionError","createUnresolvedReactVersionError","STABLE_TURBO_CONFIG_VERSION","ROOT_PARAM_STABILITY","SWC_PLUGIN_SUPPORT","BABEL_PLUGIN_SUPPORT"],"sources":["../../src/plugin/getStableNextVersionInfo.ts"],"sourcesContent":["import {\n createUnresolvedNextVersionError,\n createUnresolvedReactVersionError,\n} from '../errors/createErrors';\nimport {\n BABEL_PLUGIN_SUPPORT,\n ROOT_PARAM_STABILITY,\n STABLE_TURBO_CONFIG_VERSION,\n SWC_PLUGIN_SUPPORT,\n} from './constants';\n\n/**\n * Get the next version of the package.\n */\nfunction getPackageVersion(packageName: string): string {\n const packageJsonPath = `${packageName}/package.json`;\n\n try {\n const resolvedPackageJsonPath = require.resolve(packageJsonPath, {\n paths: [process.cwd()],\n });\n return require(resolvedPackageJsonPath).version;\n } catch (_error) {\n return require(packageJsonPath).version;\n }\n}\n\nfunction getNextVersion(): string {\n try {\n return getPackageVersion('next');\n } catch (error) {\n throw new Error(createUnresolvedNextVersionError(error as Error));\n }\n}\n\n/**\n * Get the react version of the package.\n * I am wary of dynamic imports\n */\nfunction getReactVersion(): string {\n try {\n return getPackageVersion('react');\n } catch (error) {\n throw new Error(createUnresolvedReactVersionError(error as Error));\n }\n}\n\n/**\n * Compare two package versions.\n *\n * @param a - The first version.\n * @param b - The second version.\n * @returns True if a is greater than or equal to b, false otherwise.\n */\nfunction comparePackageVersion(a: string, b: string): boolean {\n const aParts = a.split('.');\n const bParts = b.split('.');\n\n for (let i = 0; i < aParts.length; i++) {\n const aPart = Number(aParts[i]) || 0;\n const bPart = Number(bParts[i]) || 0;\n\n if (aPart > bPart) {\n return true;\n } else if (aPart < bPart) {\n return false;\n }\n }\n\n // If all parts are equal, return true\n return true;\n}\n\n/**\n * Starting at version next@15.3.0 experimental field in turbo config was deprecated.\n * Shout out to next-intl: https://github.com/amannn/next-intl/pull/1850\n */\nexport const turboConfigStable = comparePackageVersion(\n getNextVersion(),\n STABLE_TURBO_CONFIG_VERSION\n);\n\nexport type RootParam = 'unsupported' | 'unstable' | 'experimental' | 'stable';\n\n/**\n * Classify the stability of root params for a Next.js version.\n *\n * @param nextVersion - The Next.js version to classify.\n * @returns The root params stability tier for the supplied version.\n */\nexport function getRootParamStability(nextVersion: string): RootParam {\n // Check stable before experimental because each threshold is a lower bound.\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.stable)) {\n return 'stable';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.experimental)) {\n return 'experimental';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.unstable)) {\n return 'unstable';\n }\n\n return 'unsupported';\n}\n\nexport const rootParamStability = getRootParamStability(getNextVersion());\n\nexport const swcPluginCompatible = comparePackageVersion(\n getNextVersion(),\n SWC_PLUGIN_SUPPORT\n);\n\n// disable babel plugin if using react <= 16\nexport const babelPluginCompatible = comparePackageVersion(\n getReactVersion(),\n BABEL_PLUGIN_SUPPORT\n);\n"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"getStableNextVersionInfo.js","names":["createUnresolvedNextVersionError","createUnresolvedReactVersionError","STABLE_TURBO_CONFIG_VERSION","ROOT_PARAM_STABILITY","SWC_PLUGIN_SUPPORT","BABEL_PLUGIN_SUPPORT","LOCALE_REFRESH_SUPPORT"],"sources":["../../src/plugin/getStableNextVersionInfo.ts"],"sourcesContent":["import {\n createUnresolvedNextVersionError,\n createUnresolvedReactVersionError,\n} from '../errors/createErrors';\nimport {\n BABEL_PLUGIN_SUPPORT,\n LOCALE_REFRESH_SUPPORT,\n ROOT_PARAM_STABILITY,\n STABLE_TURBO_CONFIG_VERSION,\n SWC_PLUGIN_SUPPORT,\n} from './constants';\n\n/**\n * Get the next version of the package.\n */\nfunction getPackageVersion(packageName: string): string {\n const packageJsonPath = `${packageName}/package.json`;\n\n try {\n const resolvedPackageJsonPath = require.resolve(packageJsonPath, {\n paths: [process.cwd()],\n });\n return require(resolvedPackageJsonPath).version;\n } catch (_error) {\n return require(packageJsonPath).version;\n }\n}\n\nfunction getNextVersion(): string {\n try {\n return getPackageVersion('next');\n } catch (error) {\n throw new Error(createUnresolvedNextVersionError(error as Error));\n }\n}\n\n/**\n * Get the react version of the package.\n * I am wary of dynamic imports\n */\nfunction getReactVersion(): string {\n try {\n return getPackageVersion('react');\n } catch (error) {\n throw new Error(createUnresolvedReactVersionError(error as Error));\n }\n}\n\n/**\n * Compare two package versions.\n *\n * @param a - The first version.\n * @param b - The second version.\n * @returns True if a is greater than or equal to b, false otherwise.\n */\nfunction comparePackageVersion(a: string, b: string): boolean {\n const aParts = a.split('.');\n const bParts = b.split('.');\n\n for (let i = 0; i < aParts.length; i++) {\n const aPart = Number(aParts[i]) || 0;\n const bPart = Number(bParts[i]) || 0;\n\n if (aPart > bPart) {\n return true;\n } else if (aPart < bPart) {\n return false;\n }\n }\n\n // If all parts are equal, return true\n return true;\n}\n\n/**\n * Starting at version next@15.3.0 experimental field in turbo config was deprecated.\n * Shout out to next-intl: https://github.com/amannn/next-intl/pull/1850\n */\nexport const turboConfigStable = comparePackageVersion(\n getNextVersion(),\n STABLE_TURBO_CONFIG_VERSION\n);\n\nexport type RootParam = 'unsupported' | 'unstable' | 'experimental' | 'stable';\n\n/**\n * Classify the stability of root params for a Next.js version.\n *\n * @param nextVersion - The Next.js version to classify.\n * @returns The root params stability tier for the supplied version.\n */\nexport function getRootParamStability(nextVersion: string): RootParam {\n // Check stable before experimental because each threshold is a lower bound.\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.stable)) {\n return 'stable';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.experimental)) {\n return 'experimental';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.unstable)) {\n return 'unstable';\n }\n\n return 'unsupported';\n}\n\nexport const rootParamStability = getRootParamStability(getNextVersion());\n\nexport const swcPluginCompatible = comparePackageVersion(\n getNextVersion(),\n SWC_PLUGIN_SUPPORT\n);\n\n// disable babel plugin if using react <= 16\nexport const babelPluginCompatible = comparePackageVersion(\n getReactVersion(),\n BABEL_PLUGIN_SUPPORT\n);\n\n// Older refresh reducers can retain a stale layout after middleware redirects.\n// Related refresh/redirect issue: https://github.com/vercel/next.js/issues/65970\nexport const localeRefreshSupported = comparePackageVersion(\n getNextVersion(),\n LOCALE_REFRESH_SUPPORT\n);\n"],"mappings":";;;;;;;AAeA,SAAS,kBAAkB,aAA6B;CACtD,MAAM,kBAAkB,GAAG,YAAY;AAEvC,KAAI;EACF,MAAM,0BAA0B,QAAQ,QAAQ,iBAAiB,EAC/D,OAAO,CAAC,QAAQ,KAAK,CAAC,EACvB,CAAC;AACF,SAAO,QAAQ,wBAAwB,CAAC;UACjC,QAAQ;AACf,SAAO,QAAQ,gBAAgB,CAAC;;;AAIpC,SAAS,iBAAyB;AAChC,KAAI;AACF,SAAO,kBAAkB,OAAO;UACzB,OAAO;AACd,QAAM,IAAI,MAAMA,4BAAAA,iCAAiC,MAAe,CAAC;;;;;;;AAQrE,SAAS,kBAA0B;AACjC,KAAI;AACF,SAAO,kBAAkB,QAAQ;UAC1B,OAAO;AACd,QAAM,IAAI,MAAMC,4BAAAA,kCAAkC,MAAe,CAAC;;;;;;;;;;AAWtE,SAAS,sBAAsB,GAAW,GAAoB;CAC5D,MAAM,SAAS,EAAE,MAAM,IAAI;CAC3B,MAAM,SAAS,EAAE,MAAM,IAAI;AAE3B,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO,OAAO,GAAG,IAAI;EACnC,MAAM,QAAQ,OAAO,OAAO,GAAG,IAAI;AAEnC,MAAI,QAAQ,MACV,QAAO;WACE,QAAQ,MACjB,QAAO;;AAKX,QAAO;;;;;;AAOT,MAAa,oBAAoB,sBAC/B,gBAAgB,EAChBC,yBAAAA,4BACD;;;;;;;AAUD,SAAgB,sBAAsB,aAAgC;AAEpE,KAAI,sBAAsB,aAAaC,yBAAAA,qBAAqB,OAAO,CACjE,QAAO;AAGT,KAAI,sBAAsB,aAAaA,yBAAAA,qBAAqB,aAAa,CACvE,QAAO;AAGT,KAAI,sBAAsB,aAAaA,yBAAAA,qBAAqB,SAAS,CACnE,QAAO;AAGT,QAAO;;AAGT,MAAa,qBAAqB,sBAAsB,gBAAgB,CAAC;AAEzE,MAAa,sBAAsB,sBACjC,gBAAgB,EAChBC,yBAAAA,mBACD;AAGD,MAAa,wBAAwB,sBACnC,iBAAiB,EACjBC,yBAAAA,qBACD;AAID,MAAa,yBAAyB,sBACpC,gBAAgB,EAChBC,yBAAAA,uBACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BABEL_PLUGIN_SUPPORT, ROOT_PARAM_STABILITY, STABLE_TURBO_CONFIG_VERSION, SWC_PLUGIN_SUPPORT } from "./constants.mjs";
|
|
1
|
+
import { BABEL_PLUGIN_SUPPORT, LOCALE_REFRESH_SUPPORT, ROOT_PARAM_STABILITY, STABLE_TURBO_CONFIG_VERSION, SWC_PLUGIN_SUPPORT } from "./constants.mjs";
|
|
2
2
|
import { createUnresolvedNextVersionError, createUnresolvedReactVersionError } from "../errors/createErrors.mjs";
|
|
3
3
|
//#region src/plugin/getStableNextVersionInfo.ts
|
|
4
4
|
/**
|
|
@@ -69,7 +69,8 @@ function getRootParamStability(nextVersion) {
|
|
|
69
69
|
const rootParamStability = getRootParamStability(getNextVersion());
|
|
70
70
|
const swcPluginCompatible = comparePackageVersion(getNextVersion(), SWC_PLUGIN_SUPPORT);
|
|
71
71
|
const babelPluginCompatible = comparePackageVersion(getReactVersion(), BABEL_PLUGIN_SUPPORT);
|
|
72
|
+
const localeRefreshSupported = comparePackageVersion(getNextVersion(), LOCALE_REFRESH_SUPPORT);
|
|
72
73
|
//#endregion
|
|
73
|
-
export { babelPluginCompatible, getRootParamStability, rootParamStability, swcPluginCompatible, turboConfigStable };
|
|
74
|
+
export { babelPluginCompatible, getRootParamStability, localeRefreshSupported, rootParamStability, swcPluginCompatible, turboConfigStable };
|
|
74
75
|
|
|
75
76
|
//# sourceMappingURL=getStableNextVersionInfo.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getStableNextVersionInfo.mjs","names":[],"sources":["../../src/plugin/getStableNextVersionInfo.ts"],"sourcesContent":["import {\n createUnresolvedNextVersionError,\n createUnresolvedReactVersionError,\n} from '../errors/createErrors';\nimport {\n BABEL_PLUGIN_SUPPORT,\n ROOT_PARAM_STABILITY,\n STABLE_TURBO_CONFIG_VERSION,\n SWC_PLUGIN_SUPPORT,\n} from './constants';\n\n/**\n * Get the next version of the package.\n */\nfunction getPackageVersion(packageName: string): string {\n const packageJsonPath = `${packageName}/package.json`;\n\n try {\n const resolvedPackageJsonPath = require.resolve(packageJsonPath, {\n paths: [process.cwd()],\n });\n return require(resolvedPackageJsonPath).version;\n } catch (_error) {\n return require(packageJsonPath).version;\n }\n}\n\nfunction getNextVersion(): string {\n try {\n return getPackageVersion('next');\n } catch (error) {\n throw new Error(createUnresolvedNextVersionError(error as Error));\n }\n}\n\n/**\n * Get the react version of the package.\n * I am wary of dynamic imports\n */\nfunction getReactVersion(): string {\n try {\n return getPackageVersion('react');\n } catch (error) {\n throw new Error(createUnresolvedReactVersionError(error as Error));\n }\n}\n\n/**\n * Compare two package versions.\n *\n * @param a - The first version.\n * @param b - The second version.\n * @returns True if a is greater than or equal to b, false otherwise.\n */\nfunction comparePackageVersion(a: string, b: string): boolean {\n const aParts = a.split('.');\n const bParts = b.split('.');\n\n for (let i = 0; i < aParts.length; i++) {\n const aPart = Number(aParts[i]) || 0;\n const bPart = Number(bParts[i]) || 0;\n\n if (aPart > bPart) {\n return true;\n } else if (aPart < bPart) {\n return false;\n }\n }\n\n // If all parts are equal, return true\n return true;\n}\n\n/**\n * Starting at version next@15.3.0 experimental field in turbo config was deprecated.\n * Shout out to next-intl: https://github.com/amannn/next-intl/pull/1850\n */\nexport const turboConfigStable = comparePackageVersion(\n getNextVersion(),\n STABLE_TURBO_CONFIG_VERSION\n);\n\nexport type RootParam = 'unsupported' | 'unstable' | 'experimental' | 'stable';\n\n/**\n * Classify the stability of root params for a Next.js version.\n *\n * @param nextVersion - The Next.js version to classify.\n * @returns The root params stability tier for the supplied version.\n */\nexport function getRootParamStability(nextVersion: string): RootParam {\n // Check stable before experimental because each threshold is a lower bound.\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.stable)) {\n return 'stable';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.experimental)) {\n return 'experimental';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.unstable)) {\n return 'unstable';\n }\n\n return 'unsupported';\n}\n\nexport const rootParamStability = getRootParamStability(getNextVersion());\n\nexport const swcPluginCompatible = comparePackageVersion(\n getNextVersion(),\n SWC_PLUGIN_SUPPORT\n);\n\n// disable babel plugin if using react <= 16\nexport const babelPluginCompatible = comparePackageVersion(\n getReactVersion(),\n BABEL_PLUGIN_SUPPORT\n);\n"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"getStableNextVersionInfo.mjs","names":[],"sources":["../../src/plugin/getStableNextVersionInfo.ts"],"sourcesContent":["import {\n createUnresolvedNextVersionError,\n createUnresolvedReactVersionError,\n} from '../errors/createErrors';\nimport {\n BABEL_PLUGIN_SUPPORT,\n LOCALE_REFRESH_SUPPORT,\n ROOT_PARAM_STABILITY,\n STABLE_TURBO_CONFIG_VERSION,\n SWC_PLUGIN_SUPPORT,\n} from './constants';\n\n/**\n * Get the next version of the package.\n */\nfunction getPackageVersion(packageName: string): string {\n const packageJsonPath = `${packageName}/package.json`;\n\n try {\n const resolvedPackageJsonPath = require.resolve(packageJsonPath, {\n paths: [process.cwd()],\n });\n return require(resolvedPackageJsonPath).version;\n } catch (_error) {\n return require(packageJsonPath).version;\n }\n}\n\nfunction getNextVersion(): string {\n try {\n return getPackageVersion('next');\n } catch (error) {\n throw new Error(createUnresolvedNextVersionError(error as Error));\n }\n}\n\n/**\n * Get the react version of the package.\n * I am wary of dynamic imports\n */\nfunction getReactVersion(): string {\n try {\n return getPackageVersion('react');\n } catch (error) {\n throw new Error(createUnresolvedReactVersionError(error as Error));\n }\n}\n\n/**\n * Compare two package versions.\n *\n * @param a - The first version.\n * @param b - The second version.\n * @returns True if a is greater than or equal to b, false otherwise.\n */\nfunction comparePackageVersion(a: string, b: string): boolean {\n const aParts = a.split('.');\n const bParts = b.split('.');\n\n for (let i = 0; i < aParts.length; i++) {\n const aPart = Number(aParts[i]) || 0;\n const bPart = Number(bParts[i]) || 0;\n\n if (aPart > bPart) {\n return true;\n } else if (aPart < bPart) {\n return false;\n }\n }\n\n // If all parts are equal, return true\n return true;\n}\n\n/**\n * Starting at version next@15.3.0 experimental field in turbo config was deprecated.\n * Shout out to next-intl: https://github.com/amannn/next-intl/pull/1850\n */\nexport const turboConfigStable = comparePackageVersion(\n getNextVersion(),\n STABLE_TURBO_CONFIG_VERSION\n);\n\nexport type RootParam = 'unsupported' | 'unstable' | 'experimental' | 'stable';\n\n/**\n * Classify the stability of root params for a Next.js version.\n *\n * @param nextVersion - The Next.js version to classify.\n * @returns The root params stability tier for the supplied version.\n */\nexport function getRootParamStability(nextVersion: string): RootParam {\n // Check stable before experimental because each threshold is a lower bound.\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.stable)) {\n return 'stable';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.experimental)) {\n return 'experimental';\n }\n\n if (comparePackageVersion(nextVersion, ROOT_PARAM_STABILITY.unstable)) {\n return 'unstable';\n }\n\n return 'unsupported';\n}\n\nexport const rootParamStability = getRootParamStability(getNextVersion());\n\nexport const swcPluginCompatible = comparePackageVersion(\n getNextVersion(),\n SWC_PLUGIN_SUPPORT\n);\n\n// disable babel plugin if using react <= 16\nexport const babelPluginCompatible = comparePackageVersion(\n getReactVersion(),\n BABEL_PLUGIN_SUPPORT\n);\n\n// Older refresh reducers can retain a stale layout after middleware redirects.\n// Related refresh/redirect issue: https://github.com/vercel/next.js/issues/65970\nexport const localeRefreshSupported = comparePackageVersion(\n getNextVersion(),\n LOCALE_REFRESH_SUPPORT\n);\n"],"mappings":";;;;;;AAeA,SAAS,kBAAkB,aAA6B;CACtD,MAAM,kBAAkB,GAAG,YAAY;AAEvC,KAAI;EACF,MAAM,0BAA0B,QAAQ,QAAQ,iBAAiB,EAC/D,OAAO,CAAC,QAAQ,KAAK,CAAC,EACvB,CAAC;AACF,SAAO,QAAQ,wBAAwB,CAAC;UACjC,QAAQ;AACf,SAAO,QAAQ,gBAAgB,CAAC;;;AAIpC,SAAS,iBAAyB;AAChC,KAAI;AACF,SAAO,kBAAkB,OAAO;UACzB,OAAO;AACd,QAAM,IAAI,MAAM,iCAAiC,MAAe,CAAC;;;;;;;AAQrE,SAAS,kBAA0B;AACjC,KAAI;AACF,SAAO,kBAAkB,QAAQ;UAC1B,OAAO;AACd,QAAM,IAAI,MAAM,kCAAkC,MAAe,CAAC;;;;;;;;;;AAWtE,SAAS,sBAAsB,GAAW,GAAoB;CAC5D,MAAM,SAAS,EAAE,MAAM,IAAI;CAC3B,MAAM,SAAS,EAAE,MAAM,IAAI;AAE3B,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO,OAAO,GAAG,IAAI;EACnC,MAAM,QAAQ,OAAO,OAAO,GAAG,IAAI;AAEnC,MAAI,QAAQ,MACV,QAAO;WACE,QAAQ,MACjB,QAAO;;AAKX,QAAO;;;;;;AAOT,MAAa,oBAAoB,sBAC/B,gBAAgB,EAChB,4BACD;;;;;;;AAUD,SAAgB,sBAAsB,aAAgC;AAEpE,KAAI,sBAAsB,aAAa,qBAAqB,OAAO,CACjE,QAAO;AAGT,KAAI,sBAAsB,aAAa,qBAAqB,aAAa,CACvE,QAAO;AAGT,KAAI,sBAAsB,aAAa,qBAAqB,SAAS,CACnE,QAAO;AAGT,QAAO;;AAGT,MAAa,qBAAqB,sBAAsB,gBAAgB,CAAC;AAEzE,MAAa,sBAAsB,sBACjC,gBAAgB,EAChB,mBACD;AAGD,MAAa,wBAAwB,sBACnC,iBAAiB,EACjB,qBACD;AAID,MAAa,yBAAyB,sBACpC,gBAAgB,EAChB,uBACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAMtD,wBAAsB,UAAU,CAAC,EAAE,QAAQ,EAAE,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAMtD,wBAAsB,UAAU,CAAC,EAAE,QAAQ,EAAE,EAAE,eAAe,oDAiC7D"}
|
|
@@ -16,12 +16,17 @@ async function GTProvider({ children }) {
|
|
|
16
16
|
const enableI18n = await require_request_getEnableI18n.getEnableI18n();
|
|
17
17
|
const translationsSnapshotPromise = i18nConfig.requiresTranslation(locale) ? i18nCache.loadTranslations(locale) : Promise.resolve({});
|
|
18
18
|
const dictionariesSnapshotPromise = i18nCache.loadDictionaries(locale);
|
|
19
|
+
const translationsSnapshot = { [locale]: await translationsSnapshotPromise };
|
|
20
|
+
const dictionariesSnapshot = await dictionariesSnapshotPromise;
|
|
19
21
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(___utils_client_boundary_js.Client_GTProvider, {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
supportsLocaleRefresh: process.env._GENERALTRANSLATION_LOCALE_REFRESH_SUPPORTED === "true",
|
|
23
|
+
conditions: {
|
|
24
|
+
locale,
|
|
25
|
+
region,
|
|
26
|
+
enableI18n
|
|
27
|
+
},
|
|
28
|
+
translations: translationsSnapshot,
|
|
29
|
+
dictionaries: dictionariesSnapshot,
|
|
25
30
|
children
|
|
26
31
|
});
|
|
27
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GTProvider.js","names":["getNextI18nCache","getLocale","getRegion","getEnableI18n","Client_GTProvider"],"sources":["../../src/provider/GTProvider.tsx"],"sourcesContent":["import { getLocale } from '../request/getLocale';\nimport { getRegion } from '../request/getRegion';\nimport type { GTProviderProps } from '../utils/types';\nimport { Client_GTProvider } from '../utils/client-boundary';\nimport { getNextI18nCache } from '../i18n-cache/NextI18nCache';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { getEnableI18n } from '../request/getEnableI18n';\n\nexport async function GTProvider({ children }: GTProviderProps) {\n // ---------- SETUP ---------- //\n const i18nCache = getNextI18nCache();\n const i18nConfig = getI18nConfig();\n const locale = await getLocale();\n const region = await getRegion();\n const enableI18n = await getEnableI18n();\n const translationRequired = i18nConfig.requiresTranslation(locale);\n\n // ----- FETCH TRANSLATIONS FROM CACHE ----- //\n\n const translationsSnapshotPromise = translationRequired\n ? i18nCache.loadTranslations(locale)\n : Promise.resolve({});\n\n const dictionariesSnapshotPromise = i18nCache.loadDictionaries(locale);\n\n // Block until cache check resolves\n const translationsSnapshot = { [locale]: await translationsSnapshotPromise };\n const dictionariesSnapshot = await dictionariesSnapshotPromise;\n\n return (\n <Client_GTProvider\n
|
|
1
|
+
{"version":3,"file":"GTProvider.js","names":["getNextI18nCache","getLocale","getRegion","getEnableI18n","Client_GTProvider"],"sources":["../../src/provider/GTProvider.tsx"],"sourcesContent":["import { getLocale } from '../request/getLocale';\nimport { getRegion } from '../request/getRegion';\nimport type { GTProviderProps } from '../utils/types';\nimport { Client_GTProvider } from '../utils/client-boundary';\nimport { getNextI18nCache } from '../i18n-cache/NextI18nCache';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { getEnableI18n } from '../request/getEnableI18n';\n\nexport async function GTProvider({ children }: GTProviderProps) {\n // ---------- SETUP ---------- //\n const i18nCache = getNextI18nCache();\n const i18nConfig = getI18nConfig();\n const locale = await getLocale();\n const region = await getRegion();\n const enableI18n = await getEnableI18n();\n const translationRequired = i18nConfig.requiresTranslation(locale);\n\n // ----- FETCH TRANSLATIONS FROM CACHE ----- //\n\n const translationsSnapshotPromise = translationRequired\n ? i18nCache.loadTranslations(locale)\n : Promise.resolve({});\n\n const dictionariesSnapshotPromise = i18nCache.loadDictionaries(locale);\n\n // Block until cache check resolves\n const translationsSnapshot = { [locale]: await translationsSnapshotPromise };\n const dictionariesSnapshot = await dictionariesSnapshotPromise;\n\n return (\n <Client_GTProvider\n supportsLocaleRefresh={\n process.env._GENERALTRANSLATION_LOCALE_REFRESH_SUPPORTED === 'true'\n }\n conditions={{ locale, region, enableI18n }}\n translations={translationsSnapshot}\n dictionaries={dictionariesSnapshot}\n >\n {children}\n </Client_GTProvider>\n );\n}\n"],"mappings":";;;;;;;;;;AAQA,eAAsB,WAAW,EAAE,YAA6B;CAE9D,MAAM,YAAYA,iCAAAA,kBAAkB;CACpC,MAAM,cAAA,GAAA,iBAAA,gBAA4B;CAClC,MAAM,SAAS,MAAMC,0BAAAA,WAAW;CAChC,MAAM,SAAS,MAAMC,0BAAAA,WAAW;CAChC,MAAM,aAAa,MAAMC,8BAAAA,eAAe;CAKxC,MAAM,8BAJsB,WAAW,oBAAoB,OAIJ,GACnD,UAAU,iBAAiB,OAAO,GAClC,QAAQ,QAAQ,EAAE,CAAC;CAEvB,MAAM,8BAA8B,UAAU,iBAAiB,OAAO;CAGtE,MAAM,uBAAuB,GAAG,SAAS,MAAM,6BAA6B;CAC5E,MAAM,uBAAuB,MAAM;AAEnC,QACE,iBAAA,GAAA,kBAAA,KAACC,4BAAAA,mBAAD;EACE,uBACE,QAAQ,IAAI,iDAAiD;EAE/D,YAAY;GAAE;GAAQ;GAAQ;GAAY;EAC1C,cAAc;EACd,cAAc;EAEb;EACiB,CAAA"}
|
|
@@ -14,12 +14,17 @@ async function GTProvider({ children }) {
|
|
|
14
14
|
const enableI18n = await getEnableI18n();
|
|
15
15
|
const translationsSnapshotPromise = i18nConfig.requiresTranslation(locale) ? i18nCache.loadTranslations(locale) : Promise.resolve({});
|
|
16
16
|
const dictionariesSnapshotPromise = i18nCache.loadDictionaries(locale);
|
|
17
|
+
const translationsSnapshot = { [locale]: await translationsSnapshotPromise };
|
|
18
|
+
const dictionariesSnapshot = await dictionariesSnapshotPromise;
|
|
17
19
|
return /* @__PURE__ */ jsx(Client_GTProvider, {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
supportsLocaleRefresh: process.env._GENERALTRANSLATION_LOCALE_REFRESH_SUPPORTED === "true",
|
|
21
|
+
conditions: {
|
|
22
|
+
locale,
|
|
23
|
+
region,
|
|
24
|
+
enableI18n
|
|
25
|
+
},
|
|
26
|
+
translations: translationsSnapshot,
|
|
27
|
+
dictionaries: dictionariesSnapshot,
|
|
23
28
|
children
|
|
24
29
|
});
|
|
25
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GTProvider.mjs","names":[],"sources":["../../src/provider/GTProvider.tsx"],"sourcesContent":["import { getLocale } from '../request/getLocale';\nimport { getRegion } from '../request/getRegion';\nimport type { GTProviderProps } from '../utils/types';\nimport { Client_GTProvider } from '../utils/client-boundary';\nimport { getNextI18nCache } from '../i18n-cache/NextI18nCache';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { getEnableI18n } from '../request/getEnableI18n';\n\nexport async function GTProvider({ children }: GTProviderProps) {\n // ---------- SETUP ---------- //\n const i18nCache = getNextI18nCache();\n const i18nConfig = getI18nConfig();\n const locale = await getLocale();\n const region = await getRegion();\n const enableI18n = await getEnableI18n();\n const translationRequired = i18nConfig.requiresTranslation(locale);\n\n // ----- FETCH TRANSLATIONS FROM CACHE ----- //\n\n const translationsSnapshotPromise = translationRequired\n ? i18nCache.loadTranslations(locale)\n : Promise.resolve({});\n\n const dictionariesSnapshotPromise = i18nCache.loadDictionaries(locale);\n\n // Block until cache check resolves\n const translationsSnapshot = { [locale]: await translationsSnapshotPromise };\n const dictionariesSnapshot = await dictionariesSnapshotPromise;\n\n return (\n <Client_GTProvider\n
|
|
1
|
+
{"version":3,"file":"GTProvider.mjs","names":[],"sources":["../../src/provider/GTProvider.tsx"],"sourcesContent":["import { getLocale } from '../request/getLocale';\nimport { getRegion } from '../request/getRegion';\nimport type { GTProviderProps } from '../utils/types';\nimport { Client_GTProvider } from '../utils/client-boundary';\nimport { getNextI18nCache } from '../i18n-cache/NextI18nCache';\nimport { getI18nConfig } from 'gt-i18n/internal';\nimport { getEnableI18n } from '../request/getEnableI18n';\n\nexport async function GTProvider({ children }: GTProviderProps) {\n // ---------- SETUP ---------- //\n const i18nCache = getNextI18nCache();\n const i18nConfig = getI18nConfig();\n const locale = await getLocale();\n const region = await getRegion();\n const enableI18n = await getEnableI18n();\n const translationRequired = i18nConfig.requiresTranslation(locale);\n\n // ----- FETCH TRANSLATIONS FROM CACHE ----- //\n\n const translationsSnapshotPromise = translationRequired\n ? i18nCache.loadTranslations(locale)\n : Promise.resolve({});\n\n const dictionariesSnapshotPromise = i18nCache.loadDictionaries(locale);\n\n // Block until cache check resolves\n const translationsSnapshot = { [locale]: await translationsSnapshotPromise };\n const dictionariesSnapshot = await dictionariesSnapshotPromise;\n\n return (\n <Client_GTProvider\n supportsLocaleRefresh={\n process.env._GENERALTRANSLATION_LOCALE_REFRESH_SUPPORTED === 'true'\n }\n conditions={{ locale, region, enableI18n }}\n translations={translationsSnapshot}\n dictionaries={dictionariesSnapshot}\n >\n {children}\n </Client_GTProvider>\n );\n}\n"],"mappings":";;;;;;;;AAQA,eAAsB,WAAW,EAAE,YAA6B;CAE9D,MAAM,YAAY,kBAAkB;CACpC,MAAM,aAAa,eAAe;CAClC,MAAM,SAAS,MAAM,WAAW;CAChC,MAAM,SAAS,MAAM,WAAW;CAChC,MAAM,aAAa,MAAM,eAAe;CAKxC,MAAM,8BAJsB,WAAW,oBAAoB,OAIJ,GACnD,UAAU,iBAAiB,OAAO,GAClC,QAAQ,QAAQ,EAAE,CAAC;CAEvB,MAAM,8BAA8B,UAAU,iBAAiB,OAAO;CAGtE,MAAM,uBAAuB,GAAG,SAAS,MAAM,6BAA6B;CAC5E,MAAM,uBAAuB,MAAM;AAEnC,QACE,oBAAC,mBAAD;EACE,uBACE,QAAQ,IAAI,iDAAiD;EAE/D,YAAY;GAAE;GAAQ;GAAQ;GAAY;EAC1C,cAAc;EACd,cAAc;EAEb;EACiB,CAAA"}
|
|
@@ -15,9 +15,9 @@ function resolveLocaleOrDefault(locale) {
|
|
|
15
15
|
const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
|
|
16
16
|
const defaultLocale = i18nConfig.getDefaultLocale();
|
|
17
17
|
const supportedLocale = typeof locale === "string" && locale.length > 0 ? i18nConfig.determineSupportedLocale(locale) : void 0;
|
|
18
|
-
if (supportedLocale) return
|
|
18
|
+
if (supportedLocale) return supportedLocale;
|
|
19
19
|
if (typeof locale === "string" && locale.length > 0) warnInvalidLocale(locale, defaultLocale);
|
|
20
|
-
return
|
|
20
|
+
return defaultLocale;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Checks whether a locale is valid and supported by the current gt-next config.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeValidation.js","names":["createInvalidRequestLocaleWarning"],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/request';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return
|
|
1
|
+
{"version":3,"file":"localeValidation.js","names":["createInvalidRequestLocaleWarning"],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/request';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return supportedLocale;\n\n if (typeof locale === 'string' && locale.length > 0) {\n warnInvalidLocale(locale, defaultLocale);\n }\n\n return defaultLocale;\n}\n\n/**\n * Checks whether a locale is valid and supported by the current gt-next config.\n *\n * Use this when route params or other request inputs should be rejected instead\n * of falling back to the default locale.\n *\n * @param locale - The locale candidate to validate.\n * @returns True when the locale resolves to one of the configured locales.\n */\nexport function isLocaleSupported(locale: unknown): locale is string {\n return determineSupportedLocale(locale) !== undefined;\n}\n"],"mappings":";;;;;AAGA,SAAS,yBAAyB,QAAqC;AACrE,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,EAAG,QAAO,KAAA;AAC9D,SAAA,GAAA,iBAAA,gBAAsB,CAAC,yBAAyB,OAAO;;AAGzD,SAAS,kBAAkB,QAAgB,eAAuB;AAChE,KACE,QAAQ,IAAI,uDAAuD,OAEnE;AAGF,SAAQ,KAAKA,uBAAAA,kCAAkC,QAAQ,cAAc,CAAC;;AAGxE,SAAgB,uBAAuB,QAAyB;CAC9D,MAAM,cAAA,GAAA,iBAAA,gBAA4B;CAClC,MAAM,gBAAgB,WAAW,kBAAkB;CACnD,MAAM,kBACJ,OAAO,WAAW,YAAY,OAAO,SAAS,IAC1C,WAAW,yBAAyB,OAAO,GAC3C,KAAA;AAEN,KAAI,gBAAiB,QAAO;AAE5B,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,mBAAkB,QAAQ,cAAc;AAG1C,QAAO;;;;;;;;;;;AAYT,SAAgB,kBAAkB,QAAmC;AACnE,QAAO,yBAAyB,OAAO,KAAK,KAAA"}
|
|
@@ -13,9 +13,9 @@ function resolveLocaleOrDefault(locale) {
|
|
|
13
13
|
const i18nConfig = getI18nConfig();
|
|
14
14
|
const defaultLocale = i18nConfig.getDefaultLocale();
|
|
15
15
|
const supportedLocale = typeof locale === "string" && locale.length > 0 ? i18nConfig.determineSupportedLocale(locale) : void 0;
|
|
16
|
-
if (supportedLocale) return
|
|
16
|
+
if (supportedLocale) return supportedLocale;
|
|
17
17
|
if (typeof locale === "string" && locale.length > 0) warnInvalidLocale(locale, defaultLocale);
|
|
18
|
-
return
|
|
18
|
+
return defaultLocale;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Checks whether a locale is valid and supported by the current gt-next config.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeValidation.mjs","names":[],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/request';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return
|
|
1
|
+
{"version":3,"file":"localeValidation.mjs","names":[],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/request';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return supportedLocale;\n\n if (typeof locale === 'string' && locale.length > 0) {\n warnInvalidLocale(locale, defaultLocale);\n }\n\n return defaultLocale;\n}\n\n/**\n * Checks whether a locale is valid and supported by the current gt-next config.\n *\n * Use this when route params or other request inputs should be rejected instead\n * of falling back to the default locale.\n *\n * @param locale - The locale candidate to validate.\n * @returns True when the locale resolves to one of the configured locales.\n */\nexport function isLocaleSupported(locale: unknown): locale is string {\n return determineSupportedLocale(locale) !== undefined;\n}\n"],"mappings":";;;AAGA,SAAS,yBAAyB,QAAqC;AACrE,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,EAAG,QAAO,KAAA;AAC9D,QAAO,eAAe,CAAC,yBAAyB,OAAO;;AAGzD,SAAS,kBAAkB,QAAgB,eAAuB;AAChE,KACE,QAAQ,IAAI,uDAAuD,OAEnE;AAGF,SAAQ,KAAK,kCAAkC,QAAQ,cAAc,CAAC;;AAGxE,SAAgB,uBAAuB,QAAyB;CAC9D,MAAM,aAAa,eAAe;CAClC,MAAM,gBAAgB,WAAW,kBAAkB;CACnD,MAAM,kBACJ,OAAO,WAAW,YAAY,OAAO,SAAS,IAC1C,WAAW,yBAAyB,OAAO,GAC3C,KAAA;AAEN,KAAI,gBAAiB,QAAO;AAE5B,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,mBAAkB,QAAQ,cAAc;AAG1C,QAAO;;;;;;;;;;;AAYT,SAAgB,kBAAkB,QAAmC;AACnE,QAAO,yBAAyB,OAAO,KAAK,KAAA"}
|
|
@@ -12,5 +12,8 @@ import { type SharedGTProviderProps } from 'gt-react';
|
|
|
12
12
|
/**
|
|
13
13
|
* Small wrapper to embed nextjs app router behavior
|
|
14
14
|
*/
|
|
15
|
-
export declare function Client_GTProvider(props: SharedGTProviderProps
|
|
15
|
+
export declare function Client_GTProvider({ conditions, supportsLocaleRefresh, ...props }: Omit<SharedGTProviderProps, 'locale' | 'region' | 'enableI18n' | '_serverConditions'> & {
|
|
16
|
+
conditions: NonNullable<SharedGTProviderProps['_serverConditions']>;
|
|
17
|
+
supportsLocaleRefresh: boolean;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
16
19
|
//# sourceMappingURL=client-boundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-boundary.d.ts","sourceRoot":"","sources":["../../src/utils/client-boundary.tsx"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,EAAc,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAsBlE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,qBAAqB,2CA+
|
|
1
|
+
{"version":3,"file":"client-boundary.d.ts","sourceRoot":"","sources":["../../src/utils/client-boundary.tsx"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,cAAc,IAAI,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAGnE,OAAO,EAAc,KAAK,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAsBlE;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,UAAU,EACV,qBAAqB,EACrB,GAAG,KAAK,EACT,EAAE,IAAI,CACL,qBAAqB,EACrB,QAAQ,GAAG,QAAQ,GAAG,YAAY,GAAG,mBAAmB,CACzD,GAAG;IACF,UAAU,EAAE,WAAW,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACpE,qBAAqB,EAAE,OAAO,CAAC;CAChC,2CA+DA"}
|
|
@@ -20,11 +20,15 @@ if (typeof window !== "undefined") require_setup_initGT_client.initializeGTClien
|
|
|
20
20
|
/**
|
|
21
21
|
* Small wrapper to embed nextjs app router behavior
|
|
22
22
|
*/
|
|
23
|
-
function Client_GTProvider(props) {
|
|
23
|
+
function Client_GTProvider({ conditions, supportsLocaleRefresh, ...props }) {
|
|
24
24
|
const router = (0, next_navigation_js.useRouter)();
|
|
25
25
|
const refreshServerComponents = (0, react.useCallback)(() => {
|
|
26
|
+
if (!supportsLocaleRefresh) {
|
|
27
|
+
globalThis.location.reload();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
26
30
|
router.refresh();
|
|
27
|
-
}, [router]);
|
|
31
|
+
}, [router, supportsLocaleRefresh]);
|
|
28
32
|
const reloadBrowserPage = (0, react.useCallback)(() => {
|
|
29
33
|
globalThis.location.reload();
|
|
30
34
|
}, []);
|
|
@@ -45,10 +49,12 @@ function Client_GTProvider(props) {
|
|
|
45
49
|
usePathCheck({
|
|
46
50
|
reloadBrowserPage,
|
|
47
51
|
refreshServerComponents,
|
|
48
|
-
locale:
|
|
52
|
+
locale: conditions.locale
|
|
49
53
|
});
|
|
50
54
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(gt_react.GTProvider, {
|
|
51
55
|
...props,
|
|
56
|
+
...conditions,
|
|
57
|
+
_serverConditions: conditions,
|
|
52
58
|
_reload: syncServerContent
|
|
53
59
|
});
|
|
54
60
|
}
|
|
@@ -61,7 +67,7 @@ function usePathCheck({ reloadBrowserPage, refreshServerComponents, locale, refe
|
|
|
61
67
|
const pathname = (0, next_navigation_js.usePathname)();
|
|
62
68
|
(0, react.useEffect)(() => {
|
|
63
69
|
const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
|
|
64
|
-
document.cookie = `${referrerLocaleCookieName}=${
|
|
70
|
+
document.cookie = `${referrerLocaleCookieName}=${locale};path=/`;
|
|
65
71
|
const locales = i18nConfig.getLocales();
|
|
66
72
|
const defaultLocale = i18nConfig.getDefaultLocale();
|
|
67
73
|
if ((0, gt_i18n_internal.getCookieValue)(document.cookie, localeRoutingEnabledCookieName) === "true" && require_utils_pathRegex.pathnameMatchesRegex(pathname, pathRegex)) {
|
|
@@ -82,14 +88,12 @@ function usePathCheck({ reloadBrowserPage, refreshServerComponents, locale, refe
|
|
|
82
88
|
]);
|
|
83
89
|
}
|
|
84
90
|
function resolvePathLocale(pathname, i18nConfig, defaultLocale, locales) {
|
|
85
|
-
const extractedLocale = extractLocale(pathname
|
|
91
|
+
const extractedLocale = extractLocale(pathname);
|
|
86
92
|
if (!extractedLocale) return defaultLocale;
|
|
87
|
-
|
|
88
|
-
return currentPathLocale ? i18nConfig.resolveAliasLocale(currentPathLocale) : defaultLocale;
|
|
93
|
+
return i18nConfig.determineLocale([extractedLocale], locales) ?? defaultLocale;
|
|
89
94
|
}
|
|
90
|
-
function extractLocale(pathname
|
|
91
|
-
|
|
92
|
-
return matches ? i18nConfig.resolveAliasLocale(matches[1]) : null;
|
|
95
|
+
function extractLocale(pathname) {
|
|
96
|
+
return pathname.match(/^\/([^/]+)(?:\/|$)/)?.[1] ?? null;
|
|
93
97
|
}
|
|
94
98
|
//#endregion
|
|
95
99
|
exports.Client_GTProvider = Client_GTProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-boundary.js","names":["compilePathRegex","defaultLocaleRoutingEnabledCookieName","pathnameMatchesRegex","GTProvider","defaultReferrerLocaleCookieName"],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getCookieValue, getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\nimport { compilePathRegex, pathnameMatchesRegex } from './pathRegex';\n\n// withGTConfig exposes this build-time value to both middleware and client code.\nconst pathRegex = compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider(props: SharedGTProviderProps) {\n const router = useRouter();\n const refreshServerComponents = useCallback(() => {\n router.refresh();\n }, [router]);\n const reloadBrowserPage = useCallback(() => {\n globalThis.location.reload();\n }, []);\n const syncServerContent = useCallback<\n NonNullable<SharedGTProviderProps['_reload']>\n >(\n ({ locale }) => {\n const i18nConfig = getI18nConfig();\n const localeRoutingEnabled =\n getCookieValue(\n document.cookie,\n defaultLocaleRoutingEnabledCookieName\n ) === 'true';\n const defaultLocale = i18nConfig.getDefaultLocale();\n const locales = i18nConfig.getLocales();\n const currentPathname = globalThis.location.pathname;\n const localeRoutingApplies =\n localeRoutingEnabled &&\n pathnameMatchesRegex(currentPathname, pathRegex);\n if (localeRoutingApplies && locale === defaultLocale) {\n const currentPathLocale = resolvePathLocale(\n currentPathname,\n i18nConfig,\n defaultLocale,\n locales\n );\n if (currentPathLocale !== defaultLocale) {\n reloadBrowserPage();\n return;\n }\n }\n\n refreshServerComponents();\n },\n [refreshServerComponents, reloadBrowserPage]\n );\n usePathCheck({\n reloadBrowserPage,\n refreshServerComponents,\n locale:
|
|
1
|
+
{"version":3,"file":"client-boundary.js","names":["compilePathRegex","defaultLocaleRoutingEnabledCookieName","pathnameMatchesRegex","GTProvider","defaultReferrerLocaleCookieName"],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getCookieValue, getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\nimport { compilePathRegex, pathnameMatchesRegex } from './pathRegex';\n\n// withGTConfig exposes this build-time value to both middleware and client code.\nconst pathRegex = compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider({\n conditions,\n supportsLocaleRefresh,\n ...props\n}: Omit<\n SharedGTProviderProps,\n 'locale' | 'region' | 'enableI18n' | '_serverConditions'\n> & {\n conditions: NonNullable<SharedGTProviderProps['_serverConditions']>;\n supportsLocaleRefresh: boolean;\n}) {\n const router = useRouter();\n const refreshServerComponents = useCallback(() => {\n // Older Next versions can retain a stale layout/provider after a redirect.\n if (!supportsLocaleRefresh) {\n globalThis.location.reload();\n return;\n }\n // The server supplies a fresh conditions object even when its accepted\n // locale is unchanged. For example, switching /en/careers to excluded 'fr'\n // returns another 'en' snapshot, which resets the browser store to 'en'\n // without discarding client state through a document reload.\n router.refresh();\n }, [router, supportsLocaleRefresh]);\n const reloadBrowserPage = useCallback(() => {\n globalThis.location.reload();\n }, []);\n const syncServerContent = useCallback<\n NonNullable<SharedGTProviderProps['_reload']>\n >(\n ({ locale }) => {\n const i18nConfig = getI18nConfig();\n const localeRoutingEnabled =\n getCookieValue(\n document.cookie,\n defaultLocaleRoutingEnabledCookieName\n ) === 'true';\n const defaultLocale = i18nConfig.getDefaultLocale();\n const locales = i18nConfig.getLocales();\n const currentPathname = globalThis.location.pathname;\n const localeRoutingApplies =\n localeRoutingEnabled &&\n pathnameMatchesRegex(currentPathname, pathRegex);\n if (localeRoutingApplies && locale === defaultLocale) {\n const currentPathLocale = resolvePathLocale(\n currentPathname,\n i18nConfig,\n defaultLocale,\n locales\n );\n if (currentPathLocale !== defaultLocale) {\n reloadBrowserPage();\n return;\n }\n }\n\n refreshServerComponents();\n },\n [refreshServerComponents, reloadBrowserPage]\n );\n usePathCheck({\n reloadBrowserPage,\n refreshServerComponents,\n locale: conditions.locale,\n });\n return (\n <GTProvider\n {...props}\n {...conditions}\n _serverConditions={conditions}\n _reload={syncServerContent}\n />\n );\n}\n\n/**\n * Synchronizes server content if the URL locale does not match the selected\n * locale.\n * TODO: optimize this hook\n */\nfunction usePathCheck({\n reloadBrowserPage,\n refreshServerComponents,\n locale,\n referrerLocaleCookieName = defaultReferrerLocaleCookieName,\n localeRoutingEnabledCookieName = defaultLocaleRoutingEnabledCookieName,\n}: {\n reloadBrowserPage: () => void;\n refreshServerComponents: () => void;\n locale: string;\n referrerLocaleCookieName?: string;\n localeRoutingEnabledCookieName?: string;\n}) {\n const pathname = usePathname();\n\n useEffect(() => {\n // Track the referrer locale for middleware\n const i18nConfig = getI18nConfig();\n document.cookie = `${referrerLocaleCookieName}=${locale};path=/`;\n\n // Synchronize server content if the pathname changes\n const locales = i18nConfig.getLocales();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const localeRoutingEnabled =\n getCookieValue(document.cookie, localeRoutingEnabledCookieName) ===\n 'true';\n if (localeRoutingEnabled && pathnameMatchesRegex(pathname, pathRegex)) {\n // Extract locale from pathname\n const currentPathLocale = resolvePathLocale(\n pathname,\n i18nConfig,\n defaultLocale,\n locales\n );\n\n // Both values are resolved to configured identities before comparison.\n if (\n currentPathLocale &&\n locales.includes(currentPathLocale) &&\n currentPathLocale !== locale\n ) {\n // clear cookie (avoids infinite loop when there is no middleware)\n document.cookie = `${localeRoutingEnabledCookieName}=;path=/`;\n\n if (locale === defaultLocale) {\n // A browser navigation follows the middleware redirect that removes\n // the default locale prefix. Next.js router.refresh() does not.\n reloadBrowserPage();\n } else {\n refreshServerComponents();\n }\n }\n }\n }, [\n pathname,\n locale,\n referrerLocaleCookieName,\n localeRoutingEnabledCookieName,\n reloadBrowserPage,\n refreshServerComponents,\n ]);\n}\n\nfunction resolvePathLocale(\n pathname: string,\n i18nConfig: I18nConfig,\n defaultLocale: string,\n locales: string[]\n): string {\n const extractedLocale = extractLocale(pathname);\n if (!extractedLocale) {\n return defaultLocale;\n }\n\n return (\n i18nConfig.determineLocale([extractedLocale], locales) ?? defaultLocale\n );\n}\n\nfunction extractLocale(pathname: string): string | null {\n return pathname.match(/^\\/([^/]+)(?:\\/|$)/)?.[1] ?? null;\n}\n"],"mappings":";;;;;;;;;;;;AA0BA,MAAM,YAAYA,wBAAAA,iBAAiB,QAAQ,IAAI,+BAA+B;;;;;;AAO9E,IAAI,OAAO,WAAW,YACpB,6BAAA,oBAAoB;;;;AAMtB,SAAgB,kBAAkB,EAChC,YACA,uBACA,GAAG,SAOF;CACD,MAAM,UAAA,GAAA,mBAAA,YAAoB;CAC1B,MAAM,2BAAA,GAAA,MAAA,mBAA4C;AAEhD,MAAI,CAAC,uBAAuB;AAC1B,cAAW,SAAS,QAAQ;AAC5B;;AAMF,SAAO,SAAS;IACf,CAAC,QAAQ,sBAAsB,CAAC;CACnC,MAAM,qBAAA,GAAA,MAAA,mBAAsC;AAC1C,aAAW,SAAS,QAAQ;IAC3B,EAAE,CAAC;CACN,MAAM,qBAAA,GAAA,MAAA,cAGH,EAAE,aAAa;EACd,MAAM,cAAA,GAAA,iBAAA,gBAA4B;EAClC,MAAM,wBAAA,GAAA,iBAAA,gBAEF,SAAS,QACTC,sBAAAA,sCACD,KAAK;EACR,MAAM,gBAAgB,WAAW,kBAAkB;EACnD,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,kBAAkB,WAAW,SAAS;AAI5C,MAFE,wBACAC,wBAAAA,qBAAqB,iBAAiB,UAAU,IACtB,WAAW;OACX,kBACxB,iBACA,YACA,eACA,QAEmB,KAAK,eAAe;AACvC,uBAAmB;AACnB;;;AAIJ,2BAAyB;IAE3B,CAAC,yBAAyB,kBAAkB,CAC7C;AACD,cAAa;EACX;EACA;EACA,QAAQ,WAAW;EACpB,CAAC;AACF,QACE,iBAAA,GAAA,kBAAA,KAACC,SAAAA,YAAD;EACE,GAAI;EACJ,GAAI;EACJ,mBAAmB;EACnB,SAAS;EACT,CAAA;;;;;;;AASN,SAAS,aAAa,EACpB,mBACA,yBACA,QACA,2BAA2BC,sBAAAA,iCAC3B,iCAAiCH,sBAAAA,yCAOhC;CACD,MAAM,YAAA,GAAA,mBAAA,cAAwB;AAE9B,EAAA,GAAA,MAAA,iBAAgB;EAEd,MAAM,cAAA,GAAA,iBAAA,gBAA4B;AAClC,WAAS,SAAS,GAAG,yBAAyB,GAAG,OAAO;EAGxD,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,gBAAgB,WAAW,kBAAkB;AAInD,OAAA,GAAA,iBAAA,gBAFiB,SAAS,QAAQ,+BAA+B,KAC/D,UAC0BC,wBAAAA,qBAAqB,UAAU,UAAU,EAAE;GAErE,MAAM,oBAAoB,kBACxB,UACA,YACA,eACA,QACD;AAGD,OACE,qBACA,QAAQ,SAAS,kBAAkB,IACnC,sBAAsB,QACtB;AAEA,aAAS,SAAS,GAAG,+BAA+B;AAEpD,QAAI,WAAW,cAGb,oBAAmB;QAEnB,0BAAyB;;;IAI9B;EACD;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;;AAGJ,SAAS,kBACP,UACA,YACA,eACA,SACQ;CACR,MAAM,kBAAkB,cAAc,SAAS;AAC/C,KAAI,CAAC,gBACH,QAAO;AAGT,QACE,WAAW,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,IAAI;;AAI9D,SAAS,cAAc,UAAiC;AACtD,QAAO,SAAS,MAAM,qBAAqB,GAAG,MAAM"}
|
|
@@ -18,11 +18,15 @@ if (typeof window !== "undefined") initializeGTClient();
|
|
|
18
18
|
/**
|
|
19
19
|
* Small wrapper to embed nextjs app router behavior
|
|
20
20
|
*/
|
|
21
|
-
function Client_GTProvider(props) {
|
|
21
|
+
function Client_GTProvider({ conditions, supportsLocaleRefresh, ...props }) {
|
|
22
22
|
const router = useRouter();
|
|
23
23
|
const refreshServerComponents = useCallback(() => {
|
|
24
|
+
if (!supportsLocaleRefresh) {
|
|
25
|
+
globalThis.location.reload();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
24
28
|
router.refresh();
|
|
25
|
-
}, [router]);
|
|
29
|
+
}, [router, supportsLocaleRefresh]);
|
|
26
30
|
const reloadBrowserPage = useCallback(() => {
|
|
27
31
|
globalThis.location.reload();
|
|
28
32
|
}, []);
|
|
@@ -43,10 +47,12 @@ function Client_GTProvider(props) {
|
|
|
43
47
|
usePathCheck({
|
|
44
48
|
reloadBrowserPage,
|
|
45
49
|
refreshServerComponents,
|
|
46
|
-
locale:
|
|
50
|
+
locale: conditions.locale
|
|
47
51
|
});
|
|
48
52
|
return /* @__PURE__ */ jsx(GTProvider, {
|
|
49
53
|
...props,
|
|
54
|
+
...conditions,
|
|
55
|
+
_serverConditions: conditions,
|
|
50
56
|
_reload: syncServerContent
|
|
51
57
|
});
|
|
52
58
|
}
|
|
@@ -59,7 +65,7 @@ function usePathCheck({ reloadBrowserPage, refreshServerComponents, locale, refe
|
|
|
59
65
|
const pathname = usePathname();
|
|
60
66
|
useEffect(() => {
|
|
61
67
|
const i18nConfig = getI18nConfig();
|
|
62
|
-
document.cookie = `${referrerLocaleCookieName}=${
|
|
68
|
+
document.cookie = `${referrerLocaleCookieName}=${locale};path=/`;
|
|
63
69
|
const locales = i18nConfig.getLocales();
|
|
64
70
|
const defaultLocale = i18nConfig.getDefaultLocale();
|
|
65
71
|
if (getCookieValue(document.cookie, localeRoutingEnabledCookieName) === "true" && pathnameMatchesRegex(pathname, pathRegex)) {
|
|
@@ -80,14 +86,12 @@ function usePathCheck({ reloadBrowserPage, refreshServerComponents, locale, refe
|
|
|
80
86
|
]);
|
|
81
87
|
}
|
|
82
88
|
function resolvePathLocale(pathname, i18nConfig, defaultLocale, locales) {
|
|
83
|
-
const extractedLocale = extractLocale(pathname
|
|
89
|
+
const extractedLocale = extractLocale(pathname);
|
|
84
90
|
if (!extractedLocale) return defaultLocale;
|
|
85
|
-
|
|
86
|
-
return currentPathLocale ? i18nConfig.resolveAliasLocale(currentPathLocale) : defaultLocale;
|
|
91
|
+
return i18nConfig.determineLocale([extractedLocale], locales) ?? defaultLocale;
|
|
87
92
|
}
|
|
88
|
-
function extractLocale(pathname
|
|
89
|
-
|
|
90
|
-
return matches ? i18nConfig.resolveAliasLocale(matches[1]) : null;
|
|
93
|
+
function extractLocale(pathname) {
|
|
94
|
+
return pathname.match(/^\/([^/]+)(?:\/|$)/)?.[1] ?? null;
|
|
91
95
|
}
|
|
92
96
|
//#endregion
|
|
93
97
|
export { Client_GTProvider, Client_LocaleSelector, Client_RegionSelector };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-boundary.mjs","names":[],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getCookieValue, getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\nimport { compilePathRegex, pathnameMatchesRegex } from './pathRegex';\n\n// withGTConfig exposes this build-time value to both middleware and client code.\nconst pathRegex = compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider(props: SharedGTProviderProps) {\n const router = useRouter();\n const refreshServerComponents = useCallback(() => {\n router.refresh();\n }, [router]);\n const reloadBrowserPage = useCallback(() => {\n globalThis.location.reload();\n }, []);\n const syncServerContent = useCallback<\n NonNullable<SharedGTProviderProps['_reload']>\n >(\n ({ locale }) => {\n const i18nConfig = getI18nConfig();\n const localeRoutingEnabled =\n getCookieValue(\n document.cookie,\n defaultLocaleRoutingEnabledCookieName\n ) === 'true';\n const defaultLocale = i18nConfig.getDefaultLocale();\n const locales = i18nConfig.getLocales();\n const currentPathname = globalThis.location.pathname;\n const localeRoutingApplies =\n localeRoutingEnabled &&\n pathnameMatchesRegex(currentPathname, pathRegex);\n if (localeRoutingApplies && locale === defaultLocale) {\n const currentPathLocale = resolvePathLocale(\n currentPathname,\n i18nConfig,\n defaultLocale,\n locales\n );\n if (currentPathLocale !== defaultLocale) {\n reloadBrowserPage();\n return;\n }\n }\n\n refreshServerComponents();\n },\n [refreshServerComponents, reloadBrowserPage]\n );\n usePathCheck({\n reloadBrowserPage,\n refreshServerComponents,\n locale:
|
|
1
|
+
{"version":3,"file":"client-boundary.mjs","names":[],"sources":["../../src/utils/client-boundary.tsx"],"sourcesContent":["'use client';\n\n/**\n * This is a small boundary for RSC consumption of client components\n * Cannot be consumed through gt-react/index.rsc as deciding btwn\n * gt-react/index.server and gt-react/index.client can only happen\n * here. This matters for GTProvider, but not for LocaleSelector.\n * This pattern is just good to follow for carrying over different\n * behaviors between client and server from gt-react.\n */\n\nexport { LocaleSelector as Client_LocaleSelector } from 'gt-react';\nexport { RegionSelector as Client_RegionSelector } from 'gt-react';\n\nimport { getCookieValue, getI18nConfig, I18nConfig } from 'gt-i18n/internal';\nimport { GTProvider, type SharedGTProviderProps } from 'gt-react';\nimport { usePathname, useRouter } from 'next/navigation';\nimport { useCallback, useEffect } from 'react';\nimport { initializeGTClient } from '../setup/initGT.client';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from './cookies';\nimport { compilePathRegex, pathnameMatchesRegex } from './pathRegex';\n\n// withGTConfig exposes this build-time value to both middleware and client code.\nconst pathRegex = compilePathRegex(process.env._GENERALTRANSLATION_PATH_REGEX);\n\n/**\n * Only need to initalize client. We know server was already\n * inialaized by index.rsc.ts. We do not know yet if client\n * has been initialized by index.client.ts.\n */\nif (typeof window !== 'undefined') {\n initializeGTClient();\n}\n\n/**\n * Small wrapper to embed nextjs app router behavior\n */\nexport function Client_GTProvider({\n conditions,\n supportsLocaleRefresh,\n ...props\n}: Omit<\n SharedGTProviderProps,\n 'locale' | 'region' | 'enableI18n' | '_serverConditions'\n> & {\n conditions: NonNullable<SharedGTProviderProps['_serverConditions']>;\n supportsLocaleRefresh: boolean;\n}) {\n const router = useRouter();\n const refreshServerComponents = useCallback(() => {\n // Older Next versions can retain a stale layout/provider after a redirect.\n if (!supportsLocaleRefresh) {\n globalThis.location.reload();\n return;\n }\n // The server supplies a fresh conditions object even when its accepted\n // locale is unchanged. For example, switching /en/careers to excluded 'fr'\n // returns another 'en' snapshot, which resets the browser store to 'en'\n // without discarding client state through a document reload.\n router.refresh();\n }, [router, supportsLocaleRefresh]);\n const reloadBrowserPage = useCallback(() => {\n globalThis.location.reload();\n }, []);\n const syncServerContent = useCallback<\n NonNullable<SharedGTProviderProps['_reload']>\n >(\n ({ locale }) => {\n const i18nConfig = getI18nConfig();\n const localeRoutingEnabled =\n getCookieValue(\n document.cookie,\n defaultLocaleRoutingEnabledCookieName\n ) === 'true';\n const defaultLocale = i18nConfig.getDefaultLocale();\n const locales = i18nConfig.getLocales();\n const currentPathname = globalThis.location.pathname;\n const localeRoutingApplies =\n localeRoutingEnabled &&\n pathnameMatchesRegex(currentPathname, pathRegex);\n if (localeRoutingApplies && locale === defaultLocale) {\n const currentPathLocale = resolvePathLocale(\n currentPathname,\n i18nConfig,\n defaultLocale,\n locales\n );\n if (currentPathLocale !== defaultLocale) {\n reloadBrowserPage();\n return;\n }\n }\n\n refreshServerComponents();\n },\n [refreshServerComponents, reloadBrowserPage]\n );\n usePathCheck({\n reloadBrowserPage,\n refreshServerComponents,\n locale: conditions.locale,\n });\n return (\n <GTProvider\n {...props}\n {...conditions}\n _serverConditions={conditions}\n _reload={syncServerContent}\n />\n );\n}\n\n/**\n * Synchronizes server content if the URL locale does not match the selected\n * locale.\n * TODO: optimize this hook\n */\nfunction usePathCheck({\n reloadBrowserPage,\n refreshServerComponents,\n locale,\n referrerLocaleCookieName = defaultReferrerLocaleCookieName,\n localeRoutingEnabledCookieName = defaultLocaleRoutingEnabledCookieName,\n}: {\n reloadBrowserPage: () => void;\n refreshServerComponents: () => void;\n locale: string;\n referrerLocaleCookieName?: string;\n localeRoutingEnabledCookieName?: string;\n}) {\n const pathname = usePathname();\n\n useEffect(() => {\n // Track the referrer locale for middleware\n const i18nConfig = getI18nConfig();\n document.cookie = `${referrerLocaleCookieName}=${locale};path=/`;\n\n // Synchronize server content if the pathname changes\n const locales = i18nConfig.getLocales();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const localeRoutingEnabled =\n getCookieValue(document.cookie, localeRoutingEnabledCookieName) ===\n 'true';\n if (localeRoutingEnabled && pathnameMatchesRegex(pathname, pathRegex)) {\n // Extract locale from pathname\n const currentPathLocale = resolvePathLocale(\n pathname,\n i18nConfig,\n defaultLocale,\n locales\n );\n\n // Both values are resolved to configured identities before comparison.\n if (\n currentPathLocale &&\n locales.includes(currentPathLocale) &&\n currentPathLocale !== locale\n ) {\n // clear cookie (avoids infinite loop when there is no middleware)\n document.cookie = `${localeRoutingEnabledCookieName}=;path=/`;\n\n if (locale === defaultLocale) {\n // A browser navigation follows the middleware redirect that removes\n // the default locale prefix. Next.js router.refresh() does not.\n reloadBrowserPage();\n } else {\n refreshServerComponents();\n }\n }\n }\n }, [\n pathname,\n locale,\n referrerLocaleCookieName,\n localeRoutingEnabledCookieName,\n reloadBrowserPage,\n refreshServerComponents,\n ]);\n}\n\nfunction resolvePathLocale(\n pathname: string,\n i18nConfig: I18nConfig,\n defaultLocale: string,\n locales: string[]\n): string {\n const extractedLocale = extractLocale(pathname);\n if (!extractedLocale) {\n return defaultLocale;\n }\n\n return (\n i18nConfig.determineLocale([extractedLocale], locales) ?? defaultLocale\n );\n}\n\nfunction extractLocale(pathname: string): string | null {\n return pathname.match(/^\\/([^/]+)(?:\\/|$)/)?.[1] ?? null;\n}\n"],"mappings":";;;;;;;;;;AA0BA,MAAM,YAAY,iBAAiB,QAAQ,IAAI,+BAA+B;;;;;;AAO9E,IAAI,OAAO,WAAW,YACpB,qBAAoB;;;;AAMtB,SAAgB,kBAAkB,EAChC,YACA,uBACA,GAAG,SAOF;CACD,MAAM,SAAS,WAAW;CAC1B,MAAM,0BAA0B,kBAAkB;AAEhD,MAAI,CAAC,uBAAuB;AAC1B,cAAW,SAAS,QAAQ;AAC5B;;AAMF,SAAO,SAAS;IACf,CAAC,QAAQ,sBAAsB,CAAC;CACnC,MAAM,oBAAoB,kBAAkB;AAC1C,aAAW,SAAS,QAAQ;IAC3B,EAAE,CAAC;CACN,MAAM,oBAAoB,aAGvB,EAAE,aAAa;EACd,MAAM,aAAa,eAAe;EAClC,MAAM,uBACJ,eACE,SAAS,QACT,sCACD,KAAK;EACR,MAAM,gBAAgB,WAAW,kBAAkB;EACnD,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,kBAAkB,WAAW,SAAS;AAI5C,MAFE,wBACA,qBAAqB,iBAAiB,UAAU,IACtB,WAAW;OACX,kBACxB,iBACA,YACA,eACA,QAEmB,KAAK,eAAe;AACvC,uBAAmB;AACnB;;;AAIJ,2BAAyB;IAE3B,CAAC,yBAAyB,kBAAkB,CAC7C;AACD,cAAa;EACX;EACA;EACA,QAAQ,WAAW;EACpB,CAAC;AACF,QACE,oBAAC,YAAD;EACE,GAAI;EACJ,GAAI;EACJ,mBAAmB;EACnB,SAAS;EACT,CAAA;;;;;;;AASN,SAAS,aAAa,EACpB,mBACA,yBACA,QACA,2BAA2B,iCAC3B,iCAAiC,yCAOhC;CACD,MAAM,WAAW,aAAa;AAE9B,iBAAgB;EAEd,MAAM,aAAa,eAAe;AAClC,WAAS,SAAS,GAAG,yBAAyB,GAAG,OAAO;EAGxD,MAAM,UAAU,WAAW,YAAY;EACvC,MAAM,gBAAgB,WAAW,kBAAkB;AAInD,MAFE,eAAe,SAAS,QAAQ,+BAA+B,KAC/D,UAC0B,qBAAqB,UAAU,UAAU,EAAE;GAErE,MAAM,oBAAoB,kBACxB,UACA,YACA,eACA,QACD;AAGD,OACE,qBACA,QAAQ,SAAS,kBAAkB,IACnC,sBAAsB,QACtB;AAEA,aAAS,SAAS,GAAG,+BAA+B;AAEpD,QAAI,WAAW,cAGb,oBAAmB;QAEnB,0BAAyB;;;IAI9B;EACD;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;;AAGJ,SAAS,kBACP,UACA,YACA,eACA,SACQ;CACR,MAAM,kBAAkB,cAAc,SAAS;AAC/C,KAAI,CAAC,gBACH,QAAO;AAGT,QACE,WAAW,gBAAgB,CAAC,gBAAgB,EAAE,QAAQ,IAAI;;AAI9D,SAAS,cAAc,UAAiC;AACtD,QAAO,SAAS,MAAM,qBAAqB,GAAG,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-next",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.4.0",
|
|
4
4
|
"description": "A Next.js library for automatic internationalization.",
|
|
5
5
|
"main": "dist/index.server.js",
|
|
6
6
|
"peerDependencies": {
|
|
7
|
-
"@generaltranslation/compiler": "^1.3.
|
|
7
|
+
"@generaltranslation/compiler": "^1.3.53",
|
|
8
8
|
"next": ">=13.0.0 <15.2.1 || >15.2.2",
|
|
9
9
|
"react": ">=16.8.0 <20.0.0",
|
|
10
10
|
"react-dom": ">=16.8.0 <20.0.0"
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"./dist/utils/client-boundary.*"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@generaltranslation/format": "0.1.
|
|
32
|
-
"@generaltranslation/react-core": "11.
|
|
33
|
-
"generaltranslation": "9.4.
|
|
34
|
-
"gt-react": "11.
|
|
35
|
-
"gt-i18n": "1.0.
|
|
31
|
+
"@generaltranslation/format": "0.1.9",
|
|
32
|
+
"@generaltranslation/react-core": "11.4.0",
|
|
33
|
+
"generaltranslation": "9.4.1",
|
|
34
|
+
"gt-react": "11.4.0",
|
|
35
|
+
"gt-i18n": "1.0.28"
|
|
36
36
|
},
|
|
37
37
|
"repository": {
|
|
38
38
|
"type": "git",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"next": "15.2.3",
|
|
53
53
|
"tsdown": "^0.21.10",
|
|
54
54
|
"typescript": "^5.9.2",
|
|
55
|
-
"@generaltranslation/compiler": "1.3.
|
|
55
|
+
"@generaltranslation/compiler": "1.3.53"
|
|
56
56
|
},
|
|
57
57
|
"exports": {
|
|
58
58
|
".": {
|