vinext 0.0.51 → 0.0.52
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/dist/build/precompress.d.ts +7 -7
- package/dist/build/precompress.js +18 -17
- package/dist/build/precompress.js.map +1 -1
- package/dist/build/prerender.d.ts +3 -14
- package/dist/build/prerender.js +40 -40
- package/dist/build/prerender.js.map +1 -1
- package/dist/check.js +4 -0
- package/dist/check.js.map +1 -1
- package/dist/cli-args.d.ts +1 -0
- package/dist/cli-args.js +5 -0
- package/dist/cli-args.js.map +1 -1
- package/dist/cli.js +39 -0
- package/dist/cli.js.map +1 -1
- package/dist/client/navigation-runtime.d.ts +47 -0
- package/dist/client/navigation-runtime.js +156 -0
- package/dist/client/navigation-runtime.js.map +1 -0
- package/dist/client/pages-router-link-navigation.d.ts +26 -0
- package/dist/client/pages-router-link-navigation.js +14 -0
- package/dist/client/pages-router-link-navigation.js.map +1 -0
- package/dist/client/vinext-next-data.d.ts +12 -2
- package/dist/client/vinext-next-data.js +50 -1
- package/dist/client/vinext-next-data.js.map +1 -0
- package/dist/cloudflare/kv-cache-handler.js +2 -1
- package/dist/cloudflare/kv-cache-handler.js.map +1 -1
- package/dist/config/config-matchers.d.ts +63 -16
- package/dist/config/config-matchers.js +143 -8
- package/dist/config/config-matchers.js.map +1 -1
- package/dist/config/next-config.d.ts +20 -2
- package/dist/config/next-config.js +11 -1
- package/dist/config/next-config.js.map +1 -1
- package/dist/deploy.js +101 -39
- package/dist/deploy.js.map +1 -1
- package/dist/entries/app-browser-entry.js +9 -3
- package/dist/entries/app-browser-entry.js.map +1 -1
- package/dist/entries/app-rsc-entry.js +53 -13
- package/dist/entries/app-rsc-entry.js.map +1 -1
- package/dist/entries/app-rsc-manifest.d.ts +1 -0
- package/dist/entries/app-rsc-manifest.js +53 -6
- package/dist/entries/app-rsc-manifest.js.map +1 -1
- package/dist/entries/app-ssr-entry.d.ts +3 -3
- package/dist/entries/app-ssr-entry.js +4 -4
- package/dist/entries/app-ssr-entry.js.map +1 -1
- package/dist/entries/pages-client-entry.js +18 -2
- package/dist/entries/pages-client-entry.js.map +1 -1
- package/dist/entries/pages-server-entry.js +58 -8
- package/dist/entries/pages-server-entry.js.map +1 -1
- package/dist/entries/runtime-entry-module.d.ts +2 -1
- package/dist/entries/runtime-entry-module.js +9 -3
- package/dist/entries/runtime-entry-module.js.map +1 -1
- package/dist/index.js +132 -40
- package/dist/index.js.map +1 -1
- package/dist/plugins/css-data-url.d.ts +7 -0
- package/dist/plugins/css-data-url.js +81 -0
- package/dist/plugins/css-data-url.js.map +1 -0
- package/dist/plugins/fonts.js +5 -3
- package/dist/plugins/fonts.js.map +1 -1
- package/dist/plugins/middleware-server-only.d.ts +54 -0
- package/dist/plugins/middleware-server-only.js +91 -0
- package/dist/plugins/middleware-server-only.js.map +1 -0
- package/dist/plugins/optimize-imports.js +4 -4
- package/dist/plugins/optimize-imports.js.map +1 -1
- package/dist/plugins/strip-server-exports.js +5 -8
- package/dist/plugins/strip-server-exports.js.map +1 -1
- package/dist/routing/app-route-graph.d.ts +20 -1
- package/dist/routing/app-route-graph.js +58 -6
- package/dist/routing/app-route-graph.js.map +1 -1
- package/dist/routing/app-router.d.ts +2 -2
- package/dist/routing/app-router.js +2 -2
- package/dist/routing/app-router.js.map +1 -1
- package/dist/routing/utils.d.ts +2 -1
- package/dist/routing/utils.js +4 -1
- package/dist/routing/utils.js.map +1 -1
- package/dist/server/api-handler.js +139 -37
- package/dist/server/api-handler.js.map +1 -1
- package/dist/server/app-browser-entry.js +293 -149
- package/dist/server/app-browser-entry.js.map +1 -1
- package/dist/server/app-browser-interception-context.d.ts +24 -0
- package/dist/server/app-browser-interception-context.js +32 -0
- package/dist/server/app-browser-interception-context.js.map +1 -0
- package/dist/server/app-browser-navigation-controller.d.ts +3 -1
- package/dist/server/app-browser-navigation-controller.js +5 -1
- package/dist/server/app-browser-navigation-controller.js.map +1 -1
- package/dist/server/app-browser-rsc-redirect.d.ts +2 -1
- package/dist/server/app-browser-rsc-redirect.js +2 -2
- package/dist/server/app-browser-rsc-redirect.js.map +1 -1
- package/dist/server/app-browser-state.d.ts +18 -1
- package/dist/server/app-browser-state.js +19 -1
- package/dist/server/app-browser-state.js.map +1 -1
- package/dist/server/app-browser-stream.d.ts +5 -14
- package/dist/server/app-browser-stream.js +13 -7
- package/dist/server/app-browser-stream.js.map +1 -1
- package/dist/server/app-browser-visible-commit.d.ts +2 -1
- package/dist/server/app-browser-visible-commit.js +1 -0
- package/dist/server/app-browser-visible-commit.js.map +1 -1
- package/dist/server/app-elements-wire.d.ts +10 -5
- package/dist/server/app-elements-wire.js +84 -2
- package/dist/server/app-elements-wire.js.map +1 -1
- package/dist/server/app-elements.d.ts +3 -2
- package/dist/server/app-elements.js +3 -2
- package/dist/server/app-elements.js.map +1 -1
- package/dist/server/app-fallback-renderer.js +5 -3
- package/dist/server/app-fallback-renderer.js.map +1 -1
- package/dist/server/app-middleware.d.ts +13 -0
- package/dist/server/app-middleware.js +3 -1
- package/dist/server/app-middleware.js.map +1 -1
- package/dist/server/app-optimistic-routing.d.ts +54 -0
- package/dist/server/app-optimistic-routing.js +200 -0
- package/dist/server/app-optimistic-routing.js.map +1 -0
- package/dist/server/app-page-cache.d.ts +13 -1
- package/dist/server/app-page-cache.js +61 -6
- package/dist/server/app-page-cache.js.map +1 -1
- package/dist/server/app-page-dispatch.d.ts +2 -0
- package/dist/server/app-page-dispatch.js +28 -1
- package/dist/server/app-page-dispatch.js.map +1 -1
- package/dist/server/app-page-element-builder.js +2 -1
- package/dist/server/app-page-element-builder.js.map +1 -1
- package/dist/server/app-page-execution.d.ts +28 -1
- package/dist/server/app-page-execution.js +89 -4
- package/dist/server/app-page-execution.js.map +1 -1
- package/dist/server/app-page-head.js +21 -2
- package/dist/server/app-page-head.js.map +1 -1
- package/dist/server/app-page-probe.js +1 -1
- package/dist/server/app-page-render.d.ts +2 -0
- package/dist/server/app-page-render.js +2 -1
- package/dist/server/app-page-render.js.map +1 -1
- package/dist/server/app-page-response.js +4 -3
- package/dist/server/app-page-response.js.map +1 -1
- package/dist/server/app-page-route-wiring.js +17 -10
- package/dist/server/app-page-route-wiring.js.map +1 -1
- package/dist/server/app-page-stream.d.ts +3 -0
- package/dist/server/app-page-stream.js +1 -0
- package/dist/server/app-page-stream.js.map +1 -1
- package/dist/server/app-prerender-static-params.d.ts +2 -1
- package/dist/server/app-prerender-static-params.js +44 -8
- package/dist/server/app-prerender-static-params.js.map +1 -1
- package/dist/server/app-route-handler-cache.d.ts +2 -2
- package/dist/server/app-route-handler-cache.js +3 -2
- package/dist/server/app-route-handler-cache.js.map +1 -1
- package/dist/server/app-route-handler-dispatch.d.ts +6 -1
- package/dist/server/app-route-handler-dispatch.js +1 -1
- package/dist/server/app-route-handler-dispatch.js.map +1 -1
- package/dist/server/app-route-handler-execution.d.ts +17 -2
- package/dist/server/app-route-handler-execution.js.map +1 -1
- package/dist/server/app-route-handler-response.js +5 -4
- package/dist/server/app-route-handler-response.js.map +1 -1
- package/dist/server/app-router-entry.js +6 -2
- package/dist/server/app-router-entry.js.map +1 -1
- package/dist/server/app-rsc-handler.d.ts +9 -1
- package/dist/server/app-rsc-handler.js +32 -14
- package/dist/server/app-rsc-handler.js.map +1 -1
- package/dist/server/app-rsc-render-mode.d.ts +4 -3
- package/dist/server/app-rsc-render-mode.js +7 -1
- package/dist/server/app-rsc-render-mode.js.map +1 -1
- package/dist/server/app-rsc-request-normalization.d.ts +4 -1
- package/dist/server/app-rsc-request-normalization.js +4 -1
- package/dist/server/app-rsc-request-normalization.js.map +1 -1
- package/dist/server/app-rsc-response-finalizer.d.ts +8 -1
- package/dist/server/app-rsc-response-finalizer.js +10 -3
- package/dist/server/app-rsc-response-finalizer.js.map +1 -1
- package/dist/server/app-rsc-route-matching.js +2 -2
- package/dist/server/app-rsc-route-matching.js.map +1 -1
- package/dist/server/app-server-action-execution.js +1 -1
- package/dist/server/app-ssr-entry.d.ts +2 -0
- package/dist/server/app-ssr-entry.js +56 -55
- package/dist/server/app-ssr-entry.js.map +1 -1
- package/dist/server/app-ssr-stream.d.ts +6 -1
- package/dist/server/app-ssr-stream.js +17 -3
- package/dist/server/app-ssr-stream.js.map +1 -1
- package/dist/server/artifact-compatibility.d.ts +1 -1
- package/dist/server/artifact-compatibility.js.map +1 -1
- package/dist/server/cache-headers.d.ts +7 -0
- package/dist/server/cache-headers.js +19 -0
- package/dist/server/cache-headers.js.map +1 -0
- package/dist/server/cache-proof.d.ts +49 -3
- package/dist/server/cache-proof.js +78 -22
- package/dist/server/cache-proof.js.map +1 -1
- package/dist/server/client-reuse-manifest.d.ts +99 -0
- package/dist/server/client-reuse-manifest.js +212 -0
- package/dist/server/client-reuse-manifest.js.map +1 -0
- package/dist/server/default-global-error-module.d.ts +20 -0
- package/dist/server/default-global-error-module.js +20 -0
- package/dist/server/default-global-error-module.js.map +1 -0
- package/dist/server/dev-server.d.ts +9 -1
- package/dist/server/dev-server.js +76 -29
- package/dist/server/dev-server.js.map +1 -1
- package/dist/server/edge-api-runtime.d.ts +5 -0
- package/dist/server/edge-api-runtime.js +8 -0
- package/dist/server/edge-api-runtime.js.map +1 -0
- package/dist/server/headers.d.ts +18 -1
- package/dist/server/headers.js +18 -1
- package/dist/server/headers.js.map +1 -1
- package/dist/server/http-error-responses.d.ts +16 -1
- package/dist/server/http-error-responses.js +21 -1
- package/dist/server/http-error-responses.js.map +1 -1
- package/dist/server/isr-cache.d.ts +6 -2
- package/dist/server/isr-cache.js +20 -4
- package/dist/server/isr-cache.js.map +1 -1
- package/dist/server/middleware-runtime.d.ts +15 -0
- package/dist/server/middleware-runtime.js +59 -7
- package/dist/server/middleware-runtime.js.map +1 -1
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +4 -2
- package/dist/server/middleware.js.map +1 -1
- package/dist/server/navigation-planner.d.ts +9 -3
- package/dist/server/navigation-planner.js +98 -25
- package/dist/server/navigation-planner.js.map +1 -1
- package/dist/server/navigation-trace.d.ts +2 -1
- package/dist/server/navigation-trace.js +1 -0
- package/dist/server/navigation-trace.js.map +1 -1
- package/dist/server/pages-api-route.d.ts +27 -1
- package/dist/server/pages-api-route.js +24 -3
- package/dist/server/pages-api-route.js.map +1 -1
- package/dist/server/pages-data-route.d.ts +77 -0
- package/dist/server/pages-data-route.js +97 -0
- package/dist/server/pages-data-route.js.map +1 -0
- package/dist/server/pages-i18n.d.ts +51 -1
- package/dist/server/pages-i18n.js +61 -1
- package/dist/server/pages-i18n.js.map +1 -1
- package/dist/server/pages-page-data.d.ts +29 -2
- package/dist/server/pages-page-data.js +31 -17
- package/dist/server/pages-page-data.js.map +1 -1
- package/dist/server/pages-page-response.d.ts +11 -1
- package/dist/server/pages-page-response.js +5 -3
- package/dist/server/pages-page-response.js.map +1 -1
- package/dist/server/prod-server.d.ts +13 -15
- package/dist/server/prod-server.js +109 -56
- package/dist/server/prod-server.js.map +1 -1
- package/dist/server/request-pipeline.d.ts +11 -2
- package/dist/server/request-pipeline.js +28 -11
- package/dist/server/request-pipeline.js.map +1 -1
- package/dist/server/seed-cache.d.ts +12 -31
- package/dist/server/seed-cache.js +22 -35
- package/dist/server/seed-cache.js.map +1 -1
- package/dist/server/server-action-not-found.js +8 -3
- package/dist/server/server-action-not-found.js.map +1 -1
- package/dist/server/skip-cache-proof.d.ts +41 -0
- package/dist/server/skip-cache-proof.js +101 -0
- package/dist/server/skip-cache-proof.js.map +1 -0
- package/dist/server/static-file-cache.d.ts +1 -1
- package/dist/server/static-file-cache.js +7 -6
- package/dist/server/static-file-cache.js.map +1 -1
- package/dist/shims/client-locale.d.ts +15 -0
- package/dist/shims/client-locale.js +13 -0
- package/dist/shims/client-locale.js.map +1 -0
- package/dist/shims/default-global-error.d.ts +32 -0
- package/dist/shims/default-global-error.js +181 -0
- package/dist/shims/default-global-error.js.map +1 -0
- package/dist/shims/document.d.ts +59 -3
- package/dist/shims/document.js +36 -5
- package/dist/shims/document.js.map +1 -1
- package/dist/shims/error-boundary.d.ts +2 -2
- package/dist/shims/form.js +13 -6
- package/dist/shims/form.js.map +1 -1
- package/dist/shims/link.d.ts +21 -3
- package/dist/shims/link.js +131 -22
- package/dist/shims/link.js.map +1 -1
- package/dist/shims/metadata.js +4 -4
- package/dist/shims/metadata.js.map +1 -1
- package/dist/shims/navigation.d.ts +8 -2
- package/dist/shims/navigation.js +36 -15
- package/dist/shims/navigation.js.map +1 -1
- package/dist/shims/og.d.ts +18 -2
- package/dist/shims/og.js +49 -1
- package/dist/shims/og.js.map +1 -0
- package/dist/shims/request-state-types.d.ts +1 -1
- package/dist/shims/root-params.d.ts +3 -1
- package/dist/shims/root-params.js +11 -3
- package/dist/shims/root-params.js.map +1 -1
- package/dist/shims/router-state.d.ts +1 -0
- package/dist/shims/router-state.js.map +1 -1
- package/dist/shims/router.d.ts +12 -5
- package/dist/shims/router.js +172 -22
- package/dist/shims/router.js.map +1 -1
- package/dist/shims/server.d.ts +21 -4
- package/dist/shims/server.js +29 -9
- package/dist/shims/server.js.map +1 -1
- package/dist/shims/slot.js +5 -1
- package/dist/shims/slot.js.map +1 -1
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/url-safety.d.ts +23 -1
- package/dist/shims/url-safety.js +29 -2
- package/dist/shims/url-safety.js.map +1 -1
- package/dist/typegen.d.ts +10 -0
- package/dist/typegen.js +242 -0
- package/dist/typegen.js.map +1 -0
- package/dist/utils/asset-prefix.d.ts +33 -5
- package/dist/utils/asset-prefix.js +39 -6
- package/dist/utils/asset-prefix.js.map +1 -1
- package/dist/utils/cache-control-metadata.d.ts +2 -1
- package/dist/utils/cache-control-metadata.js +1 -3
- package/dist/utils/cache-control-metadata.js.map +1 -1
- package/dist/utils/domain-locale.d.ts +2 -1
- package/dist/utils/domain-locale.js +9 -1
- package/dist/utils/domain-locale.js.map +1 -1
- package/dist/utils/lazy-chunks.d.ts +1 -1
- package/dist/utils/lazy-chunks.js +1 -1
- package/dist/utils/lazy-chunks.js.map +1 -1
- package/dist/utils/prerender-output-paths.d.ts +15 -0
- package/dist/utils/prerender-output-paths.js +24 -0
- package/dist/utils/prerender-output-paths.js.map +1 -0
- package/dist/utils/query.d.ts +17 -1
- package/dist/utils/query.js +36 -1
- package/dist/utils/query.js.map +1 -1
- package/dist/utils/record.d.ts +5 -0
- package/dist/utils/record.js +8 -0
- package/dist/utils/record.js.map +1 -0
- package/package.json +11 -3
|
@@ -6,6 +6,8 @@ type RootParamsState = {
|
|
|
6
6
|
declare function pickRootParams(params: RootParams, rootParamNames: readonly string[] | null | undefined): RootParams;
|
|
7
7
|
declare function setRootParams(params: RootParams | null): void;
|
|
8
8
|
declare function getRootParam(name: string): Promise<string | string[] | undefined>;
|
|
9
|
+
declare function runWithRootParamsScope<T>(params: RootParams, fn: () => Promise<T>): Promise<T>;
|
|
10
|
+
declare function runWithRootParamsScope<T>(params: RootParams, fn: () => T | Promise<T>): T | Promise<T>;
|
|
9
11
|
//#endregion
|
|
10
|
-
export { RootParams, RootParamsState, getRootParam, pickRootParams, setRootParams };
|
|
12
|
+
export { RootParams, RootParamsState, getRootParam, pickRootParams, runWithRootParamsScope, setRootParams };
|
|
11
13
|
//# sourceMappingURL=root-params.d.ts.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
|
+
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
2
3
|
//#region src/shims/root-params.ts
|
|
3
4
|
const _FALLBACK_KEY = Symbol.for("vinext.rootParams.fallback");
|
|
4
5
|
const _g = globalThis;
|
|
6
|
+
const _als = getOrCreateAls("vinext.rootParams.als");
|
|
5
7
|
const _fallbackState = _g[_FALLBACK_KEY] ??= { rootParams: null };
|
|
6
8
|
function getState() {
|
|
7
9
|
if (isInsideUnifiedScope()) return getRequestContext();
|
|
8
|
-
return _fallbackState;
|
|
10
|
+
return _als.getStore() ?? _fallbackState;
|
|
9
11
|
}
|
|
10
12
|
function pickRootParams(params, rootParamNames) {
|
|
11
13
|
const picked = {};
|
|
@@ -18,7 +20,13 @@ function setRootParams(params) {
|
|
|
18
20
|
function getRootParam(name) {
|
|
19
21
|
return Promise.resolve(getState().rootParams?.[name]);
|
|
20
22
|
}
|
|
23
|
+
function runWithRootParamsScope(params, fn) {
|
|
24
|
+
if (isInsideUnifiedScope()) return runWithUnifiedStateMutation((ctx) => {
|
|
25
|
+
ctx.rootParams = params;
|
|
26
|
+
}, fn);
|
|
27
|
+
else return _als.run({ rootParams: params }, fn);
|
|
28
|
+
}
|
|
21
29
|
//#endregion
|
|
22
|
-
export { getRootParam, pickRootParams, setRootParams };
|
|
30
|
+
export { getRootParam, pickRootParams, runWithRootParamsScope, setRootParams };
|
|
23
31
|
|
|
24
32
|
//# sourceMappingURL=root-params.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root-params.js","names":[],"sources":["../../src/shims/root-params.ts"],"sourcesContent":["import { getRequestContext
|
|
1
|
+
{"version":3,"file":"root-params.js","names":[],"sources":["../../src/shims/root-params.ts"],"sourcesContent":["import { getOrCreateAls } from \"./internal/als-registry.js\";\nimport {\n getRequestContext,\n isInsideUnifiedScope,\n runWithUnifiedStateMutation,\n} from \"./unified-request-context.js\";\n\nexport type RootParams = Record<string, string | string[] | undefined>;\n\nexport type RootParamsState = {\n rootParams: RootParams | null;\n};\n\nconst _FALLBACK_KEY = Symbol.for(\"vinext.rootParams.fallback\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = getOrCreateAls<RootParamsState>(\"vinext.rootParams.als\");\n\nconst _fallbackState = (_g[_FALLBACK_KEY] ??= {\n rootParams: null,\n} satisfies RootParamsState) as RootParamsState;\n\nfunction getState(): RootParamsState {\n if (isInsideUnifiedScope()) {\n return getRequestContext();\n }\n return _als.getStore() ?? _fallbackState;\n}\n\nexport function pickRootParams(\n params: RootParams,\n rootParamNames: readonly string[] | null | undefined,\n): RootParams {\n const picked: RootParams = {};\n for (const name of rootParamNames ?? []) {\n picked[name] = params[name];\n }\n return picked;\n}\n\nexport function setRootParams(params: RootParams | null): void {\n getState().rootParams = params;\n}\n\nexport function getRootParam(name: string): Promise<string | string[] | undefined> {\n return Promise.resolve(getState().rootParams?.[name]);\n}\n\nexport function runWithRootParamsScope<T>(params: RootParams, fn: () => Promise<T>): Promise<T>;\nexport function runWithRootParamsScope<T>(\n params: RootParams,\n fn: () => T | Promise<T>,\n): T | Promise<T>;\nexport function runWithRootParamsScope<T>(\n params: RootParams,\n fn: () => T | Promise<T>,\n): T | Promise<T> {\n if (isInsideUnifiedScope()) {\n return runWithUnifiedStateMutation((ctx) => {\n ctx.rootParams = params;\n }, fn);\n } else {\n return _als.run({ rootParams: params }, fn);\n }\n}\n"],"mappings":";;;AAaA,MAAM,gBAAgB,OAAO,IAAI,6BAA6B;AAC9D,MAAM,KAAK;AACX,MAAM,OAAO,eAAgC,wBAAwB;AAErE,MAAM,iBAAkB,GAAG,mBAAmB,EAC5C,YAAY,MACb;AAED,SAAS,WAA4B;CACnC,IAAI,sBAAsB,EACxB,OAAO,mBAAmB;CAE5B,OAAO,KAAK,UAAU,IAAI;;AAG5B,SAAgB,eACd,QACA,gBACY;CACZ,MAAM,SAAqB,EAAE;CAC7B,KAAK,MAAM,QAAQ,kBAAkB,EAAE,EACrC,OAAO,QAAQ,OAAO;CAExB,OAAO;;AAGT,SAAgB,cAAc,QAAiC;CAC7D,UAAU,CAAC,aAAa;;AAG1B,SAAgB,aAAa,MAAsD;CACjF,OAAO,QAAQ,QAAQ,UAAU,CAAC,aAAa,MAAM;;AAQvD,SAAgB,uBACd,QACA,IACgB;CAChB,IAAI,sBAAsB,EACxB,OAAO,6BAA6B,QAAQ;EAC1C,IAAI,aAAa;IAChB,GAAG;MAEN,OAAO,KAAK,IAAI,EAAE,YAAY,QAAQ,EAAE,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-state.js","names":[],"sources":["../../src/shims/router-state.ts"],"sourcesContent":["/**\n * Server-only Pages Router state backed by AsyncLocalStorage.\n *\n * Provides request-scoped isolation for SSR context (pathname, query,\n * locale) so concurrent requests on Workers don't share state.\n *\n * This module is server-only — it imports node:async_hooks and must NOT\n * be bundled for the browser.\n */\n\nimport { _registerRouterStateAccessors } from \"./router.js\";\nimport { getOrCreateAls } from \"./internal/als-registry.js\";\nimport {\n getRequestContext,\n isInsideUnifiedScope,\n runWithUnifiedStateMutation,\n} from \"./unified-request-context.js\";\n\n// ---------------------------------------------------------------------------\n// ALS setup\n// ---------------------------------------------------------------------------\n\nexport type SSRContext = {\n pathname: string;\n query: Record<string, string | string[]>;\n asPath: string;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n};\n\nexport type RouterState = {\n ssrContext: SSRContext | null;\n};\n\nconst _FALLBACK_KEY = Symbol.for(\"vinext.router.fallback\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = getOrCreateAls<RouterState>(\"vinext.router.als\");\n\nconst _fallbackState = (_g[_FALLBACK_KEY] ??= {\n ssrContext: null,\n} satisfies RouterState) as RouterState;\n\nfunction _getState(): RouterState {\n if (isInsideUnifiedScope()) {\n return getRequestContext();\n }\n return _als.getStore() ?? _fallbackState;\n}\n\n/**\n * Run a function within a router state ALS scope.\n * Ensures per-request isolation for Pages Router SSR context\n * on concurrent runtimes.\n */\nexport function runWithRouterState<T>(fn: () => Promise<T>): Promise<T>;\nexport function runWithRouterState<T>(fn: () => T | Promise<T>): T | Promise<T>;\nexport function runWithRouterState<T>(fn: () => T | Promise<T>): T | Promise<T> {\n if (isInsideUnifiedScope()) {\n return runWithUnifiedStateMutation((uCtx) => {\n uCtx.ssrContext = null;\n }, fn);\n }\n\n const state: RouterState = {\n ssrContext: null,\n };\n return _als.run(state, fn);\n}\n\n// ---------------------------------------------------------------------------\n// Register ALS-backed accessors into router.ts\n// ---------------------------------------------------------------------------\n\n_registerRouterStateAccessors({\n getSSRContext(): SSRContext | null {\n return _getState().ssrContext;\n },\n\n setSSRContext(ctx: SSRContext | null): void {\n _getState().ssrContext = ctx;\n },\n});\n"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"router-state.js","names":[],"sources":["../../src/shims/router-state.ts"],"sourcesContent":["/**\n * Server-only Pages Router state backed by AsyncLocalStorage.\n *\n * Provides request-scoped isolation for SSR context (pathname, query,\n * locale) so concurrent requests on Workers don't share state.\n *\n * This module is server-only — it imports node:async_hooks and must NOT\n * be bundled for the browser.\n */\n\nimport { _registerRouterStateAccessors } from \"./router.js\";\nimport { getOrCreateAls } from \"./internal/als-registry.js\";\nimport {\n getRequestContext,\n isInsideUnifiedScope,\n runWithUnifiedStateMutation,\n} from \"./unified-request-context.js\";\n\n// ---------------------------------------------------------------------------\n// ALS setup\n// ---------------------------------------------------------------------------\n\nexport type SSRContext = {\n pathname: string;\n query: Record<string, string | string[]>;\n asPath: string;\n locale?: string;\n locales?: string[];\n defaultLocale?: string;\n isFallback?: boolean;\n};\n\nexport type RouterState = {\n ssrContext: SSRContext | null;\n};\n\nconst _FALLBACK_KEY = Symbol.for(\"vinext.router.fallback\");\nconst _g = globalThis as unknown as Record<PropertyKey, unknown>;\nconst _als = getOrCreateAls<RouterState>(\"vinext.router.als\");\n\nconst _fallbackState = (_g[_FALLBACK_KEY] ??= {\n ssrContext: null,\n} satisfies RouterState) as RouterState;\n\nfunction _getState(): RouterState {\n if (isInsideUnifiedScope()) {\n return getRequestContext();\n }\n return _als.getStore() ?? _fallbackState;\n}\n\n/**\n * Run a function within a router state ALS scope.\n * Ensures per-request isolation for Pages Router SSR context\n * on concurrent runtimes.\n */\nexport function runWithRouterState<T>(fn: () => Promise<T>): Promise<T>;\nexport function runWithRouterState<T>(fn: () => T | Promise<T>): T | Promise<T>;\nexport function runWithRouterState<T>(fn: () => T | Promise<T>): T | Promise<T> {\n if (isInsideUnifiedScope()) {\n return runWithUnifiedStateMutation((uCtx) => {\n uCtx.ssrContext = null;\n }, fn);\n }\n\n const state: RouterState = {\n ssrContext: null,\n };\n return _als.run(state, fn);\n}\n\n// ---------------------------------------------------------------------------\n// Register ALS-backed accessors into router.ts\n// ---------------------------------------------------------------------------\n\n_registerRouterStateAccessors({\n getSSRContext(): SSRContext | null {\n return _getState().ssrContext;\n },\n\n setSSRContext(ctx: SSRContext | null): void {\n _getState().ssrContext = ctx;\n },\n});\n"],"mappings":";;;;;;;;;;;;;AAoCA,MAAM,gBAAgB,OAAO,IAAI,yBAAyB;AAC1D,MAAM,KAAK;AACX,MAAM,OAAO,eAA4B,oBAAoB;AAE7D,MAAM,iBAAkB,GAAG,mBAAmB,EAC5C,YAAY,MACb;AAED,SAAS,YAAyB;CAChC,IAAI,sBAAsB,EACxB,OAAO,mBAAmB;CAE5B,OAAO,KAAK,UAAU,IAAI;;AAU5B,SAAgB,mBAAsB,IAA0C;CAC9E,IAAI,sBAAsB,EACxB,OAAO,6BAA6B,SAAS;EAC3C,KAAK,aAAa;IACjB,GAAG;CAMR,OAAO,KAAK,IAAI,EAFd,YAAY,MAEO,EAAE,GAAG;;AAO5B,8BAA8B;CAC5B,gBAAmC;EACjC,OAAO,WAAW,CAAC;;CAGrB,cAAc,KAA8B;EAC1C,WAAW,CAAC,aAAa;;CAE5B,CAAC"}
|
package/dist/shims/router.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ type UrlObject = {
|
|
|
38
38
|
type TransitionOptions = {
|
|
39
39
|
shallow?: boolean;
|
|
40
40
|
scroll?: boolean;
|
|
41
|
-
locale?: string;
|
|
41
|
+
locale?: string | false;
|
|
42
42
|
};
|
|
43
43
|
type RouterEvents = {
|
|
44
44
|
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
@@ -65,6 +65,14 @@ type SSRContext = {
|
|
|
65
65
|
locales?: string[];
|
|
66
66
|
defaultLocale?: string;
|
|
67
67
|
domainLocales?: VinextNextData["domainLocales"];
|
|
68
|
+
/**
|
|
69
|
+
* True when rendering a `getStaticPaths` fallback shell for a path that
|
|
70
|
+
* hasn't been pre-rendered yet (`fallback: true` + unlisted path). Mirrors
|
|
71
|
+
* `renderContext.isFallback` in Next.js's `render.tsx`: `getStaticProps`
|
|
72
|
+
* is skipped, the page renders with empty props, and `useRouter().isFallback`
|
|
73
|
+
* returns `true` so user code can show a loading state.
|
|
74
|
+
*/
|
|
75
|
+
isFallback?: boolean;
|
|
68
76
|
};
|
|
69
77
|
/**
|
|
70
78
|
* Register ALS-backed state accessors. Called by router-state.ts on import.
|
|
@@ -97,8 +105,6 @@ type PagesNavigationContextShape = {
|
|
|
97
105
|
* treat null as "App Router context, use normal app-router state".
|
|
98
106
|
*/
|
|
99
107
|
declare function getPagesNavigationContext(): PagesNavigationContextShape | null;
|
|
100
|
-
/** Inject a `<link rel="prefetch">` for the target page. */
|
|
101
|
-
declare function prefetchUrl(url: string): Promise<void>;
|
|
102
108
|
/**
|
|
103
109
|
* useRouter hook - Pages Router compatible.
|
|
104
110
|
*
|
|
@@ -151,15 +157,16 @@ type ExcludeRouterProps<P> = Pick<P, Exclude<keyof P, keyof WithRouterProps>>;
|
|
|
151
157
|
* define `getInitialProps`.
|
|
152
158
|
*/
|
|
153
159
|
declare function withRouter<P extends WithRouterProps>(ComposedComponent: ComponentType<P>): ComponentType<ExcludeRouterProps<P>>;
|
|
154
|
-
declare const
|
|
160
|
+
declare const RouterMethods: {
|
|
155
161
|
push: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
|
|
156
162
|
replace: (url: string | UrlObject, as?: string, options?: TransitionOptions) => Promise<boolean>;
|
|
157
163
|
back: () => void;
|
|
158
164
|
reload: () => void;
|
|
159
|
-
prefetch:
|
|
165
|
+
prefetch: (url: string) => Promise<void>;
|
|
160
166
|
beforePopState: (cb: BeforePopStateCallback) => void;
|
|
161
167
|
events: RouterEvents;
|
|
162
168
|
};
|
|
169
|
+
declare const Router: typeof RouterMethods & Omit<NextRouter, keyof typeof RouterMethods>;
|
|
163
170
|
//#endregion
|
|
164
171
|
export { ExcludeRouterProps, NextRouter, WithRouterProps, _registerRouterStateAccessors, applyNavigationLocale, Router as default, getPagesNavigationContext, isExternalUrl, isHashOnlyChange, setSSRContext, useRouter, withRouter, wrapWithRouterContext };
|
|
165
172
|
//# sourceMappingURL=router.d.ts.map
|
package/dist/shims/router.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { stripBasePath } from "../utils/base-path.js";
|
|
2
|
+
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
3
|
+
import { addQueryParam, appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
2
4
|
import { matchRoutePattern, routePatternParts } from "../routing/route-pattern.js";
|
|
3
5
|
import { RouterContext } from "./internal/router-context.js";
|
|
6
|
+
import { applyVinextLocaleGlobals, extractVinextNextDataJson, parseVinextNextDataJson } from "../client/vinext-next-data.js";
|
|
4
7
|
import { isValidModulePath } from "../client/validate-module-path.js";
|
|
5
8
|
import { installWindowNext } from "../client/window-next.js";
|
|
6
|
-
import { isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
7
|
-
import { addLocalePrefix, getDomainLocaleUrl } from "../utils/domain-locale.js";
|
|
8
|
-
import { addQueryParam, appendSearchParamsToUrl, urlQueryToSearchParams } from "../utils/query.js";
|
|
9
|
+
import { isAbsoluteOrProtocolRelativeUrl, isHashOnlyBrowserUrlChange, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath } from "./url-utils.js";
|
|
10
|
+
import { addLocalePrefix, getDomainLocaleUrl, getLocalePathPrefix } from "../utils/domain-locale.js";
|
|
9
11
|
import { scrollToHashTarget } from "./hash-scroll.js";
|
|
10
12
|
import { setPagesRouterPopStateHandler } from "./pages-router-runtime.js";
|
|
13
|
+
import { getCurrentBrowserLocale } from "./client-locale.js";
|
|
11
14
|
import { createElement, useContext, useEffect, useMemo, useState } from "react";
|
|
12
15
|
//#region src/shims/router.ts
|
|
13
16
|
/**
|
|
@@ -19,6 +22,8 @@ import { createElement, useContext, useEffect, useMemo, useState } from "react";
|
|
|
19
22
|
*/
|
|
20
23
|
/** basePath from next.config.js, injected by the plugin at build time */
|
|
21
24
|
const __basePath = process.env.__NEXT_ROUTER_BASEPATH ?? "";
|
|
25
|
+
/** trailingSlash from next.config.js, injected by the plugin at build time */
|
|
26
|
+
const __trailingSlash = process.env.__VINEXT_TRAILING_SLASH === "true";
|
|
22
27
|
function createRouterEvents() {
|
|
23
28
|
const listeners = /* @__PURE__ */ new Map();
|
|
24
29
|
return {
|
|
@@ -54,6 +59,18 @@ function resolveUrl(url) {
|
|
|
54
59
|
function resolveNavigationTarget(url, as, locale) {
|
|
55
60
|
return applyNavigationLocale(as ?? resolveUrl(url), locale);
|
|
56
61
|
}
|
|
62
|
+
function getCurrentUrlLocale() {
|
|
63
|
+
return getCurrentBrowserLocale({
|
|
64
|
+
basePath: __basePath,
|
|
65
|
+
domainLocales: getDomainLocales(),
|
|
66
|
+
hostname: getCurrentHostname()
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function resolveTransitionLocale(locale) {
|
|
70
|
+
if (typeof window === "undefined") return void 0;
|
|
71
|
+
if (locale === false) return window.__VINEXT_DEFAULT_LOCALE__;
|
|
72
|
+
return locale ?? getCurrentUrlLocale();
|
|
73
|
+
}
|
|
57
74
|
function getDomainLocales() {
|
|
58
75
|
return window.__NEXT_DATA__?.domainLocales;
|
|
59
76
|
}
|
|
@@ -74,10 +91,27 @@ function getDomainLocalePath(url, locale) {
|
|
|
74
91
|
function applyNavigationLocale(url, locale) {
|
|
75
92
|
if (!locale || typeof window === "undefined") return url;
|
|
76
93
|
if (isAbsoluteOrProtocolRelativeUrl(url)) return url;
|
|
94
|
+
if (getLocalePathPrefix(url, window.__VINEXT_LOCALES__)) return url;
|
|
77
95
|
const domainLocalePath = getDomainLocalePath(url, locale);
|
|
78
96
|
if (domainLocalePath) return domainLocalePath;
|
|
79
97
|
return addLocalePrefix(url, locale, window.__VINEXT_DEFAULT_LOCALE__ ?? "");
|
|
80
98
|
}
|
|
99
|
+
function isDefaultLocaleRootNavigation(url, locale) {
|
|
100
|
+
if (typeof window === "undefined") return false;
|
|
101
|
+
if (!locale || locale !== window.__VINEXT_DEFAULT_LOCALE__) return false;
|
|
102
|
+
let parsed;
|
|
103
|
+
try {
|
|
104
|
+
parsed = new URL(url, window.location.href);
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return stripBasePath(parsed.pathname, __basePath) === "/";
|
|
109
|
+
}
|
|
110
|
+
function getPagesHtmlFetchUrl(browserUrl, locale) {
|
|
111
|
+
if (!isDefaultLocaleRootNavigation(browserUrl, locale)) return browserUrl;
|
|
112
|
+
const parsed = new URL(browserUrl, window.location.href);
|
|
113
|
+
return normalizePathTrailingSlash(toBrowserNavigationHref(`${normalizePathTrailingSlash(`/${locale}`, __trailingSlash)}${parsed.search}${parsed.hash}`, window.location.href, __basePath), __trailingSlash);
|
|
114
|
+
}
|
|
81
115
|
/** Check if a URL is external (any URL scheme per RFC 3986, or protocol-relative) */
|
|
82
116
|
function isExternalUrl(url) {
|
|
83
117
|
return isAbsoluteOrProtocolRelativeUrl(url);
|
|
@@ -303,7 +337,7 @@ function scheduleHardNavigationAndThrow(url, message) {
|
|
|
303
337
|
* Throws on hard-navigation failures (non-OK response, missing data) so the
|
|
304
338
|
* caller can distinguish success from failure for event emission.
|
|
305
339
|
*/
|
|
306
|
-
async function navigateClient(url) {
|
|
340
|
+
async function navigateClient(url, fetchUrl = url) {
|
|
307
341
|
if (typeof window === "undefined") return;
|
|
308
342
|
const root = window.__VINEXT_ROOT__;
|
|
309
343
|
if (!root) {
|
|
@@ -321,7 +355,7 @@ async function navigateClient(url) {
|
|
|
321
355
|
try {
|
|
322
356
|
let res;
|
|
323
357
|
try {
|
|
324
|
-
res = await fetch(
|
|
358
|
+
res = await fetch(fetchUrl, {
|
|
325
359
|
headers: { Accept: "text/html" },
|
|
326
360
|
signal: controller.signal
|
|
327
361
|
});
|
|
@@ -333,9 +367,9 @@ async function navigateClient(url) {
|
|
|
333
367
|
if (!res.ok) scheduleHardNavigationAndThrow(url, `Navigation failed: ${res.status} ${res.statusText}`);
|
|
334
368
|
const html = await res.text();
|
|
335
369
|
assertStillCurrent();
|
|
336
|
-
const
|
|
337
|
-
if (!
|
|
338
|
-
const nextData =
|
|
370
|
+
const nextDataJson = extractVinextNextDataJson(html);
|
|
371
|
+
if (!nextDataJson) scheduleHardNavigationAndThrow(url, "Navigation failed: missing __NEXT_DATA__ in response");
|
|
372
|
+
const nextData = parseVinextNextDataJson(nextDataJson);
|
|
339
373
|
const { pageProps } = nextData.props;
|
|
340
374
|
let pageModuleUrl = nextData.__vinext?.pageModuleUrl;
|
|
341
375
|
if (!pageModuleUrl) {
|
|
@@ -376,6 +410,7 @@ async function navigateClient(url) {
|
|
|
376
410
|
else element = React.createElement(PageComponent, pageProps);
|
|
377
411
|
element = wrapWithRouterContext(element);
|
|
378
412
|
window.__NEXT_DATA__ = nextData;
|
|
413
|
+
applyVinextLocaleGlobals(window, nextData);
|
|
379
414
|
root.render(element);
|
|
380
415
|
} finally {
|
|
381
416
|
if (navId === _navigationId) _activeAbortController = null;
|
|
@@ -393,9 +428,9 @@ async function navigateClient(url) {
|
|
|
393
428
|
* - "failed" — genuine error, caller should return false (hard nav is already
|
|
394
429
|
* scheduled as recovery)
|
|
395
430
|
*/
|
|
396
|
-
async function runNavigateClient(fullUrl, resolvedUrl) {
|
|
431
|
+
async function runNavigateClient(fullUrl, resolvedUrl, fetchUrl = fullUrl) {
|
|
397
432
|
try {
|
|
398
|
-
await navigateClient(fullUrl);
|
|
433
|
+
await navigateClient(fullUrl, fetchUrl);
|
|
399
434
|
return "completed";
|
|
400
435
|
} catch (err) {
|
|
401
436
|
routerEvents.emit("routeChangeError", err, resolvedUrl, { shallow: false });
|
|
@@ -428,7 +463,7 @@ function buildRouterValue(pathname, query, asPath, methods) {
|
|
|
428
463
|
domainLocales,
|
|
429
464
|
isReady: true,
|
|
430
465
|
isPreview: false,
|
|
431
|
-
isFallback: typeof window !== "undefined"
|
|
466
|
+
isFallback: typeof window !== "undefined" ? nextData?.isFallback === true : _ssrState?.isFallback === true,
|
|
432
467
|
...methods,
|
|
433
468
|
events: routerEvents
|
|
434
469
|
};
|
|
@@ -452,6 +487,22 @@ function updateHistory(mode, url) {
|
|
|
452
487
|
_lastPathnameAndSearch = window.location.pathname + window.location.search;
|
|
453
488
|
}
|
|
454
489
|
/**
|
|
490
|
+
* Throw the canonical "no router instance" error used when a Pages Router
|
|
491
|
+
* navigation method (push/replace/back/reload/prefetch/beforePopState) is
|
|
492
|
+
* invoked during SSR or prerendering.
|
|
493
|
+
*
|
|
494
|
+
* Mirrors Next.js's `ServerRouter.push`/`replace`/etc. which all call
|
|
495
|
+
* `noRouter()` in `packages/next/src/server/render.tsx`. The error message
|
|
496
|
+
* matches Next.js verbatim so userland error handling and docs links work
|
|
497
|
+
* unchanged.
|
|
498
|
+
*
|
|
499
|
+
* Ported from Next.js: packages/next/src/server/render.tsx
|
|
500
|
+
* https://github.com/vercel/next.js/blob/canary/packages/next/src/server/render.tsx
|
|
501
|
+
*/
|
|
502
|
+
function throwNoRouterInstance() {
|
|
503
|
+
throw new Error("No router instance found. you should only use \"next/router\" inside the client side of your app. https://nextjs.org/docs/messages/no-router-instance");
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
455
506
|
* Shared client-side navigation flow used by both `useRouter()` and the
|
|
456
507
|
* `Router` singleton. The only differences between push/replace are the
|
|
457
508
|
* history method (`pushState` vs `replaceState`), the external-URL fallback
|
|
@@ -463,7 +514,11 @@ function updateHistory(mode, url) {
|
|
|
463
514
|
* passes no callback.
|
|
464
515
|
*/
|
|
465
516
|
async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
466
|
-
|
|
517
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
518
|
+
assertSafeNavigationUrl(resolveUrl(url));
|
|
519
|
+
if (as !== void 0) assertSafeNavigationUrl(String(as));
|
|
520
|
+
const navigationLocale = resolveTransitionLocale(options?.locale);
|
|
521
|
+
let resolved = resolveNavigationTarget(url, as, navigationLocale);
|
|
467
522
|
if (isExternalUrl(resolved)) {
|
|
468
523
|
const localPath = toSameOriginAppPath(resolved, __basePath);
|
|
469
524
|
if (localPath == null) {
|
|
@@ -473,7 +528,9 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
473
528
|
}
|
|
474
529
|
resolved = localPath;
|
|
475
530
|
}
|
|
476
|
-
|
|
531
|
+
resolved = normalizePathTrailingSlash(resolved, __trailingSlash);
|
|
532
|
+
const full = normalizePathTrailingSlash(toBrowserNavigationHref(resolved, window.location.href, __basePath), __trailingSlash);
|
|
533
|
+
const htmlFetchUrl = getPagesHtmlFetchUrl(full, navigationLocale);
|
|
477
534
|
const shallow = options?.shallow ?? false;
|
|
478
535
|
const doScroll = options?.scroll !== false;
|
|
479
536
|
if (isHashOnlyChange(full)) {
|
|
@@ -491,7 +548,7 @@ async function performNavigation(url, as, options, mode, onStateUpdate) {
|
|
|
491
548
|
routerEvents.emit("beforeHistoryChange", resolved, { shallow });
|
|
492
549
|
updateHistory(mode, full);
|
|
493
550
|
if (!shallow) {
|
|
494
|
-
const result = await runNavigateClient(full, resolved);
|
|
551
|
+
const result = await runNavigateClient(full, resolved, htmlFetchUrl);
|
|
495
552
|
if (result === "cancelled") return true;
|
|
496
553
|
if (result === "failed") return false;
|
|
497
554
|
}
|
|
@@ -573,7 +630,7 @@ function handlePagesRouterPopState(e) {
|
|
|
573
630
|
routerEvents.emit("routeChangeStart", fullAppUrl, { shallow: false });
|
|
574
631
|
routerEvents.emit("beforeHistoryChange", fullAppUrl, { shallow: false });
|
|
575
632
|
(async () => {
|
|
576
|
-
if (await runNavigateClient(browserUrl, fullAppUrl) === "completed") {
|
|
633
|
+
if (await runNavigateClient(browserUrl, fullAppUrl, getPagesHtmlFetchUrl(browserUrl, window.__VINEXT_LOCALE__)) === "completed") {
|
|
577
634
|
routerEvents.emit("routeChangeComplete", fullAppUrl, { shallow: false });
|
|
578
635
|
restoreScrollPosition(e.state);
|
|
579
636
|
dispatchNavigateEvent();
|
|
@@ -624,17 +681,110 @@ function withRouter(ComposedComponent) {
|
|
|
624
681
|
if (process.env.NODE_ENV !== "production") WithRouterWrapper.displayName = `withRouter(${composed.displayName || composed.name || "Unknown"})`;
|
|
625
682
|
return WithRouterWrapper;
|
|
626
683
|
}
|
|
627
|
-
const Router = {
|
|
628
|
-
push: (url, as, options) =>
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
684
|
+
const Router = Object.defineProperties({
|
|
685
|
+
push: (url, as, options) => {
|
|
686
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
687
|
+
return performNavigation(url, as, options, "push");
|
|
688
|
+
},
|
|
689
|
+
replace: (url, as, options) => {
|
|
690
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
691
|
+
return performNavigation(url, as, options, "replace");
|
|
692
|
+
},
|
|
693
|
+
back: () => {
|
|
694
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
695
|
+
window.history.back();
|
|
696
|
+
},
|
|
697
|
+
reload: () => {
|
|
698
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
699
|
+
window.location.reload();
|
|
700
|
+
},
|
|
701
|
+
prefetch: (url) => {
|
|
702
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
703
|
+
return prefetchUrl(url);
|
|
704
|
+
},
|
|
633
705
|
beforePopState: (cb) => {
|
|
706
|
+
if (typeof window === "undefined") throwNoRouterInstance();
|
|
634
707
|
_beforePopStateCb = cb;
|
|
635
708
|
},
|
|
636
709
|
events: routerEvents
|
|
637
|
-
}
|
|
710
|
+
}, {
|
|
711
|
+
pathname: {
|
|
712
|
+
enumerable: true,
|
|
713
|
+
get() {
|
|
714
|
+
return getPathnameAndQuery().pathname;
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
route: {
|
|
718
|
+
enumerable: true,
|
|
719
|
+
get() {
|
|
720
|
+
const { pathname } = getPathnameAndQuery();
|
|
721
|
+
if (typeof window === "undefined") return pathname;
|
|
722
|
+
return window.__NEXT_DATA__?.page ?? pathname;
|
|
723
|
+
}
|
|
724
|
+
},
|
|
725
|
+
query: {
|
|
726
|
+
enumerable: true,
|
|
727
|
+
get() {
|
|
728
|
+
return getPathnameAndQuery().query;
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
asPath: {
|
|
732
|
+
enumerable: true,
|
|
733
|
+
get() {
|
|
734
|
+
return getPathnameAndQuery().asPath;
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
basePath: {
|
|
738
|
+
enumerable: true,
|
|
739
|
+
value: __basePath,
|
|
740
|
+
writable: false
|
|
741
|
+
},
|
|
742
|
+
locale: {
|
|
743
|
+
enumerable: true,
|
|
744
|
+
get() {
|
|
745
|
+
if (typeof window === "undefined") return _getSSRContext()?.locale;
|
|
746
|
+
return window.__VINEXT_LOCALE__;
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
locales: {
|
|
750
|
+
enumerable: true,
|
|
751
|
+
get() {
|
|
752
|
+
if (typeof window === "undefined") return _getSSRContext()?.locales;
|
|
753
|
+
return window.__VINEXT_LOCALES__;
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
defaultLocale: {
|
|
757
|
+
enumerable: true,
|
|
758
|
+
get() {
|
|
759
|
+
if (typeof window === "undefined") return _getSSRContext()?.defaultLocale;
|
|
760
|
+
return window.__VINEXT_DEFAULT_LOCALE__;
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
domainLocales: {
|
|
764
|
+
enumerable: true,
|
|
765
|
+
get() {
|
|
766
|
+
if (typeof window === "undefined") return _getSSRContext()?.domainLocales;
|
|
767
|
+
return window.__NEXT_DATA__?.domainLocales;
|
|
768
|
+
}
|
|
769
|
+
},
|
|
770
|
+
isReady: {
|
|
771
|
+
enumerable: true,
|
|
772
|
+
value: true,
|
|
773
|
+
writable: false
|
|
774
|
+
},
|
|
775
|
+
isPreview: {
|
|
776
|
+
enumerable: true,
|
|
777
|
+
value: false,
|
|
778
|
+
writable: false
|
|
779
|
+
},
|
|
780
|
+
isFallback: {
|
|
781
|
+
enumerable: true,
|
|
782
|
+
get() {
|
|
783
|
+
if (typeof window === "undefined") return _getSSRContext()?.isFallback === true;
|
|
784
|
+
return window.__NEXT_DATA__?.isFallback === true;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
});
|
|
638
788
|
if (typeof window !== "undefined") installWindowNext({ router: Router });
|
|
639
789
|
const _PAGES_NAVIGATION_ACCESSOR_KEY = Symbol.for("vinext.navigation.pagesNavigationContextAccessor");
|
|
640
790
|
globalThis[_PAGES_NAVIGATION_ACCESSOR_KEY] = getPagesNavigationContext;
|