vinext 1.0.1 → 1.2.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/README.md +93 -10
- package/dist/build/app-page-static-eligibility.d.ts +15 -0
- package/dist/build/app-page-static-eligibility.js +82 -0
- package/dist/build/client-build-config.d.ts +10 -0
- package/dist/build/client-build-config.js +18 -2
- package/dist/build/pages-client-assets-module.d.ts +8 -0
- package/dist/build/pages-client-assets-module.js +21 -1
- package/dist/build/prerender-paths.js +8 -81
- package/dist/build/prerender.js +33 -8
- package/dist/build/run-prerender.js +1 -1
- package/dist/build/server-manifest.d.ts +7 -0
- package/dist/build/server-manifest.js +11 -1
- package/dist/build/ssr-manifest.d.ts +2 -0
- package/dist/build/ssr-manifest.js +6 -2
- package/dist/cache/cache-adapters-virtual.d.ts +7 -1
- package/dist/cache/cache-adapters-virtual.js +3 -3
- package/dist/check.js +7 -6
- package/dist/cli.js +2 -1
- package/dist/client/client-redirect-matcher.d.ts +14 -0
- package/dist/client/client-redirect-matcher.js +37 -0
- package/dist/client/client-redirects.d.ts +27 -0
- package/dist/client/client-redirects.js +28 -0
- package/dist/client/client-rewrites.d.ts +2 -1
- package/dist/client/client-rewrites.js +1 -1
- package/dist/client/navigation-runtime.d.ts +11 -0
- package/dist/client/navigation-runtime.js +1 -1
- package/dist/config/config-matchers.d.ts +26 -11
- package/dist/config/config-matchers.js +81 -82
- package/dist/config/destination-params.d.ts +47 -0
- package/dist/config/destination-params.js +116 -0
- package/dist/config/next-config.d.ts +14 -0
- package/dist/config/next-config.js +21 -3
- package/dist/entries/app-rsc-entry.d.ts +6 -0
- package/dist/entries/app-rsc-entry.js +84 -49
- package/dist/entries/pages-client-entry.js +3 -1
- package/dist/entries/pages-server-entry.js +13 -37
- package/dist/index.d.ts +7 -2
- package/dist/index.js +193 -73
- package/dist/init-cloudflare.d.ts +9 -0
- package/dist/init-cloudflare.js +107 -31
- package/dist/init-platform.d.ts +4 -0
- package/dist/init-platform.js +27 -2
- package/dist/init.d.ts +1 -0
- package/dist/init.js +67 -3
- package/dist/plugins/ast-scope.d.ts +7 -0
- package/dist/plugins/ast-scope.js +59 -3
- package/dist/plugins/cache-flight-codec.d.ts +19 -0
- package/dist/plugins/cache-flight-codec.js +68 -0
- package/dist/plugins/commonjs-esm-facade.d.ts +35 -0
- package/dist/plugins/commonjs-esm-facade.js +80 -0
- package/dist/plugins/dynamic-preload-metadata.d.ts +1 -1
- package/dist/plugins/dynamic-preload-metadata.js +9 -8
- package/dist/plugins/fonts.d.ts +8 -11
- package/dist/plugins/fonts.js +71 -34
- package/dist/plugins/ignore-dynamic-requests.d.ts +1 -1
- package/dist/plugins/ignore-dynamic-requests.js +3 -4
- package/dist/plugins/middleware-server-only.d.ts +5 -4
- package/dist/plugins/middleware-server-only.js +8 -5
- package/dist/plugins/pages-node-externals.js +1 -1
- package/dist/plugins/rsc-scan-glob-imports.d.ts +19 -0
- package/dist/plugins/rsc-scan-glob-imports.js +50 -0
- package/dist/plugins/strip-server-exports.js +262 -98
- package/dist/plugins/transform-result.d.ts +9 -5
- package/dist/plugins/transitive-externals.js +1 -1
- package/dist/plugins/typeof-window.d.ts +2 -2
- package/dist/plugins/use-cache-callable.js +8 -2
- package/dist/plugins/worker-server-only-imports.d.ts +20 -0
- package/dist/plugins/worker-server-only-imports.js +31 -0
- package/dist/plugins/worker-use-server.d.ts +25 -0
- package/dist/plugins/worker-use-server.js +129 -0
- package/dist/routing/file-matcher.d.ts +1 -0
- package/dist/routing/file-matcher.js +1 -1
- package/dist/server/api-handler.d.ts +1 -0
- package/dist/server/api-handler.js +19 -8
- package/dist/server/app-browser-action-result.d.ts +1 -1
- package/dist/server/app-browser-action-result.js +9 -2
- package/dist/server/app-browser-entry.js +11 -7
- package/dist/server/app-browser-history-controller.d.ts +2 -0
- package/dist/server/app-browser-history-controller.js +8 -0
- package/dist/server/app-browser-interception-context.js +26 -2
- package/dist/server/app-browser-navigation-controller.d.ts +7 -1
- package/dist/server/app-browser-navigation-controller.js +94 -11
- package/dist/server/app-browser-server-action-client.js +1 -1
- package/dist/server/app-fallback-renderer.d.ts +2 -0
- package/dist/server/app-fallback-renderer.js +1 -0
- package/dist/server/app-history-state.d.ts +3 -0
- package/dist/server/app-history-state.js +7 -0
- package/dist/server/app-middleware.d.ts +11 -0
- package/dist/server/app-middleware.js +19 -3
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-boundary-render.d.ts +5 -0
- package/dist/server/app-page-boundary-render.js +6 -4
- package/dist/server/app-page-cache-finalizer.d.ts +11 -0
- package/dist/server/app-page-cache-finalizer.js +41 -7
- package/dist/server/app-page-cache-render.d.ts +18 -0
- package/dist/server/app-page-cache-render.js +63 -43
- package/dist/server/app-page-cache.d.ts +6 -1
- package/dist/server/app-page-cache.js +28 -8
- package/dist/server/app-page-dispatch.d.ts +12 -2
- package/dist/server/app-page-dispatch.js +51 -33
- package/dist/server/app-page-element-builder.d.ts +7 -0
- package/dist/server/app-page-element-builder.js +27 -42
- package/dist/server/app-page-execution.d.ts +15 -12
- package/dist/server/app-page-execution.js +30 -40
- package/dist/server/app-page-head.d.ts +5 -0
- package/dist/server/app-page-head.js +9 -3
- package/dist/server/app-page-ppr-runtime.js +1 -1
- package/dist/server/app-page-probe.d.ts +0 -109
- package/dist/server/app-page-probe.js +3 -136
- package/dist/server/app-page-render-identity.d.ts +0 -1
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render-observation.js +3 -3
- package/dist/server/app-page-render.d.ts +13 -5
- package/dist/server/app-page-render.js +219 -119
- package/dist/server/app-page-request.d.ts +0 -1
- package/dist/server/app-page-request.js +54 -17
- package/dist/server/app-page-response.d.ts +4 -3
- package/dist/server/app-page-response.js +4 -3
- package/dist/server/app-page-route-wiring.d.ts +17 -5
- package/dist/server/app-page-route-wiring.js +57 -35
- package/dist/server/app-page-rsc-render-status.d.ts +48 -0
- package/dist/server/app-page-rsc-render-status.js +54 -0
- package/dist/server/app-page-stream.d.ts +15 -8
- package/dist/server/app-page-stream.js +6 -0
- package/dist/server/app-pages-bridge.d.ts +1 -1
- package/dist/server/app-pages-bridge.js +2 -3
- package/dist/server/app-prerender-endpoints.js +9 -6
- package/dist/server/app-request-stage-dispatch.js +7 -3
- package/dist/server/app-request-stage-independent-entry.js +29 -9
- package/dist/server/app-response-header-provenance.d.ts +2 -0
- package/dist/server/app-response-header-provenance.js +10 -4
- package/dist/server/app-response-stage-entry.js +10 -2
- package/dist/server/app-route-handler-cache.d.ts +1 -0
- package/dist/server/app-route-handler-cache.js +1 -0
- package/dist/server/app-route-handler-dispatch.d.ts +1 -0
- package/dist/server/app-route-handler-dispatch.js +6 -3
- package/dist/server/app-route-handler-execution.d.ts +1 -0
- package/dist/server/app-route-handler-execution.js +1 -0
- package/dist/server/app-route-handler-runtime.d.ts +4 -1
- package/dist/server/app-route-handler-runtime.js +45 -24
- package/dist/server/app-router-entry.js +27 -8
- package/dist/server/app-rsc-cache-busting.js +1 -1
- package/dist/server/app-rsc-errors.js +20 -16
- package/dist/server/app-rsc-handler.d.ts +11 -0
- package/dist/server/app-rsc-handler.js +291 -125
- package/dist/server/app-rsc-request-normalization.d.ts +3 -1
- package/dist/server/app-rsc-request-normalization.js +4 -2
- package/dist/server/app-rsc-response-stage.d.ts +1 -1
- package/dist/server/app-rsc-response-stage.js +10 -6
- package/dist/server/app-rsc-route-matching.d.ts +9 -1
- package/dist/server/app-rsc-route-matching.js +36 -19
- package/dist/server/app-segment-config.d.ts +2 -1
- package/dist/server/app-server-action-execution.d.ts +2 -1
- package/dist/server/app-server-action-execution.js +62 -23
- package/dist/server/app-ssr-entry.d.ts +3 -2
- package/dist/server/app-ssr-entry.js +8 -5
- package/dist/server/app-ssr-stream.d.ts +6 -1
- package/dist/server/app-ssr-stream.js +34 -15
- package/dist/server/app-worker-stages.d.ts +7 -2
- package/dist/server/app-worker-stages.js +4 -4
- package/dist/server/cacheability-request.js +11 -7
- package/dist/server/client-build-files.d.ts +16 -0
- package/dist/server/client-build-files.js +36 -0
- package/dist/server/client-reuse-manifest.js +1 -1
- package/dist/server/config-headers.js +2 -0
- package/dist/server/dev-server.js +50 -29
- package/dist/server/dev-stack-sourcemap.js +18 -23
- package/dist/server/document-initial-head.d.ts +0 -11
- package/dist/server/document-initial-head.js +1 -1
- package/dist/server/forwarded-middleware-context.d.ts +5 -0
- package/dist/server/forwarded-middleware-context.js +22 -0
- package/dist/server/headers.d.ts +18 -1
- package/dist/server/headers.js +19 -2
- package/dist/server/http-conditional.d.ts +11 -0
- package/dist/server/http-conditional.js +10 -1
- package/dist/server/http-error-responses.d.ts +1 -1
- package/dist/server/image-optimization.d.ts +54 -0
- package/dist/server/image-optimization.js +118 -9
- package/dist/server/isr-cache.d.ts +10 -0
- package/dist/server/isr-cache.js +43 -8
- package/dist/server/metadata-route-response.js +9 -8
- package/dist/server/middleware-matcher-pattern.js +8 -4
- package/dist/server/middleware-matcher.d.ts +2 -0
- package/dist/server/middleware-matcher.js +23 -2
- package/dist/server/middleware-response-headers.js +2 -0
- package/dist/server/middleware-runtime.d.ts +13 -0
- package/dist/server/middleware-runtime.js +33 -20
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +3 -1
- package/dist/server/multi-stage.d.ts +19 -0
- package/dist/server/navigation-planner.js +1 -1
- package/dist/server/node-response-signal.d.ts +16 -0
- package/dist/server/node-response-signal.js +26 -0
- package/dist/server/normalize-path.d.ts +0 -13
- package/dist/server/normalize-path.js +1 -34
- package/dist/server/open-redirect.d.ts +47 -0
- package/dist/server/open-redirect.js +74 -1
- package/dist/server/pages-api-route.d.ts +3 -2
- package/dist/server/pages-api-route.js +4 -3
- package/dist/server/pages-cache-tag.d.ts +12 -0
- package/dist/server/pages-cache-tag.js +19 -0
- package/dist/server/pages-client-assets.d.ts +2 -0
- package/dist/server/pages-data-route.d.ts +10 -0
- package/dist/server/pages-data-route.js +19 -2
- package/dist/server/pages-document-asset-props.d.ts +5 -1
- package/dist/server/pages-document-asset-props.js +13 -5
- package/dist/server/pages-document-splice.d.ts +19 -0
- package/dist/server/pages-document-splice.js +55 -0
- package/dist/server/pages-i18n.d.ts +12 -1
- package/dist/server/pages-i18n.js +18 -4
- package/dist/server/pages-node-compat.d.ts +16 -5
- package/dist/server/pages-node-compat.js +20 -12
- package/dist/server/pages-page-data.d.ts +32 -24
- package/dist/server/pages-page-data.js +50 -120
- package/dist/server/pages-page-handler.d.ts +0 -6
- package/dist/server/pages-page-handler.js +209 -130
- package/dist/server/pages-page-response.d.ts +12 -6
- package/dist/server/pages-page-response.js +41 -34
- package/dist/server/pages-request-pipeline.d.ts +10 -2
- package/dist/server/pages-request-pipeline.js +37 -18
- package/dist/server/pages-request-stage-entry.d.ts +6 -0
- package/dist/server/pages-request-stage-entry.js +79 -16
- package/dist/server/pages-response-stage-entry.js +4 -0
- package/dist/server/pages-revalidate.js +1 -1
- package/dist/server/pages-router-entry.js +4 -3
- package/dist/server/prerender-manifest.d.ts +3 -3
- package/dist/server/prerender-manifest.js +4 -3
- package/dist/server/prerender-work-unit-setup.js +4 -0
- package/dist/server/prod-server.d.ts +20 -7
- package/dist/server/prod-server.js +343 -129
- package/dist/server/proper-error.d.ts +4 -0
- package/dist/server/proper-error.js +31 -0
- package/dist/server/request-pipeline.d.ts +24 -9
- package/dist/server/request-pipeline.js +24 -9
- package/dist/server/response-compression.d.ts +43 -0
- package/dist/server/response-compression.js +111 -0
- package/dist/server/revalidation-request.d.ts +1 -0
- package/dist/server/revalidation-request.js +1 -1
- package/dist/server/rsc-stream-hints.js +31 -2
- package/dist/server/seed-cache.d.ts +1 -0
- package/dist/server/seed-cache.js +15 -11
- package/dist/server/server-reference-loader.d.ts +4 -0
- package/dist/server/server-reference-loader.js +29 -0
- package/dist/server/socket-error-backstop.d.ts +23 -1
- package/dist/server/socket-error-backstop.js +69 -17
- package/dist/server/static-file-signal.d.ts +15 -4
- package/dist/server/static-file-signal.js +46 -12
- package/dist/server/worker-image-optimization.d.ts +34 -0
- package/dist/server/worker-image-optimization.js +86 -0
- package/dist/server/worker-stages.d.ts +1 -1
- package/dist/server/worker-stages.js +2 -2
- package/dist/server/worker-utils.d.ts +8 -3
- package/dist/server/worker-utils.js +12 -7
- package/dist/shims/app-router-scroll.js +4 -1
- package/dist/shims/app-router-tree-context.d.ts +5 -0
- package/dist/shims/app-router-tree-context.js +27 -0
- package/dist/shims/cache-adapter-instantiate.d.ts +50 -0
- package/dist/shims/cache-adapter-instantiate.js +118 -0
- package/dist/shims/cache-callable-runtime.d.ts +6 -42
- package/dist/shims/cache-callable-runtime.js +65 -174
- package/dist/shims/cache-flight-arguments.d.ts +22 -0
- package/dist/shims/cache-flight-arguments.js +56 -0
- package/dist/shims/cache-handler.js +1 -9
- package/dist/shims/cache-request-state.d.ts +15 -0
- package/dist/shims/cache-request-state.js +31 -8
- package/dist/shims/cache-runtime.d.ts +12 -20
- package/dist/shims/cache-runtime.js +166 -225
- package/dist/shims/cache.d.ts +4 -4
- package/dist/shims/cache.js +44 -16
- package/dist/shims/cacheability-classification.d.ts +7 -0
- package/dist/shims/cdn-cache.d.ts +8 -0
- package/dist/shims/cdn-cache.js +17 -1
- package/dist/shims/disable-smooth-scroll.d.ts +3 -0
- package/dist/shims/disable-smooth-scroll.js +36 -0
- package/dist/shims/document-placeholders.d.ts +19 -0
- package/dist/shims/document-placeholders.js +45 -0
- package/dist/shims/document.js +21 -5
- package/dist/shims/dynamic-preload-chunks.d.ts +1 -0
- package/dist/shims/dynamic-preload-chunks.js +13 -9
- package/dist/shims/dynamic.d.ts +1 -1
- package/dist/shims/dynamic.js +60 -8
- package/dist/shims/error-boundary-navigation.d.ts +7 -0
- package/dist/shims/error-boundary-navigation.js +19 -1
- package/dist/shims/error-boundary.d.ts +10 -10
- package/dist/shims/error-boundary.js +26 -7
- package/dist/shims/fetch-cache-state.d.ts +66 -0
- package/dist/shims/fetch-cache-state.js +92 -0
- package/dist/shims/fetch-cache.d.ts +3 -61
- package/dist/shims/fetch-cache.js +161 -108
- package/dist/shims/form.js +1 -1
- package/dist/shims/head.d.ts +10 -6
- package/dist/shims/head.js +15 -13
- package/dist/shims/headers.d.ts +13 -0
- package/dist/shims/headers.js +47 -4
- package/dist/shims/image.js +2 -1
- package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -2
- package/dist/shims/internal/app-page-props-cache-key.js +24 -15
- package/dist/shims/internal/headers-state.d.ts +0 -1
- package/dist/shims/internal/work-store-scope.d.ts +5 -0
- package/dist/shims/internal/work-store-scope.js +24 -0
- package/dist/shims/metadata.js +3 -3
- package/dist/shims/navigation-errors.d.ts +6 -0
- package/dist/shims/navigation-errors.js +11 -1
- package/dist/shims/navigation.d.ts +7 -0
- package/dist/shims/navigation.js +45 -9
- package/dist/shims/request-context.d.ts +11 -0
- package/dist/shims/request-state-types.d.ts +2 -1
- package/dist/shims/router.js +12 -20
- package/dist/shims/server.d.ts +16 -0
- package/dist/shims/server.js +24 -4
- package/dist/shims/thenable-params.d.ts +4 -0
- package/dist/shims/thenable-params.js +25 -3
- package/dist/shims/unified-request-context.d.ts +1 -1
- package/dist/shims/unified-request-context.js +1 -0
- package/dist/shims/url-utils.d.ts +2 -0
- package/dist/shims/url-utils.js +3 -1
- package/dist/utils/client-runtime-metadata.js +1 -1
- package/dist/utils/hash.d.ts +7 -0
- package/dist/utils/hash.js +11 -1
- package/dist/utils/mdx-scan.d.ts +5 -0
- package/dist/utils/mdx-scan.js +8 -1
- package/dist/utils/package-name.d.ts +6 -0
- package/dist/utils/package-name.js +12 -1
- package/dist/utils/plugin-rsc-version.d.ts +4 -0
- package/dist/utils/plugin-rsc-version.js +15 -0
- package/dist/utils/prerender-output-paths.js +15 -4
- package/dist/utils/public-file-path.d.ts +10 -2
- package/dist/utils/public-file-path.js +13 -9
- package/dist/utils/public-routes.js +2 -2
- package/dist/utils/react-version.d.ts +3 -0
- package/dist/utils/react-version.js +1 -1
- package/dist/utils/regex-safety.d.ts +10 -0
- package/dist/utils/regex-safety.js +70 -18
- package/package.json +9 -5
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
//#region src/plugins/worker-use-server.d.ts
|
|
3
|
+
type RscPluginModule = typeof import("@vitejs/plugin-rsc");
|
|
4
|
+
/**
|
|
5
|
+
* Replace `"use server"` modules in browser Web Worker bundles with Server
|
|
6
|
+
* Function reference proxies.
|
|
7
|
+
*
|
|
8
|
+
* Vite bundles every worker in a fresh plugin container built from
|
|
9
|
+
* `worker.plugins`, so @vitejs/plugin-rsc's `rsc:use-server` transform never
|
|
10
|
+
* sees worker modules in production builds and the module bodies would be
|
|
11
|
+
* emitted verbatim. Next.js compiles workers as part of the browser graph,
|
|
12
|
+
* where `"use server"` exports become `createServerReference(...)` proxies.
|
|
13
|
+
* This mirrors the client-environment branch of `rsc:use-server` with the
|
|
14
|
+
* same reference keys, without claiming references.
|
|
15
|
+
*
|
|
16
|
+
* The worker realm has no router to dispatch Server Function calls. Next.js's
|
|
17
|
+
* `callServer` dispatches inside `startTransition`, so the dispatch error is
|
|
18
|
+
* reported globally and the call's promise never settles; the worker
|
|
19
|
+
* references reproduce that instead of reaching the server.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createWorkerUseServerPlugins(options: {
|
|
22
|
+
rscPluginModule: Promise<RscPluginModule>;
|
|
23
|
+
rscPluginPath: string;
|
|
24
|
+
}): Promise<Plugin[]>;
|
|
25
|
+
//#endregion
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import path, { toSlash } from "../deps/.pnpm/pathslash@0.1.0/deps/pathslash/dist/index.js";
|
|
2
|
+
import { escapeRegExp } from "../utils/regex.js";
|
|
3
|
+
import { magicStringTransformResult } from "./transform-result.js";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { parseAstAsync, transformWithOxc } from "vite";
|
|
8
|
+
//#region src/plugins/worker-use-server.ts
|
|
9
|
+
const WORKER_REFERENCE_RUNTIME_ID = "\0vinext:worker-server-reference";
|
|
10
|
+
const WORKER_REFERENCE_RUNTIME_ID_RE = /^\0vinext:worker-server-reference$/;
|
|
11
|
+
function workerReferenceRuntime(browserRuntime) {
|
|
12
|
+
return `import { createServerReference } from ${JSON.stringify(browserRuntime)};
|
|
13
|
+
|
|
14
|
+
function callServer() {
|
|
15
|
+
return new Promise(() => {
|
|
16
|
+
reportError(new Error("Server Functions cannot be called from a browser Web Worker."));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createWorkerServerReference(id, name) {
|
|
21
|
+
return createServerReference(id, callServer, undefined, undefined, name);
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
}
|
|
25
|
+
/** A module-local binding that cannot collide with any name in `code`. */
|
|
26
|
+
function uniqueBinding(code, base) {
|
|
27
|
+
let binding = base;
|
|
28
|
+
while (code.includes(binding)) binding += "_";
|
|
29
|
+
return binding;
|
|
30
|
+
}
|
|
31
|
+
function isPlainFilePath(id) {
|
|
32
|
+
return !/[\0?#]/.test(id) && fs.existsSync(id);
|
|
33
|
+
}
|
|
34
|
+
function withPositionedError(ctx, run) {
|
|
35
|
+
return Promise.resolve().then(run).catch((error) => {
|
|
36
|
+
if (error instanceof Error && "pos" in error && typeof error.pos === "number") ctx.error(error.message, error.pos);
|
|
37
|
+
throw error;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Replace `"use server"` modules in browser Web Worker bundles with Server
|
|
42
|
+
* Function reference proxies.
|
|
43
|
+
*
|
|
44
|
+
* Vite bundles every worker in a fresh plugin container built from
|
|
45
|
+
* `worker.plugins`, so @vitejs/plugin-rsc's `rsc:use-server` transform never
|
|
46
|
+
* sees worker modules in production builds and the module bodies would be
|
|
47
|
+
* emitted verbatim. Next.js compiles workers as part of the browser graph,
|
|
48
|
+
* where `"use server"` exports become `createServerReference(...)` proxies.
|
|
49
|
+
* This mirrors the client-environment branch of `rsc:use-server` with the
|
|
50
|
+
* same reference keys, without claiming references.
|
|
51
|
+
*
|
|
52
|
+
* The worker realm has no router to dispatch Server Function calls. Next.js's
|
|
53
|
+
* `callServer` dispatches inside `startTransition`, so the dispatch error is
|
|
54
|
+
* reported globally and the call's promise never settles; the worker
|
|
55
|
+
* references reproduce that instead of reaching the server.
|
|
56
|
+
*/
|
|
57
|
+
async function createWorkerUseServerPlugins(options) {
|
|
58
|
+
const rscRequire = createRequire(options.rscPluginPath);
|
|
59
|
+
const importRscModule = (specifier) => import(pathToFileURL(rscRequire.resolve(specifier)).href);
|
|
60
|
+
const browserRuntime = pathToFileURL(rscRequire.resolve("@vitejs/plugin-rsc/react/browser")).href;
|
|
61
|
+
const [transforms, rscCore] = await Promise.all([importRscModule("@vitejs/plugin-rsc/transforms"), importRscModule("@vitejs/plugin-rsc/core/plugin")]);
|
|
62
|
+
let manager;
|
|
63
|
+
const useServerPlugin = {
|
|
64
|
+
name: "vinext:worker-use-server",
|
|
65
|
+
async configResolved(config) {
|
|
66
|
+
// @vitejs/plugin-rsc's plugin API (and its reference manager) lives.
|
|
67
|
+
const mainConfig = config.mainConfig;
|
|
68
|
+
manager = (await options.rscPluginModule).getPluginApi(mainConfig ?? config)?.manager;
|
|
69
|
+
},
|
|
70
|
+
resolveId: {
|
|
71
|
+
filter: { id: WORKER_REFERENCE_RUNTIME_ID_RE },
|
|
72
|
+
handler: (source) => source
|
|
73
|
+
},
|
|
74
|
+
load: {
|
|
75
|
+
filter: { id: WORKER_REFERENCE_RUNTIME_ID_RE },
|
|
76
|
+
handler: () => workerReferenceRuntime(browserRuntime)
|
|
77
|
+
},
|
|
78
|
+
transform: {
|
|
79
|
+
filter: { code: "use server" },
|
|
80
|
+
async handler(code, id) {
|
|
81
|
+
let ast = await parseAstAsync(code);
|
|
82
|
+
if (!transforms.hasDirective(ast.body, "use server")) return null;
|
|
83
|
+
if (!manager) throw new Error("vinext: cannot compile a \"use server\" module in a Web Worker without @vitejs/plugin-rsc.");
|
|
84
|
+
const expanded = await withPositionedError(this, () => transforms.transformExpandExportAll({
|
|
85
|
+
code,
|
|
86
|
+
ast,
|
|
87
|
+
importer: id,
|
|
88
|
+
resolve: async (source, importer) => (await this.resolve(source, importer))?.id,
|
|
89
|
+
load: async (target) => {
|
|
90
|
+
if (!isPlainFilePath(target)) throw new Error(`vinext: a "use server" module imported by a Web Worker cannot \`export *\` from ${JSON.stringify(target)}; re-export its names explicitly.`);
|
|
91
|
+
this.addWatchFile(target);
|
|
92
|
+
const source = await fs.promises.readFile(target, "utf-8");
|
|
93
|
+
return parseAstAsync((await transformWithOxc(source, target, { sourcemap: false })).code);
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
if (expanded) {
|
|
97
|
+
code = expanded.code;
|
|
98
|
+
ast = await parseAstAsync(code);
|
|
99
|
+
}
|
|
100
|
+
const { referenceKey } = manager.serverReferences.resolve(id, "rsc");
|
|
101
|
+
const runtime = uniqueBinding(code, "$$vinextWorkerReference");
|
|
102
|
+
const result = await withPositionedError(this, () => transforms.transformDirectiveProxyExport(ast, {
|
|
103
|
+
code,
|
|
104
|
+
directive: "use server",
|
|
105
|
+
rejectNonAsyncFunction: true,
|
|
106
|
+
runtime: (name) => `${runtime}(${JSON.stringify(`${referenceKey}#${name}`)}, ${JSON.stringify(name)})`
|
|
107
|
+
}));
|
|
108
|
+
if (!result?.output.hasChanged()) return null;
|
|
109
|
+
result.output.prepend(`import { createWorkerServerReference as ${runtime} } from ${JSON.stringify(WORKER_REFERENCE_RUNTIME_ID)};\n`);
|
|
110
|
+
return magicStringTransformResult(result.output);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const patchHook = rscCore.default().find((plugin) => plugin.name === "rsc:patch-react-server-dom-webpack")?.transform;
|
|
115
|
+
if (!patchHook || typeof patchHook !== "object") throw new Error("vinext: @vitejs/plugin-rsc no longer exposes its Flight client patch plugin.");
|
|
116
|
+
const flightClientDir = path.dirname(rscRequire.resolve("@vitejs/plugin-rsc/vendor/react-server-dom/client.browser"));
|
|
117
|
+
return [{
|
|
118
|
+
name: "vinext:worker-patch-react-server-dom",
|
|
119
|
+
transform: {
|
|
120
|
+
filter: {
|
|
121
|
+
id: new RegExp(`^${escapeRegExp(`${toSlash(flightClientDir)}/`)}`),
|
|
122
|
+
code: "__webpack_require__"
|
|
123
|
+
},
|
|
124
|
+
handler: patchHook.handler
|
|
125
|
+
}
|
|
126
|
+
}, useServerPlugin];
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { createWorkerUseServerPlugins };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
//#region src/routing/file-matcher.d.ts
|
|
2
|
+
export declare const DEFAULT_PAGE_EXTENSIONS: readonly ["tsx", "ts", "jsx", "js"];
|
|
2
3
|
export declare function normalizePageExtensions(pageExtensions?: readonly string[] | null): string[];
|
|
3
4
|
export type ValidFileMatcher = {
|
|
4
5
|
extensions: string[];
|
|
@@ -152,4 +152,4 @@ async function* scanWithExtensions(stem, cwd, extensions, exclude) {
|
|
|
152
152
|
})) yield toSlash(file);
|
|
153
153
|
}
|
|
154
154
|
//#endregion
|
|
155
|
-
export { buildViteResolveExtensions, createValidFileMatcher, findFileWithExtensions, findFileWithExts, normalizePageExtensions, normalizeViteResolveExtensions, scanWithExtensions };
|
|
155
|
+
export { DEFAULT_PAGE_EXTENSIONS, buildViteResolveExtensions, createValidFileMatcher, findFileWithExtensions, findFileWithExts, normalizePageExtensions, normalizeViteResolveExtensions, scanWithExtensions };
|
|
@@ -13,5 +13,6 @@ export declare function handleApiRoute(runner: ModuleImporter, req: IncomingMess
|
|
|
13
13
|
trustedRevalidateOrigin?: string;
|
|
14
14
|
allowedRevalidateHeaderKeys?: readonly string[];
|
|
15
15
|
trailingSlash?: boolean;
|
|
16
|
+
skipTrailingSlashRedirect?: boolean;
|
|
16
17
|
}): Promise<boolean>;
|
|
17
18
|
//#endregion
|
|
@@ -11,6 +11,7 @@ import { resolveRequestHost, resolveRequestProtocol } from "./proxy-trust.js";
|
|
|
11
11
|
import { performOnDemandRevalidate } from "./pages-revalidate.js";
|
|
12
12
|
import { attachPagesPreviewApi, attachPagesRequestCookies } from "./pages-node-compat.js";
|
|
13
13
|
import { finalizeEdgeApiResponse, isEdgeApiRuntime } from "./edge-api-runtime.js";
|
|
14
|
+
import { signalFromNodeResponse } from "./node-response-signal.js";
|
|
14
15
|
import { Buffer } from "node:buffer";
|
|
15
16
|
import { decode } from "node:querystring";
|
|
16
17
|
//#region src/server/api-handler.ts
|
|
@@ -89,7 +90,7 @@ function readEdgeRequestBody(req) {
|
|
|
89
90
|
req.on("error", (error) => controller.error(error));
|
|
90
91
|
} });
|
|
91
92
|
}
|
|
92
|
-
function createEdgeApiRequest(req, url, params, nextConfig) {
|
|
93
|
+
function createEdgeApiRequest(req, res, url, params, nextConfig) {
|
|
93
94
|
const headers = new Headers();
|
|
94
95
|
for (const [name, value] of Object.entries(req.headers)) {
|
|
95
96
|
if (name.startsWith(":")) continue;
|
|
@@ -103,10 +104,12 @@ function createEdgeApiRequest(req, url, params, nextConfig) {
|
|
|
103
104
|
if (basePath && !hasBasePath(requestUrl.pathname, basePath)) requestUrl.pathname = `${basePath}${requestUrl.pathname}`;
|
|
104
105
|
const query = mergeRouteParamsIntoQuery(parseQueryString(url), params);
|
|
105
106
|
requestUrl.search = urlQueryToSearchParams(query).toString();
|
|
106
|
-
const
|
|
107
|
+
const signal = signalFromNodeResponse(res);
|
|
108
|
+
const body = signal.aborted ? void 0 : readEdgeRequestBody(req);
|
|
107
109
|
const init = {
|
|
108
110
|
headers,
|
|
109
|
-
method: req.method
|
|
111
|
+
method: req.method,
|
|
112
|
+
signal
|
|
110
113
|
};
|
|
111
114
|
if (body) {
|
|
112
115
|
init.body = body;
|
|
@@ -138,12 +141,17 @@ function waitForWritableDrain(res) {
|
|
|
138
141
|
res.once("close", onClose);
|
|
139
142
|
});
|
|
140
143
|
}
|
|
141
|
-
async function writeEdgeApiResponseBody(res, body) {
|
|
144
|
+
async function writeEdgeApiResponseBody(res, body, signal) {
|
|
142
145
|
if (!body) {
|
|
143
146
|
res.end();
|
|
144
147
|
return;
|
|
145
148
|
}
|
|
146
149
|
const reader = body.getReader();
|
|
150
|
+
const cancel = () => {
|
|
151
|
+
reader.cancel(signal.reason).catch(() => {});
|
|
152
|
+
};
|
|
153
|
+
if (signal.aborted) cancel();
|
|
154
|
+
else signal.addEventListener("abort", cancel, { once: true });
|
|
147
155
|
try {
|
|
148
156
|
while (true) {
|
|
149
157
|
const result = await reader.read();
|
|
@@ -151,11 +159,13 @@ async function writeEdgeApiResponseBody(res, body) {
|
|
|
151
159
|
if (result.value.byteLength === 0) continue;
|
|
152
160
|
if (!res.write(Buffer.from(result.value))) await waitForWritableDrain(res);
|
|
153
161
|
}
|
|
154
|
-
res.end();
|
|
162
|
+
if (!signal.aborted) res.end();
|
|
155
163
|
} catch (error) {
|
|
164
|
+
if (signal.aborted) return;
|
|
156
165
|
res.destroy(error instanceof Error ? error : new Error(String(error)));
|
|
157
166
|
throw error;
|
|
158
167
|
} finally {
|
|
168
|
+
signal.removeEventListener("abort", cancel);
|
|
159
169
|
reader.releaseLock();
|
|
160
170
|
}
|
|
161
171
|
}
|
|
@@ -224,10 +234,11 @@ async function handleApiRoute(runner, req, res, url, apiRoutes, nextConfig) {
|
|
|
224
234
|
try {
|
|
225
235
|
const apiModule = await importModule(runner, route.filePath);
|
|
226
236
|
if (isEdgeApiRouteModule(apiModule)) {
|
|
227
|
-
const nextRequest = new NextRequest(createEdgeApiRequest(req, url, params, nextConfig), nextConfig ? { nextConfig: {
|
|
237
|
+
const nextRequest = new NextRequest(createEdgeApiRequest(req, res, url, params, nextConfig), nextConfig ? { nextConfig: {
|
|
228
238
|
basePath: nextConfig.basePath,
|
|
229
239
|
i18n: nextConfig.i18n ?? void 0,
|
|
230
|
-
trailingSlash: nextConfig.trailingSlash
|
|
240
|
+
trailingSlash: nextConfig.trailingSlash,
|
|
241
|
+
skipTrailingSlashRedirect: nextConfig.skipTrailingSlashRedirect
|
|
231
242
|
} } : void 0);
|
|
232
243
|
const handlerResponse = await tracePagesApiHandler(route.pattern, () => apiModule.default(nextRequest));
|
|
233
244
|
if (!(handlerResponse instanceof Response)) throw new Error("Edge API route did not return a Response");
|
|
@@ -239,7 +250,7 @@ async function handleApiRoute(runner, req, res, url, apiRoutes, nextConfig) {
|
|
|
239
250
|
if (name !== "set-cookie") res.setHeader(name, value);
|
|
240
251
|
});
|
|
241
252
|
if (setCookieHeaders.length) res.setHeader("set-cookie", setCookieHeaders);
|
|
242
|
-
await writeEdgeApiResponseBody(res, response.body);
|
|
253
|
+
await writeEdgeApiResponseBody(res, response.body, nextRequest.signal);
|
|
243
254
|
return true;
|
|
244
255
|
}
|
|
245
256
|
const handler = apiModule.default;
|
|
@@ -25,7 +25,7 @@ export declare function isServerActionResult<TRoot>(value: unknown): value is Ap
|
|
|
25
25
|
export declare function shouldClearClientNavigationCachesForServerActionResult<TRoot>(result: AppBrowserServerActionResult<TRoot> | TRoot, revalidation?: ServerActionRevalidationKind): boolean;
|
|
26
26
|
export declare function parseServerActionRevalidationHeader(headers: Pick<Headers, "get">): ServerActionRevalidationKind;
|
|
27
27
|
export declare function resolveServerActionOperationLane(revalidation: ServerActionRevalidationKind): Extract<OperationLane, "refresh" | "server-action">;
|
|
28
|
-
export declare function normalizeServerActionThrownValue(data: unknown, responseStatus: number): unknown
|
|
28
|
+
export declare function normalizeServerActionThrownValue(data: unknown, responseStatus: number): Promise<unknown>;
|
|
29
29
|
export declare function shouldSyncServerActionHttpFallbackHead<TRoot>(result: AppBrowserServerActionResult<TRoot> | TRoot): boolean;
|
|
30
30
|
export declare function readInvalidServerActionResponseError(response: Pick<Response, "headers" | "status" | "text">, hasRedirectLocation: boolean): Promise<Error | null>;
|
|
31
31
|
export type ServerActionResultResponseFactsInput = {
|
|
@@ -41,8 +41,15 @@ function createServerActionHttpFallbackError(status) {
|
|
|
41
41
|
const error = /* @__PURE__ */ new Error(status === 404 ? "NEXT_NOT_FOUND" : `NEXT_HTTP_ERROR_FALLBACK;${status}`);
|
|
42
42
|
return Object.assign(error, { digest });
|
|
43
43
|
}
|
|
44
|
-
function normalizeServerActionThrownValue(data, responseStatus) {
|
|
45
|
-
|
|
44
|
+
async function normalizeServerActionThrownValue(data, responseStatus) {
|
|
45
|
+
const fallbackError = createServerActionHttpFallbackError(responseStatus);
|
|
46
|
+
if (fallbackError) return fallbackError;
|
|
47
|
+
try {
|
|
48
|
+
await data;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
return error;
|
|
51
|
+
}
|
|
52
|
+
return data;
|
|
46
53
|
}
|
|
47
54
|
function shouldSyncServerActionHttpFallbackHead(result) {
|
|
48
55
|
if (!isServerActionResult(result) || result.root !== void 0) return false;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { splitPathnameForRouteMatch } from "../routing/utils.js";
|
|
2
2
|
import { addBasePathToPathname, stripBasePath } from "../utils/base-path.js";
|
|
3
3
|
import { VINEXT_CLIENT_REUSE_MANIFEST_HEADER, VINEXT_PARAMS_HEADER, VINEXT_RENDERED_PATH_AND_SEARCH_HEADER, VINEXT_RSC_REDIRECT_HEADER, VINEXT_RSC_REDIRECT_TYPE_HEADER } from "./headers.js";
|
|
4
|
-
import { AppElementsWire } from "./app-elements-wire.js";
|
|
5
|
-
import { getMountedSlotIdsHeader, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
|
|
6
4
|
import { AppRouterContext } from "../shims/internal/app-router-context.js";
|
|
7
5
|
import { matchRoutePattern } from "../routing/route-pattern.js";
|
|
8
6
|
import { installWindowNext, setWindowNextInternalSourcePage } from "../client/window-next.js";
|
|
9
7
|
import { retryScrollTo, scrollToHashTargetOnNextFrame } from "../shims/hash-scroll.js";
|
|
8
|
+
import { AppElementsWire } from "./app-elements-wire.js";
|
|
9
|
+
import { getMountedSlotIdsHeader, resolveVisitedResponseInterceptionContext } from "./app-elements.js";
|
|
10
10
|
import { getBfcacheIdMapContext, getNavigationContext, setNavigationContext } from "../shims/navigation-context-state.js";
|
|
11
11
|
import { decodeRedirectError, isRedirectError } from "../shims/navigation-errors.js";
|
|
12
12
|
import DefaultGlobalError from "../shims/default-global-error.js";
|
|
@@ -362,22 +362,22 @@ function createActionInitiationSnapshot() {
|
|
|
362
362
|
}
|
|
363
363
|
function createNavigationCommitEffect(options) {
|
|
364
364
|
const { activeRoutePaths, bfcacheIds, href, historyUpdateMode, navId, params, previousNextUrl, targetHistoryIndex } = options;
|
|
365
|
-
return () => {
|
|
365
|
+
return ({ keepCurrentUrl, releaseSnapshot }) => {
|
|
366
366
|
if (!browserNavigationController.isCurrentNavigation(navId)) {
|
|
367
|
-
commitClientNavigationState(void 0, { releaseSnapshot
|
|
367
|
+
commitClientNavigationState(void 0, { releaseSnapshot });
|
|
368
368
|
return;
|
|
369
369
|
}
|
|
370
370
|
historyController.commitNavigationHistory({
|
|
371
371
|
activeRoutePaths,
|
|
372
372
|
bfcacheIds,
|
|
373
373
|
href,
|
|
374
|
-
historyUpdateMode,
|
|
374
|
+
historyUpdateMode: keepCurrentUrl ? void 0 : historyUpdateMode,
|
|
375
375
|
previousNextUrl,
|
|
376
376
|
stageClientParams: () => stageClientParams(params),
|
|
377
377
|
targetHistoryIndex
|
|
378
378
|
});
|
|
379
379
|
clearAppNavigationFailureTarget(href);
|
|
380
|
-
commitClientNavigationState(navId);
|
|
380
|
+
commitClientNavigationState(navId, { releaseSnapshot });
|
|
381
381
|
};
|
|
382
382
|
}
|
|
383
383
|
async function renderNavigationPayload(options) {
|
|
@@ -1505,7 +1505,11 @@ function bootstrapHydration(rscStream, devErrorOverlay, initialRscBootstrap) {
|
|
|
1505
1505
|
},
|
|
1506
1506
|
preparePrefetchResponse: (response) => decodeAppElementsPromise(createFromFetch(Promise.resolve(response))),
|
|
1507
1507
|
claimCurrentHistoryTreeSnapshot: (historyUpdateMode, previousHistoryState) => historyController.claimCurrentHistoryTreeSnapshot(historyUpdateMode, previousHistoryState),
|
|
1508
|
-
commitAppOwnedHistoryStateWrite: (historyUpdateMode, previousHistoryState) => historyController.commitAppOwnedHistoryStateWrite(historyUpdateMode, previousHistoryState)
|
|
1508
|
+
commitAppOwnedHistoryStateWrite: (historyUpdateMode, previousHistoryState) => historyController.commitAppOwnedHistoryStateWrite(historyUpdateMode, previousHistoryState),
|
|
1509
|
+
discardPendingNavigation: () => {
|
|
1510
|
+
if (browserNavigationController.discardPendingNavigation(historyController.readCurrentTreeSnapshot())) navigationAbortCoordinator.abortActive();
|
|
1511
|
+
},
|
|
1512
|
+
flushCommittingNavigationUrl: () => browserNavigationController.flushCommittingNavigationUrl()
|
|
1509
1513
|
});
|
|
1510
1514
|
const handlePopstate = createPopstateRestoreHandler({
|
|
1511
1515
|
getActiveNavigationId: browserNavigationController.getActiveNavigationId.bind(browserNavigationController),
|
|
@@ -79,6 +79,8 @@ export declare class AppBrowserHistoryController {
|
|
|
79
79
|
beginCacheInvalidationGuard(): () => void;
|
|
80
80
|
invalidateRestorableClientState(): void;
|
|
81
81
|
rememberHistoryStateSnapshot(state: AppRouterState): void;
|
|
82
|
+
/** The router state of the most recently committed render, if any. */
|
|
83
|
+
readCurrentTreeSnapshot(): AppRouterState | null;
|
|
82
84
|
isCurrentExternalHistoryTree(historyState: unknown): boolean;
|
|
83
85
|
/** Records the raw/hash history entry that now claims the live tree. */
|
|
84
86
|
claimCurrentHistoryTreeSnapshot(historyUpdateMode: HistoryUpdateMode, previousHistoryState: unknown): void;
|
|
@@ -96,6 +96,9 @@ var AppBrowserHistoryController = class {
|
|
|
96
96
|
this.#treeSnapshotIdPendingFreshState = historyTreeSnapshotId !== null && this.#treeSnapshots.has(historyTreeSnapshotId) ? historyTreeSnapshotId : null;
|
|
97
97
|
}
|
|
98
98
|
rememberHistoryStateSnapshot(state) {
|
|
99
|
+
const previousState = this.readCurrentTreeSnapshot();
|
|
100
|
+
const previousOperation = previousState?.activeOperation;
|
|
101
|
+
if (previousState && previousOperation?.navigationCommitKind === "detached" && state.activeOperation?.navigationCommitKind === "authoritative" && state.activeOperation.navigationId === previousOperation.navigationId) this.#restorableClientState.replaceHistoryStateSnapshots(previousState, state);
|
|
99
102
|
this.#restorableClientState.rememberHistoryStateSnapshot({
|
|
100
103
|
historyIndex: this.#currentHistoryTraversalIndex,
|
|
101
104
|
state
|
|
@@ -109,6 +112,11 @@ var AppBrowserHistoryController = class {
|
|
|
109
112
|
if (previousTreeSnapshotId !== null && previousTreeSnapshotId !== treeSnapshotId && !this.#treeSnapshotClaimCounts.has(previousTreeSnapshotId)) this.#treeSnapshots.delete(previousTreeSnapshotId);
|
|
110
113
|
if (historyTreeSnapshotId !== treeSnapshotId) this.#replaceHistoryState(createHistoryStateWithTreeSnapshotId(this.#readHistoryState(), treeSnapshotId));
|
|
111
114
|
}
|
|
115
|
+
/** The router state of the most recently committed render, if any. */
|
|
116
|
+
readCurrentTreeSnapshot() {
|
|
117
|
+
if (this.#currentTreeSnapshotId === null) return null;
|
|
118
|
+
return this.#treeSnapshots.get(this.#currentTreeSnapshotId) ?? null;
|
|
119
|
+
}
|
|
112
120
|
isCurrentExternalHistoryTree(historyState) {
|
|
113
121
|
const treeSnapshotId = readHistoryStateTreeSnapshotId(historyState);
|
|
114
122
|
return treeSnapshotId !== null && treeSnapshotId === this.#currentTreeSnapshotId;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { splitPathnameForRouteMatch } from "../routing/utils.js";
|
|
1
|
+
import { normalizePathnameForRouteMatch, splitPathnameForRouteMatch } from "../routing/utils.js";
|
|
2
2
|
import { stripBasePath } from "../utils/base-path.js";
|
|
3
|
+
import { normalizePath } from "./normalize-path.js";
|
|
3
4
|
import { matchRoutePattern, matchRoutePatternPrefix, matchRoutePatternWithOptionalDynamicSegments } from "../routing/route-pattern.js";
|
|
4
5
|
//#region src/server/app-browser-interception-context.ts
|
|
5
6
|
/**
|
|
@@ -37,9 +38,32 @@ function resolveMiddlewareRewriteNavigationInterceptionContext(options) {
|
|
|
37
38
|
for (const interception of options.routeManifest.segmentGraph.interceptions.values()) {
|
|
38
39
|
if (!matchRoutePatternWithOptionalDynamicSegments(targetParts, interception.targetPatternParts)) continue;
|
|
39
40
|
if (matchRoutePatternPrefix(sourceParts, interception.sourcePatternParts)) return currentPathname;
|
|
40
|
-
if (currentMatchedPathname !== null && matchedSourceParts !== null && matchRoutePatternPrefix(matchedSourceParts, interception.sourcePatternParts)) return currentMatchedPathname;
|
|
41
|
+
if (currentMatchedPathname !== null && matchedSourceParts !== null && matchRoutePatternPrefix(matchedSourceParts, interception.sourcePatternParts)) return encodeMatchedPathname(currentMatchedPathname);
|
|
41
42
|
}
|
|
42
43
|
return null;
|
|
43
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* The matched route pathname is the matched URL decoded once per segment, with
|
|
47
|
+
* path delimiters (and literal `%2F`-style text) re-escaped. The server matches
|
|
48
|
+
* the context on its raw segments, so undo that: keep the escaped delimiters and
|
|
49
|
+
* encode every other `%`, then let the URL parser encode the rest (`café`
|
|
50
|
+
* becomes `caf%C3%A9`). An escaped ASCII character comes back unescaped (`%61`
|
|
51
|
+
* as `a`), like Next.js's `Next-Url`, which it builds from the router tree's
|
|
52
|
+
* canonical params; both spellings match the same params. `%252F` is
|
|
53
|
+
* ambiguous, since both a literal `%2F` and a literal `%252F` produce it. That
|
|
54
|
+
* case, and a result that does not reproduce the same matched pathname because
|
|
55
|
+
* the URL parser changed it (stripping a control character, say), navigate
|
|
56
|
+
* without interception instead of naming a different source.
|
|
57
|
+
*/
|
|
58
|
+
function encodeMatchedPathname(pathname) {
|
|
59
|
+
if (/%25(?:2f|23|3f|5c)/i.test(pathname)) return null;
|
|
60
|
+
let encoded;
|
|
61
|
+
try {
|
|
62
|
+
encoded = new URL(pathname.replace(/%(?!(?:25)?(?:2f|23|3f|5c))/gi, "%25"), "http://n").pathname;
|
|
63
|
+
} catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return normalizePath(normalizePathnameForRouteMatch(encoded)) === pathname ? encoded : null;
|
|
67
|
+
}
|
|
44
68
|
//#endregion
|
|
45
69
|
export { resolveManifestNavigationInterceptionContext, resolveMiddlewareRewriteNavigationInterceptionContext };
|
|
@@ -17,7 +17,10 @@ export type PendingBrowserRouterState = {
|
|
|
17
17
|
};
|
|
18
18
|
export type NavigationPayloadOutcome = "committed" | "no-commit" | "hard-navigate";
|
|
19
19
|
type HardNavigationMode = "assign" | "replace";
|
|
20
|
-
type BrowserNavigationCommitEffect = (
|
|
20
|
+
type BrowserNavigationCommitEffect = (options: {
|
|
21
|
+
keepCurrentUrl: boolean;
|
|
22
|
+
releaseSnapshot: boolean;
|
|
23
|
+
}) => void;
|
|
21
24
|
type BrowserNavigationCommitEffectFactory = (options: {
|
|
22
25
|
activeRoutePaths: readonly string[];
|
|
23
26
|
bfcacheIds: Readonly<Record<string, string>>;
|
|
@@ -78,6 +81,8 @@ type BrowserNavigationController = {
|
|
|
78
81
|
attachBrowserRouterState(setter: Dispatch<AppRouterState | Promise<AppRouterState>>, stateRef: BrowserRouterStateRef): () => void;
|
|
79
82
|
beginPendingBrowserRouterState(): PendingBrowserRouterState;
|
|
80
83
|
finalizeNavigation(navId: number, pending: PendingBrowserRouterState | null | undefined): void;
|
|
84
|
+
discardPendingNavigation(visibleState: AppRouterState | null): boolean;
|
|
85
|
+
flushCommittingNavigationUrl(): void;
|
|
81
86
|
restoreHistorySnapshotVisibleState(options: {
|
|
82
87
|
restoreCopiedExternalHistoryEntry?: boolean;
|
|
83
88
|
beforeCommit?: () => void;
|
|
@@ -100,6 +105,7 @@ type BrowserNavigationController = {
|
|
|
100
105
|
* navigation would otherwise be lost.
|
|
101
106
|
*/
|
|
102
107
|
drainPrePaintEffects(renderId: number): void;
|
|
108
|
+
beginNavigationRenderCommit(renderId: number): void;
|
|
103
109
|
commitNavigationRender(renderId: number): void;
|
|
104
110
|
clearCommittedNavigationFailureTargets(renderId: number): void;
|
|
105
111
|
NavigationCommitSignal(this: void, { renderId, children }: {
|