@qzsy/vinext 0.1.12 → 0.1.81
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 +19 -5
- package/dist/build/inject-pregenerated-paths.d.ts +4 -0
- package/dist/build/inject-pregenerated-paths.js +18 -0
- package/dist/build/pages-client-assets-module.d.ts +11 -0
- package/dist/build/pages-client-assets-module.js +27 -0
- package/dist/build/prerender.d.ts +2 -1
- package/dist/build/prerender.js +11 -4
- package/dist/build/report.d.ts +2 -1
- package/dist/build/report.js +2 -1
- package/dist/build/run-prerender.d.ts +7 -0
- package/dist/build/run-prerender.js +9 -0
- package/dist/build/standalone.js +2 -0
- package/dist/check.d.ts +18 -0
- package/dist/check.js +77 -19
- package/dist/cli-dev-config.d.ts +12 -0
- package/dist/cli-dev-config.js +23 -0
- package/dist/cli.js +64 -28
- package/dist/{server → client}/dev-error-overlay-store.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay-store.js +1 -1
- package/dist/{server → client}/dev-error-overlay.d.ts +1 -1
- package/dist/{server → client}/dev-error-overlay.js +2 -2
- package/dist/cloudflare/deploy-config.d.ts +51 -0
- package/dist/cloudflare/deploy-config.js +153 -0
- package/dist/cloudflare/index.d.ts +1 -1
- package/dist/cloudflare/index.js +1 -1
- package/dist/cloudflare/project.d.ts +41 -0
- package/dist/cloudflare/project.js +243 -0
- package/dist/cloudflare/tpr.js +1 -1
- package/dist/config/config-matchers.js +14 -10
- package/dist/config/next-config.d.ts +6 -3
- package/dist/config/next-config.js +47 -1
- package/dist/config/server-external-packages.d.ts +4 -0
- package/dist/config/server-external-packages.js +91 -0
- package/dist/deploy.d.ts +2 -122
- package/dist/deploy.js +20 -793
- package/dist/entries/app-rsc-entry.d.ts +2 -1
- package/dist/entries/app-rsc-entry.js +70 -12
- package/dist/entries/app-rsc-manifest.js +8 -0
- package/dist/entries/pages-client-entry.d.ts +1 -0
- package/dist/entries/pages-client-entry.js +2 -1
- package/dist/entries/pages-server-entry.js +6 -2
- package/dist/image/image-adapters-virtual.d.ts +59 -0
- package/dist/image/image-adapters-virtual.js +50 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +160 -160
- package/dist/init-cloudflare.d.ts +43 -0
- package/dist/init-cloudflare.js +1000 -0
- package/dist/init-platform.d.ts +38 -0
- package/dist/init-platform.js +150 -0
- package/dist/init.d.ts +14 -37
- package/dist/init.js +205 -95
- package/dist/node_modules/.pnpm/am-i-vibing@0.5.0/node_modules/am-i-vibing/dist/detector-1yx2Hoe0.js +294 -0
- package/dist/node_modules/.pnpm/process-ancestry@0.1.0/node_modules/process-ancestry/dist/index.js +94 -0
- package/dist/{cloudflare → packages/cloudflare}/src/cache/cdn-adapter.runtime.js +1 -1
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.d.ts +2 -2
- package/dist/{cloudflare → packages/cloudflare}/src/cache/kv-data-adapter.runtime.js +1 -1
- package/dist/plugins/ast-scope.d.ts +16 -0
- package/dist/plugins/ast-scope.js +62 -0
- package/dist/plugins/ast-utils.js +3 -0
- package/dist/plugins/css-module-imports.d.ts +14 -0
- package/dist/plugins/css-module-imports.js +59 -0
- package/dist/plugins/ignore-dynamic-requests.d.ts +11 -0
- package/dist/plugins/ignore-dynamic-requests.js +530 -0
- package/dist/plugins/middleware-server-only.d.ts +8 -6
- package/dist/plugins/middleware-server-only.js +8 -7
- package/dist/plugins/optimize-imports.js +1 -1
- package/dist/plugins/typeof-window.d.ts +1 -1
- package/dist/plugins/typeof-window.js +28 -56
- package/dist/routing/app-route-graph.d.ts +13 -2
- package/dist/routing/app-route-graph.js +116 -32
- package/dist/routing/app-router.d.ts +5 -0
- package/dist/routing/app-router.js +5 -0
- package/dist/routing/file-matcher.d.ts +8 -0
- package/dist/routing/file-matcher.js +10 -1
- package/dist/routing/pages-router.js +2 -2
- package/dist/server/app-browser-action-result.d.ts +2 -1
- package/dist/server/app-browser-action-result.js +5 -1
- package/dist/server/app-browser-entry.js +17 -12
- package/dist/server/app-browser-history-controller.d.ts +2 -1
- package/dist/server/app-browser-history-controller.js +6 -2
- package/dist/server/app-browser-interception-context.d.ts +1 -0
- package/dist/server/app-browser-interception-context.js +4 -2
- package/dist/server/app-browser-navigation-controller.js +1 -0
- package/dist/server/app-browser-server-action-client.js +2 -3
- package/dist/server/app-browser-state.d.ts +1 -0
- package/dist/server/app-browser-state.js +3 -2
- package/dist/server/app-fallback-renderer.d.ts +3 -2
- package/dist/server/app-fallback-renderer.js +12 -7
- package/dist/server/app-middleware.d.ts +2 -3
- package/dist/server/app-middleware.js +3 -2
- package/dist/server/app-optimistic-routing.js +1 -1
- package/dist/server/app-page-boundary-render.d.ts +1 -0
- package/dist/server/app-page-boundary-render.js +12 -3
- package/dist/server/app-page-cache-finalizer.d.ts +1 -0
- package/dist/server/app-page-cache-finalizer.js +10 -3
- package/dist/server/app-page-cache-render.d.ts +1 -0
- package/dist/server/app-page-cache-render.js +8 -4
- package/dist/server/app-page-cache.d.ts +1 -0
- package/dist/server/app-page-cache.js +4 -1
- package/dist/server/app-page-dispatch.d.ts +11 -3
- package/dist/server/app-page-dispatch.js +55 -15
- package/dist/server/app-page-element-builder.d.ts +5 -1
- package/dist/server/app-page-element-builder.js +57 -20
- package/dist/server/app-page-head.d.ts +12 -0
- package/dist/server/app-page-head.js +42 -19
- package/dist/server/app-page-params.d.ts +2 -1
- package/dist/server/app-page-params.js +8 -1
- package/dist/server/app-page-probe.d.ts +1 -0
- package/dist/server/app-page-probe.js +6 -1
- package/dist/server/app-page-render-identity.d.ts +1 -0
- package/dist/server/app-page-render-identity.js +1 -1
- package/dist/server/app-page-render.d.ts +4 -1
- package/dist/server/app-page-render.js +8 -3
- package/dist/server/app-page-request.d.ts +22 -1
- package/dist/server/app-page-request.js +89 -13
- package/dist/server/app-page-route-wiring.d.ts +6 -1
- package/dist/server/app-page-route-wiring.js +31 -15
- package/dist/server/app-page-search-params-observation.d.ts +4 -2
- package/dist/server/app-page-search-params-observation.js +11 -7
- package/dist/server/app-page-segment-state.js +2 -0
- package/dist/server/app-route-handler-dispatch.js +1 -0
- package/dist/server/app-route-handler-execution.js +7 -2
- package/dist/server/app-route-handler-response.js +1 -0
- package/dist/server/app-route-handler-runtime.js +1 -1
- package/dist/server/app-route-module-loader.d.ts +2 -0
- package/dist/server/app-route-module-loader.js +1 -0
- package/dist/server/app-router-entry.d.ts +12 -0
- package/dist/server/app-router-entry.js +22 -8
- package/dist/server/app-router-image-optimization.d.ts +37 -0
- package/dist/server/app-router-image-optimization.js +40 -0
- package/dist/server/app-rsc-errors.js +7 -1
- package/dist/server/app-rsc-handler.js +27 -14
- package/dist/server/app-rsc-route-matching.d.ts +7 -0
- package/dist/server/app-rsc-route-matching.js +36 -3
- package/dist/server/app-segment-config.d.ts +12 -0
- package/dist/server/app-segment-config.js +91 -5
- package/dist/server/app-server-action-execution.d.ts +5 -0
- package/dist/server/app-server-action-execution.js +106 -33
- package/dist/server/app-ssr-entry.js +12 -1
- package/dist/server/app-static-generation.d.ts +1 -0
- package/dist/server/app-static-generation.js +1 -0
- package/dist/server/client-trace-metadata.js +26 -0
- package/dist/server/default-global-not-found-module.d.ts +14 -0
- package/dist/server/default-global-not-found-module.js +14 -0
- package/dist/server/dev-response-headers.d.ts +19 -0
- package/dist/server/dev-response-headers.js +78 -0
- package/dist/server/dev-server.js +8 -15
- package/dist/server/dev-stack-sourcemap.d.ts +1 -1
- package/dist/server/dev-stack-sourcemap.js +1 -1
- package/dist/server/headers.d.ts +7 -15
- package/dist/server/headers.js +6 -15
- package/dist/server/image-optimization.d.ts +51 -1
- package/dist/server/image-optimization.js +52 -2
- package/dist/server/isr-cache.d.ts +1 -1
- package/dist/server/isr-cache.js +2 -2
- package/dist/server/middleware-runtime.js +6 -1
- package/dist/server/navigation-planner.d.ts +1 -0
- package/dist/server/navigation-planner.js +14 -3
- package/dist/server/pages-asset-tags.d.ts +4 -6
- package/dist/server/pages-asset-tags.js +12 -12
- package/dist/server/pages-client-assets.d.ts +12 -0
- package/dist/server/pages-client-assets.js +10 -0
- package/dist/server/pages-page-data.d.ts +23 -1
- package/dist/server/pages-page-data.js +43 -24
- package/dist/server/pages-page-handler.d.ts +2 -1
- package/dist/server/pages-page-handler.js +10 -4
- package/dist/server/pages-request-pipeline.d.ts +2 -0
- package/dist/server/pages-request-pipeline.js +25 -1
- package/dist/server/prerender-manifest.d.ts +3 -1
- package/dist/server/prerender-route-params.js +1 -1
- package/dist/server/prod-server.d.ts +1 -1
- package/dist/server/prod-server.js +47 -25
- package/dist/server/request-log.d.ts +5 -14
- package/dist/server/request-log.js +7 -1
- package/dist/server/request-pipeline.js +1 -0
- package/dist/server/seed-cache.js +4 -4
- package/dist/server/server-action-logger.d.ts +39 -0
- package/dist/server/server-action-logger.js +104 -0
- package/dist/server/worker-utils.d.ts +2 -1
- package/dist/server/worker-utils.js +7 -1
- package/dist/shims/app-router-scroll-state.d.ts +1 -0
- package/dist/shims/app-router-scroll-state.js +1 -0
- package/dist/shims/app-router-scroll.js +2 -1
- package/dist/shims/cache.js +19 -15
- package/dist/shims/cdn-cache.js +1 -1
- package/dist/shims/dynamic-preload-chunks.js +2 -1
- package/dist/shims/error-boundary.d.ts +19 -1
- package/dist/shims/error-boundary.js +11 -1
- package/dist/shims/form.d.ts +3 -1
- package/dist/shims/form.js +37 -43
- package/dist/shims/headers.d.ts +9 -1
- package/dist/shims/headers.js +31 -6
- package/dist/shims/image-optimization-url.d.ts +4 -0
- package/dist/shims/image-optimization-url.js +33 -1
- package/dist/shims/image.js +46 -13
- package/dist/shims/internal/app-route-detection.d.ts +2 -17
- package/dist/shims/internal/app-route-detection.js +4 -17
- package/dist/shims/internal/hybrid-client-route-owner-direct.d.ts +23 -0
- package/dist/shims/internal/hybrid-client-route-owner-direct.js +51 -0
- package/dist/shims/internal/hybrid-client-route-owner.d.ts +2 -5
- package/dist/shims/internal/hybrid-client-route-owner.js +9 -60
- package/dist/shims/internal/pages-router-components.d.ts +7 -0
- package/dist/shims/internal/pages-router-components.js +13 -0
- package/dist/shims/link.js +23 -16
- package/dist/shims/metadata.d.ts +3 -2
- package/dist/shims/metadata.js +8 -4
- package/dist/shims/navigation.js +4 -2
- package/dist/shims/root-params.d.ts +15 -1
- package/dist/shims/root-params.js +21 -1
- package/dist/shims/router.d.ts +2 -5
- package/dist/shims/router.js +41 -22
- package/dist/shims/server.js +3 -2
- package/dist/typegen.js +6 -5
- package/dist/utils/client-runtime-metadata.d.ts +2 -18
- package/dist/utils/client-runtime-metadata.js +31 -22
- package/dist/utils/dev-stack-sourcemap-endpoint.d.ts +4 -0
- package/dist/{server → utils}/dev-stack-sourcemap-endpoint.js +1 -1
- package/dist/utils/domain-locale.d.ts +6 -3
- package/dist/{server → utils}/middleware-request-headers.d.ts +1 -1
- package/dist/{server → utils}/middleware-request-headers.js +2 -2
- package/dist/utils/path.d.ts +2 -1
- package/dist/utils/path.js +1 -1
- package/dist/utils/project.d.ts +9 -1
- package/dist/utils/project.js +21 -4
- package/dist/utils/protocol-headers.d.ts +17 -0
- package/dist/utils/protocol-headers.js +17 -0
- package/dist/utils/react-version.d.ts +4 -0
- package/dist/utils/react-version.js +44 -0
- package/package.json +29 -23
- package/dist/server/dev-stack-sourcemap-endpoint.d.ts +0 -4
- /package/dist/{cloudflare → packages/cloudflare}/src/utils/cache-control-metadata.js +0 -0
package/dist/shims/cache.js
CHANGED
|
@@ -5,7 +5,7 @@ import { MemoryCacheHandler, NoOpCacheHandler, configureMemoryCacheHandler, getC
|
|
|
5
5
|
import { getCdnCacheAdapter } from "./cdn-cache.js";
|
|
6
6
|
import { fnv1a64 } from "../utils/hash.js";
|
|
7
7
|
import { makeHangingPromise } from "./internal/make-hanging-promise.js";
|
|
8
|
-
import { getHeadersAccessPhase, markDynamicUsage } from "./headers.js";
|
|
8
|
+
import { getHeadersAccessPhase, isDraftModeEnabled, markDynamicUsage } from "./headers.js";
|
|
9
9
|
import { ACTION_DID_REVALIDATE_DYNAMIC_ONLY, ACTION_DID_REVALIDATE_STATIC_AND_DYNAMIC, _consumeRequestScopedCacheLife, _initRequestScopedCacheState, _peekRequestScopedCacheLife, _peekUnstableCacheObservations, _registerCacheContextAccessor, _runWithCacheState, _setRequestScopedCacheLife, cacheLifeProfiles, getAndClearActionRevalidationKind, getRegisteredCacheContext, markActionRevalidation, recordUnstableCacheObservation, shouldServeStaleUnstableCacheEntry } from "./cache-request-state.js";
|
|
10
10
|
import { encodeCacheTag, encodeCacheTags } from "../utils/encode-cache-tag.js";
|
|
11
11
|
import { workUnitAsyncStorage } from "./internal/work-unit-async-storage.js";
|
|
@@ -110,10 +110,10 @@ function refresh() {
|
|
|
110
110
|
*
|
|
111
111
|
* @see https://nextjs.org/docs/app/api-reference/functions/updateTag
|
|
112
112
|
*/
|
|
113
|
-
|
|
113
|
+
function updateTag(tag) {
|
|
114
114
|
if (getHeadersAccessPhase() !== "action") throw new Error("updateTag can only be called from within a Server Action. To invalidate cache tags in Route Handlers or other contexts, use revalidateTag instead. See more info here: https://nextjs.org/docs/app/api-reference/functions/updateTag");
|
|
115
115
|
markActionRevalidation(1);
|
|
116
|
-
|
|
116
|
+
return _invalidateEncodedTag(encodeCacheTag(tag));
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
119
119
|
* Opt out of static rendering and indicate a particular component should not be cached.
|
|
@@ -380,19 +380,23 @@ function unstable_cache(fn, keyParts, options) {
|
|
|
380
380
|
tagCount: tags.length,
|
|
381
381
|
tagHash: tags.length > 0 ? fnv1a64(JSON.stringify(tags)) : null
|
|
382
382
|
});
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
383
|
+
const isDraftMode = isDraftModeEnabled();
|
|
384
|
+
if (!isDraftMode) {
|
|
385
|
+
const existing = await getDataCacheHandler().get(cacheKey, {
|
|
386
|
+
kind: "FETCH",
|
|
387
|
+
tags
|
|
388
|
+
});
|
|
389
|
+
if (existing?.value && existing.value.kind === "FETCH") {
|
|
390
|
+
const cached = tryDeserializeUnstableCacheResult(existing.value.data.body);
|
|
391
|
+
if (cached.ok) if (existing.cacheState === "stale") {
|
|
392
|
+
if (shouldServeStaleUnstableCacheEntry()) {
|
|
393
|
+
scheduleUnstableCacheBackgroundRevalidation(cacheKey, () => refreshUnstableCacheResult(fn, args, cacheKey, tags, revalidateSeconds));
|
|
394
|
+
return cached.value;
|
|
395
|
+
}
|
|
396
|
+
} else return cached.value;
|
|
397
|
+
}
|
|
395
398
|
}
|
|
399
|
+
if (isDraftMode) return await _unstableCacheAls.run(true, () => fn(...args));
|
|
396
400
|
return await refreshUnstableCacheResult(fn, args, cacheKey, tags, revalidateSeconds);
|
|
397
401
|
};
|
|
398
402
|
return cachedFn;
|
package/dist/shims/cdn-cache.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getRequestExecutionContext } from "./request-context.js";
|
|
2
2
|
import { getDataCacheHandler } from "./cache-handler.js";
|
|
3
|
-
import { CloudflareCdnCacheAdapter } from "../cloudflare/src/cache/cdn-adapter.runtime.js";
|
|
3
|
+
import { CloudflareCdnCacheAdapter } from "../packages/cloudflare/src/cache/cdn-adapter.runtime.js";
|
|
4
4
|
//#region src/shims/cdn-cache.ts
|
|
5
5
|
/**
|
|
6
6
|
* CDN cache adapter — owns the *page-level ISR serving strategy*.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { appendAssetDeploymentIdQuery } from "../utils/deployment-id.js";
|
|
3
3
|
import { useScriptNonce } from "./script-nonce-context.js";
|
|
4
|
+
import { getPagesClientAssets } from "../server/pages-client-assets.js";
|
|
4
5
|
import React from "react";
|
|
5
6
|
import * as ReactDOM from "react-dom";
|
|
6
7
|
//#region src/shims/dynamic-preload-chunks.tsx
|
|
@@ -34,7 +35,7 @@ function dynamicPreloadHref(file) {
|
|
|
34
35
|
}
|
|
35
36
|
function resolveDynamicPreloadFiles(moduleIds) {
|
|
36
37
|
if (!moduleIds || moduleIds.length === 0) return [];
|
|
37
|
-
const preloadMap =
|
|
38
|
+
const preloadMap = getPagesClientAssets().dynamicPreloads;
|
|
38
39
|
if (!preloadMap) return [];
|
|
39
40
|
const files = [];
|
|
40
41
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -9,6 +9,24 @@ type ErrorBoundaryProps = {
|
|
|
9
9
|
children: React.ReactNode;
|
|
10
10
|
resetKey?: string | null;
|
|
11
11
|
};
|
|
12
|
+
type SerializedBoundaryError = {
|
|
13
|
+
digest?: string;
|
|
14
|
+
message: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
stack?: string;
|
|
17
|
+
};
|
|
18
|
+
declare function SerializedErrorBoundary({
|
|
19
|
+
fallback: Fallback,
|
|
20
|
+
error
|
|
21
|
+
}: {
|
|
22
|
+
fallback: React.ComponentType<{
|
|
23
|
+
error: Error & {
|
|
24
|
+
digest?: string;
|
|
25
|
+
};
|
|
26
|
+
reset: () => void;
|
|
27
|
+
}>;
|
|
28
|
+
error: SerializedBoundaryError;
|
|
29
|
+
}): React.JSX.Element;
|
|
12
30
|
type CapturedError = {
|
|
13
31
|
thrownValue: unknown;
|
|
14
32
|
};
|
|
@@ -152,4 +170,4 @@ declare class DevRecoveryBoundary extends React.Component<DevRecoveryBoundaryPro
|
|
|
152
170
|
render(): React.ReactNode;
|
|
153
171
|
}
|
|
154
172
|
//#endregion
|
|
155
|
-
export { DevRecoveryBoundary, DevRecoveryBoundaryProps, ErrorBoundary, ErrorBoundaryInner, ErrorBoundaryProps, ErrorBoundaryState, ForbiddenBoundary, ForbiddenBoundaryInner, GlobalErrorBoundary, NotFoundBoundary, RedirectBoundary, RedirectErrorBoundary, UnauthorizedBoundary, UnauthorizedBoundaryInner };
|
|
173
|
+
export { DevRecoveryBoundary, DevRecoveryBoundaryProps, ErrorBoundary, ErrorBoundaryInner, ErrorBoundaryProps, ErrorBoundaryState, ForbiddenBoundary, ForbiddenBoundaryInner, GlobalErrorBoundary, NotFoundBoundary, RedirectBoundary, RedirectErrorBoundary, SerializedBoundaryError, SerializedErrorBoundary, UnauthorizedBoundary, UnauthorizedBoundaryInner };
|
|
@@ -9,6 +9,16 @@ import { isNavigationSignalError } from "../utils/navigation-signal.js";
|
|
|
9
9
|
import React from "react";
|
|
10
10
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
//#region src/shims/error-boundary.tsx
|
|
12
|
+
function SerializedErrorBoundary({ fallback: Fallback, error }) {
|
|
13
|
+
return /* @__PURE__ */ jsx(Fallback, {
|
|
14
|
+
error: Object.assign(new Error(error.message), {
|
|
15
|
+
digest: error.digest,
|
|
16
|
+
name: error.name ?? "Error",
|
|
17
|
+
stack: error.stack
|
|
18
|
+
}),
|
|
19
|
+
reset: () => globalThis.location?.reload()
|
|
20
|
+
});
|
|
21
|
+
}
|
|
12
22
|
function normalizeBoundaryResetKey(resetKey) {
|
|
13
23
|
return resetKey === void 0 || resetKey === null || resetKey === "" ? null : resetKey;
|
|
14
24
|
}
|
|
@@ -339,4 +349,4 @@ var DevRecoveryBoundary = class extends React.Component {
|
|
|
339
349
|
}
|
|
340
350
|
};
|
|
341
351
|
//#endregion
|
|
342
|
-
export { DevRecoveryBoundary, ErrorBoundary, ErrorBoundaryInner, ForbiddenBoundary, ForbiddenBoundaryInner, GlobalErrorBoundary, NotFoundBoundary, RedirectBoundary, RedirectErrorBoundary, UnauthorizedBoundary, UnauthorizedBoundaryInner };
|
|
352
|
+
export { DevRecoveryBoundary, ErrorBoundary, ErrorBoundaryInner, ForbiddenBoundary, ForbiddenBoundaryInner, GlobalErrorBoundary, NotFoundBoundary, RedirectBoundary, RedirectErrorBoundary, SerializedErrorBoundary, UnauthorizedBoundary, UnauthorizedBoundaryInner };
|
package/dist/shims/form.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FormHTMLAttributes, useActionState } from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/shims/form.d.ts
|
|
4
|
+
type FormSubmitter = HTMLButtonElement | HTMLInputElement;
|
|
5
|
+
declare function createFormSubmitDestinationUrl(action: string, form: HTMLFormElement, submitter: FormSubmitter | null): string;
|
|
4
6
|
declare const Form: import("react").ForwardRefExoticComponent<{
|
|
5
7
|
/** Target URL for GET forms, or server action for POST forms */action: string | ((formData: FormData) => void | Promise<void>); /** Replace instead of push in history (default: false) */
|
|
6
8
|
replace?: boolean; /** Scroll to top after navigation (default: true) */
|
|
@@ -16,4 +18,4 @@ declare const Form: import("react").ForwardRefExoticComponent<{
|
|
|
16
18
|
prefetch?: false | null;
|
|
17
19
|
} & Omit<FormHTMLAttributes<HTMLFormElement>, "method" | "encType" | "target"> & import("react").RefAttributes<HTMLFormElement>>;
|
|
18
20
|
//#endregion
|
|
19
|
-
export { Form as default, useActionState };
|
|
21
|
+
export { createFormSubmitDestinationUrl, Form as default, useActionState };
|
package/dist/shims/form.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { VINEXT_MOUNTED_SLOTS_HEADER } from "../server/headers.js";
|
|
3
|
-
import {
|
|
3
|
+
import { assertSafeNavigationUrl } from "./url-safety.js";
|
|
4
4
|
import { AppElementsWire } from "../server/app-elements-wire.js";
|
|
5
|
+
import { APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL } from "../server/app-rsc-render-mode.js";
|
|
5
6
|
import "../server/app-elements.js";
|
|
6
|
-
import {
|
|
7
|
+
import { withBasePath } from "./url-utils.js";
|
|
8
|
+
import { isBotUserAgent } from "../utils/html-limited-bots.js";
|
|
7
9
|
import { createRscRequestHeaders, createRscRequestUrl } from "../server/app-rsc-cache-busting.js";
|
|
8
10
|
import { hasAppNavigationRuntime } from "../client/navigation-runtime.js";
|
|
9
11
|
import { getMountedSlotsHeader, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, navigateClientSide, prefetchRscResponse } from "./navigation.js";
|
|
@@ -37,18 +39,13 @@ const DISALLOWED_FORM_PROPS = [
|
|
|
37
39
|
const SUPPORTED_FORM_ENCTYPE = "application/x-www-form-urlencoded";
|
|
38
40
|
const SUPPORTED_FORM_METHOD = "GET";
|
|
39
41
|
const SUPPORTED_FORM_TARGET = "_self";
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return new URL(action).origin === window.location.origin;
|
|
46
|
-
} catch {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
42
|
+
function isPrefetchableAction(action) {
|
|
43
|
+
try {
|
|
44
|
+
const actionUrl = new URL(action, window.location.href);
|
|
45
|
+
return (actionUrl.protocol === "http:" || actionUrl.protocol === "https:") && actionUrl.origin === window.location.origin;
|
|
46
|
+
} catch {
|
|
49
47
|
return false;
|
|
50
48
|
}
|
|
51
|
-
return true;
|
|
52
49
|
}
|
|
53
50
|
function getSubmitter(nativeEvent) {
|
|
54
51
|
const submitter = nativeEvent && typeof nativeEvent === "object" && "submitter" in nativeEvent && nativeEvent.submitter instanceof Element ? nativeEvent.submitter : null;
|
|
@@ -103,7 +100,7 @@ function createFormSubmitDestinationUrl(action, form, submitter) {
|
|
|
103
100
|
if (process.env.NODE_ENV !== "production") console.warn("<Form> only supports file inputs if `action` is a function. File inputs cannot be used if `action` is a string, because files cannot be encoded as search params.");
|
|
104
101
|
targetUrl.searchParams.append(name, value.name);
|
|
105
102
|
} else targetUrl.searchParams.append(name, value);
|
|
106
|
-
return
|
|
103
|
+
return targetUrl.href;
|
|
107
104
|
}
|
|
108
105
|
function buildFormData(form, submitter) {
|
|
109
106
|
if (!submitter) return new FormData(form);
|
|
@@ -137,7 +134,7 @@ const Form = forwardRef(function Form(props, ref) {
|
|
|
137
134
|
useEffect(() => {
|
|
138
135
|
if (typeof action !== "string") return;
|
|
139
136
|
if (prefetch === false || process.env.NODE_ENV !== "production") return;
|
|
140
|
-
if (!
|
|
137
|
+
if (!isPrefetchableAction(actionHref)) return;
|
|
141
138
|
if (!hasAppNavigationRuntime()) return;
|
|
142
139
|
const node = formRef.current;
|
|
143
140
|
if (!node) return;
|
|
@@ -145,9 +142,13 @@ const Form = forwardRef(function Form(props, ref) {
|
|
|
145
142
|
const observer = new IntersectionObserver((entries) => {
|
|
146
143
|
for (const entry of entries) if (entry.isIntersecting || entry.intersectionRatio > 0) {
|
|
147
144
|
(async () => {
|
|
145
|
+
if (isBotUserAgent(window.navigator?.userAgent ?? "")) return;
|
|
148
146
|
const interceptionContext = getPrefetchInterceptionContext(actionHref);
|
|
149
147
|
const mountedSlotsHeader = getMountedSlotsHeader();
|
|
150
|
-
const headers = createRscRequestHeaders({
|
|
148
|
+
const headers = createRscRequestHeaders({
|
|
149
|
+
interceptionContext,
|
|
150
|
+
renderMode: APP_RSC_RENDER_MODE_PREFETCH_LOADING_SHELL
|
|
151
|
+
});
|
|
151
152
|
if (mountedSlotsHeader) headers.set(VINEXT_MOUNTED_SLOTS_HEADER, mountedSlotsHeader);
|
|
152
153
|
const rscUrl = await createRscRequestUrl(actionHref, headers);
|
|
153
154
|
const cacheKey = AppElementsWire.encodeCacheKey(rscUrl, interceptionContext);
|
|
@@ -161,8 +162,8 @@ const Form = forwardRef(function Form(props, ref) {
|
|
|
161
162
|
priority: "low",
|
|
162
163
|
purpose: "prefetch"
|
|
163
164
|
}), interceptionContext, mountedSlotsHeader, void 0, {
|
|
164
|
-
cacheForNavigation:
|
|
165
|
-
optimisticRouteShell:
|
|
165
|
+
cacheForNavigation: false,
|
|
166
|
+
optimisticRouteShell: true
|
|
166
167
|
});
|
|
167
168
|
})();
|
|
168
169
|
observer.unobserve(node);
|
|
@@ -183,15 +184,7 @@ const Form = forwardRef(function Form(props, ref) {
|
|
|
183
184
|
onSubmit,
|
|
184
185
|
...cleanRest
|
|
185
186
|
});
|
|
186
|
-
|
|
187
|
-
if (process.env.NODE_ENV !== "production") console.warn(`<Form> blocked unsafe action: ${action}`);
|
|
188
|
-
return /* @__PURE__ */ jsx("form", {
|
|
189
|
-
ref: setRefs,
|
|
190
|
-
onSubmit,
|
|
191
|
-
...cleanRest
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
async function handleSubmit(e) {
|
|
187
|
+
function handleSubmit(e) {
|
|
195
188
|
if (onSubmit) {
|
|
196
189
|
onSubmit(e);
|
|
197
190
|
if (e.defaultPrevented) return;
|
|
@@ -204,23 +197,24 @@ const Form = forwardRef(function Form(props, ref) {
|
|
|
204
197
|
}
|
|
205
198
|
const effectiveAction = getEffectiveAction(submitter, actionHref);
|
|
206
199
|
if (process.env.NODE_ENV !== "production" && submitter?.getAttribute("formaction") !== null) checkFormActionUrl(effectiveAction, "formAction");
|
|
207
|
-
if (!isSafeAction(effectiveAction)) {
|
|
208
|
-
if (process.env.NODE_ENV !== "production") console.warn(`<Form> blocked unsafe action: ${effectiveAction}`);
|
|
209
|
-
e.preventDefault();
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
e.preventDefault();
|
|
213
200
|
const url = createFormSubmitDestinationUrl(effectiveAction, e.currentTarget, submitter);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
if (hasAppNavigationRuntime()) {
|
|
203
|
+
assertSafeNavigationUrl(url);
|
|
204
|
+
navigateClientSide(url, replace ? "replace" : "push", scroll);
|
|
205
|
+
} else {
|
|
206
|
+
assertSafeNavigationUrl(url);
|
|
207
|
+
(async () => {
|
|
208
|
+
let Router;
|
|
209
|
+
try {
|
|
210
|
+
Router = (await import("./router.js")).default;
|
|
211
|
+
if (replace) await Router.replace(url, void 0, { scroll });
|
|
212
|
+
else await Router.push(url, void 0, { scroll });
|
|
213
|
+
} catch {
|
|
214
|
+
if (replace) window.location.replace(url);
|
|
215
|
+
else window.location.assign(url);
|
|
216
|
+
}
|
|
217
|
+
})();
|
|
224
218
|
}
|
|
225
219
|
}
|
|
226
220
|
return /* @__PURE__ */ jsx("form", {
|
|
@@ -233,4 +227,4 @@ const Form = forwardRef(function Form(props, ref) {
|
|
|
233
227
|
});
|
|
234
228
|
});
|
|
235
229
|
//#endregion
|
|
236
|
-
export { Form as default, useActionState };
|
|
230
|
+
export { createFormSubmitDestinationUrl, Form as default, useActionState };
|
package/dist/shims/headers.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ type HeadersContext = {
|
|
|
5
5
|
headers: Headers;
|
|
6
6
|
cookies: Map<string, string>;
|
|
7
7
|
accessError?: Error;
|
|
8
|
+
draftModeEnabled?: boolean;
|
|
8
9
|
forceStatic?: boolean;
|
|
9
10
|
mutableCookies?: RequestCookies;
|
|
10
11
|
readonlyCookies?: RequestCookies;
|
|
@@ -47,6 +48,7 @@ type ConnectionProbeResult<T> = {
|
|
|
47
48
|
*/
|
|
48
49
|
declare function markDynamicUsage(): void;
|
|
49
50
|
declare function markRenderRequestApiUsage(kind: RenderRequestApiKind): void;
|
|
51
|
+
declare function throwIfStaticGenerationAccessError(): void;
|
|
50
52
|
declare function runWithConnectionProbe<T>(fn: () => T | Promise<T>): Promise<ConnectionProbeResult<T>>;
|
|
51
53
|
declare function suspendConnectionProbe(): Promise<never> | null;
|
|
52
54
|
declare function peekRenderRequestApiUsage(): RenderRequestApiKind[];
|
|
@@ -177,6 +179,12 @@ declare function getAndClearPendingCookies(): string[];
|
|
|
177
179
|
*/
|
|
178
180
|
declare function getDraftModeCookieHeader(): string | null;
|
|
179
181
|
declare function isDraftModeRequest(request: Request, draftModeSecret: string): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Read the active request's draft-mode state without recording request API usage.
|
|
184
|
+
* Internal cache implementations use this to bypass persistent reads and writes,
|
|
185
|
+
* matching Next.js's request-level `workStore.isDraftMode` guard.
|
|
186
|
+
*/
|
|
187
|
+
declare function isDraftModeEnabled(): boolean;
|
|
180
188
|
type DraftModeResult = {
|
|
181
189
|
readonly isEnabled: boolean;
|
|
182
190
|
enable(): void;
|
|
@@ -250,4 +258,4 @@ declare class RequestCookies {
|
|
|
250
258
|
toString(): string;
|
|
251
259
|
}
|
|
252
260
|
//#endregion
|
|
253
|
-
export { HeadersAccessPhase, HeadersContext, type RequestCookies, VinextHeadersShimState, applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope };
|
|
261
|
+
export { HeadersAccessPhase, HeadersContext, type RequestCookies, VinextHeadersShimState, applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeEnabled, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope, throwIfStaticGenerationAccessError };
|
package/dist/shims/headers.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getOrCreateAls } from "./internal/als-registry.js";
|
|
2
2
|
import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
|
|
3
|
-
import { MIDDLEWARE_SET_COOKIE_HEADER } from "../
|
|
4
|
-
import {
|
|
3
|
+
import { MIDDLEWARE_SET_COOKIE_HEADER } from "../utils/protocol-headers.js";
|
|
4
|
+
import { FLIGHT_HEADERS, NEXT_HTML_REQUEST_ID_HEADER, NEXT_REQUEST_ID_HEADER } from "../server/headers.js";
|
|
5
|
+
import { buildRequestHeadersFromMiddlewareResponse } from "../utils/middleware-request-headers.js";
|
|
5
6
|
import { serializeSetCookie, validateCookieAttributeValue, validateCookieName } from "./internal/cookie-serialize.js";
|
|
6
7
|
import { parseEdgeRequestCookieHeader } from "../utils/parse-cookie.js";
|
|
7
8
|
import { createPprFallbackShellSuspensePromise } from "./ppr-fallback-shell.js";
|
|
@@ -117,6 +118,10 @@ function markDynamicUsage() {
|
|
|
117
118
|
function markRenderRequestApiUsage(kind) {
|
|
118
119
|
_getState().renderRequestApiUsage.add(kind);
|
|
119
120
|
}
|
|
121
|
+
function throwIfStaticGenerationAccessError() {
|
|
122
|
+
const accessError = _getState().headersContext?.accessError;
|
|
123
|
+
if (accessError) throw accessError;
|
|
124
|
+
}
|
|
120
125
|
async function runWithConnectionProbe(fn) {
|
|
121
126
|
const state = _getState();
|
|
122
127
|
const previousProbe = state.connectionProbe;
|
|
@@ -468,7 +473,13 @@ function _getReadonlyCookies(ctx) {
|
|
|
468
473
|
return ctx.readonlyCookies;
|
|
469
474
|
}
|
|
470
475
|
function _getReadonlyHeaders(ctx) {
|
|
471
|
-
if (!ctx.readonlyHeaders)
|
|
476
|
+
if (!ctx.readonlyHeaders) {
|
|
477
|
+
const cleaned = new Headers(ctx.headers);
|
|
478
|
+
for (const header of FLIGHT_HEADERS) cleaned.delete(header);
|
|
479
|
+
cleaned.delete(NEXT_REQUEST_ID_HEADER);
|
|
480
|
+
cleaned.delete(NEXT_HTML_REQUEST_ID_HEADER);
|
|
481
|
+
ctx.readonlyHeaders = _sealHeaders(cleaned);
|
|
482
|
+
}
|
|
472
483
|
return ctx.readonlyHeaders;
|
|
473
484
|
}
|
|
474
485
|
/**
|
|
@@ -599,6 +610,19 @@ function isDraftModeRequest(request, draftModeSecret) {
|
|
|
599
610
|
if (!cookieHeader) return false;
|
|
600
611
|
return parseEdgeRequestCookieHeader(cookieHeader).get(DRAFT_MODE_COOKIE) === validateDraftModeSecret(draftModeSecret);
|
|
601
612
|
}
|
|
613
|
+
/**
|
|
614
|
+
* Read the active request's draft-mode state without recording request API usage.
|
|
615
|
+
* Internal cache implementations use this to bypass persistent reads and writes,
|
|
616
|
+
* matching Next.js's request-level `workStore.isDraftMode` guard.
|
|
617
|
+
*/
|
|
618
|
+
function isDraftModeEnabled() {
|
|
619
|
+
const context = _getState().headersContext;
|
|
620
|
+
if (!context) return false;
|
|
621
|
+
if (context.draftModeEnabled !== void 0) return context.draftModeEnabled;
|
|
622
|
+
const secret = context.draftModeSecret;
|
|
623
|
+
if (secret === void 0) return false;
|
|
624
|
+
return context.cookies.get(DRAFT_MODE_COOKIE) === validateDraftModeSecret(secret);
|
|
625
|
+
}
|
|
602
626
|
function draftModeCookieAttributes() {
|
|
603
627
|
if (typeof process !== "undefined" && process.env?.NODE_ENV === "development") return "Path=/; HttpOnly; SameSite=Lax";
|
|
604
628
|
return "Path=/; HttpOnly; SameSite=None; Secure";
|
|
@@ -631,16 +655,16 @@ async function draftMode() {
|
|
|
631
655
|
const state = _getState();
|
|
632
656
|
const context = state.headersContext;
|
|
633
657
|
if (!context) throw createDraftModeScopeError("draftMode()");
|
|
634
|
-
if (context.accessError) throw context.accessError;
|
|
635
658
|
const secret = ensureContextDraftModeSecret(context);
|
|
636
659
|
return {
|
|
637
660
|
get isEnabled() {
|
|
638
|
-
return context.cookies.get(DRAFT_MODE_COOKIE) === secret;
|
|
661
|
+
return context.draftModeEnabled ?? context.cookies.get(DRAFT_MODE_COOKIE) === secret;
|
|
639
662
|
},
|
|
640
663
|
enable() {
|
|
641
664
|
throwIfInsideCacheScope("draftMode().enable()");
|
|
642
665
|
const activeContext = requireActiveDraftModeContext(state, context, "draftMode().enable()");
|
|
643
666
|
markDynamicUsage();
|
|
667
|
+
activeContext.draftModeEnabled = true;
|
|
644
668
|
activeContext.cookies.set(DRAFT_MODE_COOKIE, secret);
|
|
645
669
|
state.draftModeCookieHeader = `${DRAFT_MODE_COOKIE}=${secret}; ${draftModeCookieAttributes()}`;
|
|
646
670
|
},
|
|
@@ -648,6 +672,7 @@ async function draftMode() {
|
|
|
648
672
|
throwIfInsideCacheScope("draftMode().disable()");
|
|
649
673
|
const activeContext = requireActiveDraftModeContext(state, context, "draftMode().disable()");
|
|
650
674
|
markDynamicUsage();
|
|
675
|
+
activeContext.draftModeEnabled = false;
|
|
651
676
|
activeContext.cookies.delete(DRAFT_MODE_COOKIE);
|
|
652
677
|
state.draftModeCookieHeader = `${DRAFT_MODE_COOKIE}=; ${draftModeCookieAttributes()}; Expires=${DRAFT_MODE_EXPIRED_DATE}`;
|
|
653
678
|
}
|
|
@@ -751,4 +776,4 @@ var RequestCookies = class {
|
|
|
751
776
|
}
|
|
752
777
|
};
|
|
753
778
|
//#endregion
|
|
754
|
-
export { applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope };
|
|
779
|
+
export { applyMiddlewareRequestHeaders, consumeDynamicUsage, consumeInvalidDynamicUsageError, consumeRenderRequestApiUsage, cookies, draftMode, getAndClearPendingCookies, getDraftModeCookieHeader, getHeadersAccessPhase, getHeadersContext, headers, headersContextFromRequest, isDraftModeEnabled, isDraftModeRequest, markDynamicUsage, markRenderRequestApiUsage, peekDynamicUsage, peekRenderRequestApiUsage, runWithConnectionProbe, runWithHeadersContext, setHeadersAccessPhase, setHeadersContext, suspendConnectionProbe, throwIfInsideCacheScope, throwIfStaticGenerationAccessError };
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Shared by the next/image shim and the default image loader module so
|
|
6
6
|
* `images.loaderFile` aliasing does not create a circular import.
|
|
7
|
+
*
|
|
8
|
+
* In production (Cloudflare Workers), the worker intercepts this path and uses
|
|
9
|
+
* the Images binding to resize/transcode on the fly. In dev, the Vite dev
|
|
10
|
+
* server handles it as a passthrough (serves the original file).
|
|
7
11
|
*/
|
|
8
12
|
declare function imageOptimizationUrl(src: string, width: number, quality?: number): string;
|
|
9
13
|
//#endregion
|
|
@@ -1,12 +1,44 @@
|
|
|
1
|
+
import { getDeploymentId } from "../utils/deployment-id.js";
|
|
1
2
|
//#region src/shims/image-optimization-url.ts
|
|
3
|
+
function extractLocalDeploymentId(src) {
|
|
4
|
+
let deploymentId = getDeploymentId();
|
|
5
|
+
if (!src.startsWith("/") || src.startsWith("//")) return {
|
|
6
|
+
src,
|
|
7
|
+
deploymentId
|
|
8
|
+
};
|
|
9
|
+
const queryIndex = src.indexOf("?");
|
|
10
|
+
if (queryIndex === -1) return {
|
|
11
|
+
src,
|
|
12
|
+
deploymentId
|
|
13
|
+
};
|
|
14
|
+
const params = new URLSearchParams(src.slice(queryIndex + 1));
|
|
15
|
+
const sourceDeploymentId = params.get("dpl");
|
|
16
|
+
if (!sourceDeploymentId) return {
|
|
17
|
+
src,
|
|
18
|
+
deploymentId
|
|
19
|
+
};
|
|
20
|
+
deploymentId = sourceDeploymentId;
|
|
21
|
+
params.delete("dpl");
|
|
22
|
+
const remainingQuery = params.toString();
|
|
23
|
+
return {
|
|
24
|
+
src: src.slice(0, queryIndex) + (remainingQuery ? `?${remainingQuery}` : ""),
|
|
25
|
+
deploymentId
|
|
26
|
+
};
|
|
27
|
+
}
|
|
2
28
|
/**
|
|
3
29
|
* Build a `/_next/image` optimization URL.
|
|
4
30
|
*
|
|
5
31
|
* Shared by the next/image shim and the default image loader module so
|
|
6
32
|
* `images.loaderFile` aliasing does not create a circular import.
|
|
33
|
+
*
|
|
34
|
+
* In production (Cloudflare Workers), the worker intercepts this path and uses
|
|
35
|
+
* the Images binding to resize/transcode on the fly. In dev, the Vite dev
|
|
36
|
+
* server handles it as a passthrough (serves the original file).
|
|
7
37
|
*/
|
|
8
38
|
function imageOptimizationUrl(src, width, quality = 75) {
|
|
9
|
-
|
|
39
|
+
const source = extractLocalDeploymentId(src);
|
|
40
|
+
const deploymentQuery = source.src.startsWith("/") && source.deploymentId ? `&dpl=${source.deploymentId}` : "";
|
|
41
|
+
return `/_next/image?url=${encodeURIComponent(source.src)}&w=${width}&q=${quality}${deploymentQuery}`;
|
|
10
42
|
}
|
|
11
43
|
//#endregion
|
|
12
44
|
export { imageOptimizationUrl };
|
package/dist/shims/image.js
CHANGED
|
@@ -56,6 +56,22 @@ const __imageDeviceSizes = (() => {
|
|
|
56
56
|
];
|
|
57
57
|
}
|
|
58
58
|
})();
|
|
59
|
+
const __imageSizes = (() => {
|
|
60
|
+
try {
|
|
61
|
+
return JSON.parse(process.env.__VINEXT_IMAGE_SIZES ?? "[16,32,48,64,96,128,256,384]");
|
|
62
|
+
} catch {
|
|
63
|
+
return [
|
|
64
|
+
16,
|
|
65
|
+
32,
|
|
66
|
+
48,
|
|
67
|
+
64,
|
|
68
|
+
96,
|
|
69
|
+
128,
|
|
70
|
+
256,
|
|
71
|
+
384
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
})();
|
|
59
75
|
/**
|
|
60
76
|
* Whether dangerouslyAllowSVG is enabled in next.config.js.
|
|
61
77
|
* When false (default), .svg sources auto-skip the optimization endpoint
|
|
@@ -78,6 +94,7 @@ function resolveEffectiveLoader(loader) {
|
|
|
78
94
|
if (typeof defaultImageLoader !== "function") throw new Error("images.loaderFile detected but the file is missing default export.\nRead more: https://nextjs.org/docs/messages/invalid-images-config");
|
|
79
95
|
return defaultImageLoader;
|
|
80
96
|
}
|
|
97
|
+
const __globallyUnoptimized = process.env.__VINEXT_IMAGE_UNOPTIMIZED === "true";
|
|
81
98
|
/**
|
|
82
99
|
* Validate that a remote URL is allowed by the configured remote patterns.
|
|
83
100
|
* Returns true if the URL is allowed, false otherwise.
|
|
@@ -220,7 +237,8 @@ function resolveImageSource(v) {
|
|
|
220
237
|
* These are the breakpoints used for srcSet generation.
|
|
221
238
|
* Configurable via `images.deviceSizes` in next.config.js.
|
|
222
239
|
*/
|
|
223
|
-
const RESPONSIVE_WIDTHS = __imageDeviceSizes;
|
|
240
|
+
const RESPONSIVE_WIDTHS = [...__imageDeviceSizes].sort((left, right) => left - right);
|
|
241
|
+
const ALL_IMAGE_WIDTHS = [...RESPONSIVE_WIDTHS, ...__imageSizes].sort((left, right) => left - right);
|
|
224
242
|
function preloadImageResource(input) {
|
|
225
243
|
if (!input.shouldPreload) return;
|
|
226
244
|
if (typeof ReactDOM.preload !== "function") return;
|
|
@@ -235,13 +253,26 @@ function preloadImageResource(input) {
|
|
|
235
253
|
* Generate a srcSet string for responsive images.
|
|
236
254
|
*
|
|
237
255
|
* Each width points to the `/_next/image` optimization endpoint so the
|
|
238
|
-
* server can resize and transcode the image.
|
|
239
|
-
* <= 2x the original image width to avoid pointless upscaling.
|
|
256
|
+
* server can resize and transcode the image.
|
|
240
257
|
*/
|
|
241
|
-
function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
258
|
+
function getImageWidths(width) {
|
|
259
|
+
return [...new Set([width, width * 2].map((targetWidth) => ALL_IMAGE_WIDTHS.find((configuredWidth) => configuredWidth >= targetWidth) ?? ALL_IMAGE_WIDTHS[ALL_IMAGE_WIDTHS.length - 1]))];
|
|
260
|
+
}
|
|
261
|
+
function generateImageAttributes(src, width, quality = 75, sizes) {
|
|
262
|
+
if (sizes) {
|
|
263
|
+
const viewportPercentages = Array.from(sizes.matchAll(/(^|\s)(1?\d?\d)vw/g), (match) => Number.parseInt(match[2], 10));
|
|
264
|
+
const minimumWidth = viewportPercentages.length > 0 ? RESPONSIVE_WIDTHS[0] * (Math.min(...viewportPercentages) * .01) : 0;
|
|
265
|
+
const candidates = ALL_IMAGE_WIDTHS.filter((candidateWidth) => candidateWidth >= minimumWidth);
|
|
266
|
+
return {
|
|
267
|
+
src: imageOptimizationUrl(src, candidates[candidates.length - 1], quality),
|
|
268
|
+
srcSet: candidates.map((candidateWidth) => `${imageOptimizationUrl(src, candidateWidth, quality)} ${candidateWidth}w`).join(", ")
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
const widths = getImageWidths(width);
|
|
272
|
+
return {
|
|
273
|
+
src: imageOptimizationUrl(src, widths[widths.length - 1], quality),
|
|
274
|
+
srcSet: widths.map((candidateWidth, index) => `${imageOptimizationUrl(src, candidateWidth, quality)} ${index + 1}x`).join(", ")
|
|
275
|
+
};
|
|
245
276
|
}
|
|
246
277
|
const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill, preload, priority, quality, placeholder, blurDataURL, loader, sizes, className, style, onLoad, onLoadingComplete, onError, unoptimized: _unoptimized, overrideSrc, loading, ...rest }, ref) {
|
|
247
278
|
const lastLoadedSrcRef = useRef(void 0);
|
|
@@ -327,7 +358,7 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
|
|
|
327
358
|
lastErrorSrcRef.current = src;
|
|
328
359
|
markBlurComplete();
|
|
329
360
|
} : void 0;
|
|
330
|
-
if (_unoptimized === true) {
|
|
361
|
+
if (_unoptimized === true || __globallyUnoptimized) {
|
|
331
362
|
const renderedSrc = overrideSrc || src;
|
|
332
363
|
const sanitizedBlur = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
333
364
|
const blurStyle = !blurComplete && placeholder === "blur" && sanitizedBlur ? {
|
|
@@ -457,8 +488,9 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
|
|
|
457
488
|
}
|
|
458
489
|
const imgQuality = quality ?? 75;
|
|
459
490
|
const skipOptimization = isSvgUrl(src) && !__dangerouslyAllowSVG;
|
|
460
|
-
const
|
|
461
|
-
const
|
|
491
|
+
const optimizedAttributes = imgWidth && !fill && !skipOptimization ? generateImageAttributes(src, imgWidth, imgQuality, sizes) : void 0;
|
|
492
|
+
const srcSet = optimizedAttributes ? optimizedAttributes.srcSet : imgWidth && !fill ? RESPONSIVE_WIDTHS.filter((w) => w <= imgWidth * 2).map((w) => `${src} ${w}w`).join(", ") || `${src} ${imgWidth}w` : void 0;
|
|
493
|
+
const optimizedSrc = skipOptimization ? src : optimizedAttributes ? optimizedAttributes.src : imageOptimizationUrl(src, RESPONSIVE_WIDTHS[0], imgQuality);
|
|
462
494
|
const sanitizedLocalBlur = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
463
495
|
const blurStyle = !blurComplete && placeholder === "blur" && sanitizedLocalBlur ? {
|
|
464
496
|
backgroundImage: `url(${sanitizedLocalBlur})`,
|
|
@@ -510,7 +542,7 @@ function getImageProps(props) {
|
|
|
510
542
|
});
|
|
511
543
|
const shouldPreload = _preload === true || priority === true;
|
|
512
544
|
const effectiveLoader = resolveEffectiveLoader(loader);
|
|
513
|
-
if (_unoptimized === true) {
|
|
545
|
+
if (_unoptimized === true || __globallyUnoptimized) {
|
|
514
546
|
const renderedSrc = overrideSrc || src;
|
|
515
547
|
const sanitizedBlurURL = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
516
548
|
const blurStyle = placeholder === "blur" && sanitizedBlurURL ? {
|
|
@@ -552,8 +584,9 @@ function getImageProps(props) {
|
|
|
552
584
|
quality: imgQuality
|
|
553
585
|
}) : src;
|
|
554
586
|
const skipOpt = isSvgUrl(resolvedSrc) && !__dangerouslyAllowSVG || blockedInProd || !!effectiveLoader || isRemoteUrl(resolvedSrc);
|
|
555
|
-
const
|
|
556
|
-
const
|
|
587
|
+
const optimizedAttributes = imgWidth && !fill && !skipOpt ? generateImageAttributes(resolvedSrc, imgWidth, imgQuality, sizes) : null;
|
|
588
|
+
const optimizedSrc = skipOpt ? resolvedSrc : optimizedAttributes ? optimizedAttributes.src : imageOptimizationUrl(resolvedSrc, RESPONSIVE_WIDTHS[0], imgQuality);
|
|
589
|
+
const srcSet = optimizedAttributes?.srcSet;
|
|
557
590
|
const sanitizedBlurURL = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
|
|
558
591
|
const blurStyle = placeholder === "blur" && sanitizedBlurURL ? {
|
|
559
592
|
backgroundImage: `url(${sanitizedBlurURL})`,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { VinextLinkPrefetchRoute } from "../../client/vinext-next-data.js";
|
|
2
|
+
import { getPagesRouterComponentsMap } from "./pages-router-components.js";
|
|
2
3
|
|
|
3
4
|
//#region src/shims/internal/app-route-detection.d.ts
|
|
4
5
|
declare global {
|
|
@@ -6,22 +7,6 @@ declare global {
|
|
|
6
7
|
__VINEXT_LINK_PREFETCH_ROUTES__?: VinextLinkPrefetchRoute[];
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
/**
|
|
10
|
-
* Pages Router `components` map shape. Next.js types this loosely (route
|
|
11
|
-
* pattern → `PrivateRouteInfo`), but for the App Router-detected case it
|
|
12
|
-
* stores `{ __appRouter: true }` as a marker (see Next.js source link above).
|
|
13
|
-
* Vinext only writes the marker variant; reads are by test code that checks
|
|
14
|
-
* for `__appRouter: true`.
|
|
15
|
-
*/
|
|
16
|
-
type PagesRouterComponentsMap = Record<string, {
|
|
17
|
-
__appRouter: true;
|
|
18
|
-
} | Record<string, unknown>>;
|
|
19
|
-
/**
|
|
20
|
-
* Get-or-create the Pages Router `components` map. Returns the same object
|
|
21
|
-
* on every call so `router.components` and `window.next.router.components`
|
|
22
|
-
* have referential identity.
|
|
23
|
-
*/
|
|
24
|
-
declare function getPagesRouterComponentsMap(): PagesRouterComponentsMap;
|
|
25
10
|
/**
|
|
26
11
|
* Record `components[pathname] = { __appRouter: true }` on the shared
|
|
27
12
|
* Pages Router map when the href matches an App Router route. No-op when the
|
|
@@ -34,6 +19,6 @@ declare function getPagesRouterComponentsMap(): PagesRouterComponentsMap;
|
|
|
34
19
|
* first (e.g. `link.tsx` normalises to match `trailingSlash` config before
|
|
35
20
|
* calling, while `router.prefetch()` passes the raw user-supplied URL).
|
|
36
21
|
*/
|
|
37
|
-
declare function markAppRouteDetectedOnPrefetch(href: string, basePath: string): void
|
|
22
|
+
declare function markAppRouteDetectedOnPrefetch(href: string, basePath: string): Promise<void>;
|
|
38
23
|
//#endregion
|
|
39
24
|
export { getPagesRouterComponentsMap, markAppRouteDetectedOnPrefetch };
|