vinext 0.1.4 → 0.1.5

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.
Files changed (126) hide show
  1. package/dist/build/css-url-assets.d.ts +1 -1
  2. package/dist/build/css-url-assets.js +9 -7
  3. package/dist/build/prerender.js +2 -1
  4. package/dist/cache/cache-adapters-virtual.js +1 -1
  5. package/dist/cloudflare/src/cache/kv-data-adapter.runtime.d.ts +1 -1
  6. package/dist/entries/app-rsc-entry.js +24 -20
  7. package/dist/entries/pages-server-entry.js +2 -1
  8. package/dist/index.js +187 -146
  9. package/dist/plugins/css-data-url.js +30 -26
  10. package/dist/plugins/extensionless-dynamic-import.js +27 -24
  11. package/dist/plugins/import-meta-url.js +21 -15
  12. package/dist/plugins/instrumentation-client.js +1 -1
  13. package/dist/plugins/middleware-server-only.js +7 -6
  14. package/dist/plugins/og-assets.js +48 -46
  15. package/dist/plugins/optimize-imports.js +9 -3
  16. package/dist/plugins/remove-console.d.ts +7 -1
  17. package/dist/plugins/remove-console.js +4 -1
  18. package/dist/plugins/require-context.js +21 -20
  19. package/dist/plugins/strip-server-exports.d.ts +7 -1
  20. package/dist/plugins/strip-server-exports.js +4 -1
  21. package/dist/server/app-bfcache-identity.d.ts +26 -0
  22. package/dist/server/app-bfcache-identity.js +127 -0
  23. package/dist/server/app-browser-entry.js +14 -11
  24. package/dist/server/app-browser-navigation-controller.js +1 -1
  25. package/dist/server/app-browser-state.d.ts +2 -21
  26. package/dist/server/app-browser-state.js +4 -128
  27. package/dist/server/app-browser-stream.js +1 -1
  28. package/dist/server/app-browser-visible-commit.js +3 -2
  29. package/dist/server/app-fallback-renderer.d.ts +1 -1
  30. package/dist/server/app-layout-param-observation.d.ts +1 -1
  31. package/dist/server/app-layout-param-observation.js +1 -1
  32. package/dist/server/app-middleware.js +2 -1
  33. package/dist/server/app-page-boundary-render.d.ts +1 -1
  34. package/dist/server/app-page-boundary.js +1 -1
  35. package/dist/server/app-page-cache-finalizer.d.ts +62 -0
  36. package/dist/server/app-page-cache-finalizer.js +122 -0
  37. package/dist/server/app-page-cache-render.d.ts +2 -2
  38. package/dist/server/app-page-cache-render.js +1 -1
  39. package/dist/server/app-page-cache.d.ts +2 -53
  40. package/dist/server/app-page-cache.js +5 -131
  41. package/dist/server/app-page-dispatch.d.ts +2 -2
  42. package/dist/server/app-page-dispatch.js +10 -8
  43. package/dist/server/app-page-probe.js +3 -2
  44. package/dist/server/app-page-render-observation.js +2 -2
  45. package/dist/server/app-page-render.d.ts +3 -3
  46. package/dist/server/app-page-render.js +3 -2
  47. package/dist/server/app-page-stream.d.ts +2 -9
  48. package/dist/server/app-page-stream.js +1 -35
  49. package/dist/server/app-request-context.d.ts +1 -2
  50. package/dist/server/app-request-context.js +2 -1
  51. package/dist/server/app-route-handler-dispatch.js +3 -2
  52. package/dist/server/app-route-handler-execution.d.ts +1 -1
  53. package/dist/server/app-route-handler-execution.js +1 -1
  54. package/dist/server/app-route-handler-response.d.ts +1 -1
  55. package/dist/server/app-router-entry.js +2 -1
  56. package/dist/server/app-rsc-handler.js +22 -16
  57. package/dist/server/app-rsc-response-finalizer.js +1 -1
  58. package/dist/server/app-server-action-execution.d.ts +1 -1
  59. package/dist/server/app-server-action-execution.js +5 -4
  60. package/dist/server/app-ssr-entry.d.ts +1 -1
  61. package/dist/server/app-ssr-entry.js +11 -9
  62. package/dist/server/app-ssr-router-instance.d.ts +6 -0
  63. package/dist/server/app-ssr-router-instance.js +24 -0
  64. package/dist/server/app-ssr-stream.js +1 -1
  65. package/dist/server/artifact-compatibility.js +1 -1
  66. package/dist/server/client-reuse-manifest.js +1 -1
  67. package/dist/server/defer-until-stream-consumed.d.ts +7 -0
  68. package/dist/server/defer-until-stream-consumed.js +34 -0
  69. package/dist/server/dev-server.js +1 -1
  70. package/dist/server/instrumentation.js +1 -1
  71. package/dist/server/isr-cache.d.ts +1 -1
  72. package/dist/server/isr-cache.js +1 -1
  73. package/dist/server/isr-decision.d.ts +1 -1
  74. package/dist/server/middleware-matcher.js +8 -6
  75. package/dist/server/middleware-runtime.js +2 -2
  76. package/dist/server/open-redirect.d.ts +12 -0
  77. package/dist/server/open-redirect.js +21 -0
  78. package/dist/server/pages-page-data.d.ts +1 -1
  79. package/dist/server/pages-page-response.d.ts +1 -1
  80. package/dist/server/pages-page-response.js +2 -2
  81. package/dist/server/prod-server.js +2 -1
  82. package/dist/server/request-pipeline.d.ts +1 -24
  83. package/dist/server/request-pipeline.js +1 -33
  84. package/dist/server/seed-cache.d.ts +1 -1
  85. package/dist/shims/cache-handler.d.ts +106 -0
  86. package/dist/shims/cache-handler.js +176 -0
  87. package/dist/shims/cache-request-state.d.ts +47 -0
  88. package/dist/shims/cache-request-state.js +126 -0
  89. package/dist/shims/cache-runtime.d.ts +2 -2
  90. package/dist/shims/cache-runtime.js +3 -14
  91. package/dist/shims/cache.d.ts +3 -231
  92. package/dist/shims/cache.js +17 -383
  93. package/dist/shims/cdn-cache.d.ts +1 -1
  94. package/dist/shims/cdn-cache.js +1 -1
  95. package/dist/shims/error-boundary-navigation.d.ts +7 -0
  96. package/dist/shims/error-boundary-navigation.js +44 -0
  97. package/dist/shims/error-boundary.js +10 -8
  98. package/dist/shims/error.js +2 -1
  99. package/dist/shims/fetch-cache.js +1 -1
  100. package/dist/shims/form.js +1 -1
  101. package/dist/shims/image.js +67 -9
  102. package/dist/shims/internal/app-page-props-cache-key.d.ts +5 -0
  103. package/dist/shims/internal/app-page-props-cache-key.js +16 -0
  104. package/dist/shims/internal/navigation-untracked.js +2 -1
  105. package/dist/shims/layout-segment-context.d.ts +1 -1
  106. package/dist/shims/layout-segment-context.js +2 -1
  107. package/dist/shims/link.js +2 -2
  108. package/dist/shims/navigation-context-state.d.ts +40 -0
  109. package/dist/shims/navigation-context-state.js +116 -0
  110. package/dist/shims/navigation-errors.d.ts +55 -0
  111. package/dist/shims/navigation-errors.js +110 -0
  112. package/dist/shims/navigation-server.d.ts +3 -0
  113. package/dist/shims/navigation-server.js +3 -0
  114. package/dist/shims/navigation-state.d.ts +1 -2
  115. package/dist/shims/navigation-state.js +2 -1
  116. package/dist/shims/navigation.d.ts +3 -291
  117. package/dist/shims/navigation.js +14 -445
  118. package/dist/shims/navigation.react-server.d.ts +2 -2
  119. package/dist/shims/navigation.react-server.js +3 -1
  120. package/dist/shims/request-state-types.d.ts +3 -3
  121. package/dist/shims/script.js +1 -1
  122. package/dist/shims/slot.js +3 -1
  123. package/dist/shims/unified-request-context.d.ts +2 -2
  124. package/dist/utils/virtual-module.d.ts +5 -0
  125. package/dist/utils/virtual-module.js +0 -0
  126. package/package.json +5 -1
@@ -243,7 +243,7 @@ function generateSrcSet(src, originalWidth, quality = 75) {
243
243
  if (widths.length === 0) return `${imageOptimizationUrl(src, originalWidth, quality)} ${originalWidth}w`;
244
244
  return widths.map((w) => `${imageOptimizationUrl(src, w, quality)} ${w}w`).join(", ");
245
245
  }
246
- 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: _overrideSrc, loading, ...rest }, ref) {
246
+ 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
247
  const lastLoadedSrcRef = useRef(void 0);
248
248
  const lastErrorSrcRef = useRef(void 0);
249
249
  const didInsertRef = useRef(false);
@@ -326,6 +326,40 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
326
326
  lastErrorSrcRef.current = src;
327
327
  markBlurComplete();
328
328
  } : void 0;
329
+ if (_unoptimized === true) {
330
+ const renderedSrc = overrideSrc || src;
331
+ const sanitizedBlur = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
332
+ const blurStyle = !blurComplete && placeholder === "blur" && sanitizedBlur ? {
333
+ backgroundImage: `url(${sanitizedBlur})`,
334
+ backgroundSize: "cover",
335
+ backgroundRepeat: "no-repeat",
336
+ backgroundPosition: "center"
337
+ } : void 0;
338
+ preloadImageResource({
339
+ shouldPreload,
340
+ src: renderedSrc,
341
+ fetchPriority: priorityFetchPriority
342
+ });
343
+ return /* @__PURE__ */ jsx("img", {
344
+ ref: mergedRef,
345
+ src: renderedSrc,
346
+ alt,
347
+ width: fill ? void 0 : imgWidth,
348
+ height: fill ? void 0 : imgHeight,
349
+ loading: imageLoading,
350
+ fetchPriority: priorityFetchPriority,
351
+ decoding: "async",
352
+ className,
353
+ "data-nimg": fill ? "fill" : "1",
354
+ onLoad: handleLoad,
355
+ onError: handleError,
356
+ style: fill ? getFillStyle(style, blurStyle) : {
357
+ ...blurStyle,
358
+ ...style
359
+ },
360
+ ...rest
361
+ });
362
+ }
329
363
  if (loader) {
330
364
  const resolvedSrc = loader({
331
365
  src,
@@ -371,11 +405,11 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
371
405
  } : void 0;
372
406
  const bg = showBlur ? `url(${sanitizedBlur})` : void 0;
373
407
  if (fill) {
374
- const fillSizes = sizes ?? "100vw";
408
+ const imageSizes = sizes ?? "100vw";
375
409
  preloadImageResource({
376
410
  shouldPreload,
377
411
  src,
378
- sizes: fillSizes,
412
+ sizes: imageSizes,
379
413
  fetchPriority: priorityFetchPriority
380
414
  });
381
415
  return /* @__PURE__ */ jsx("img", {
@@ -385,7 +419,7 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
385
419
  loading: imageLoading,
386
420
  fetchPriority: priorityFetchPriority,
387
421
  decoding: "async",
388
- sizes: fillSizes,
422
+ sizes: imageSizes,
389
423
  className,
390
424
  "data-nimg": "fill",
391
425
  onLoad: handleLoad,
@@ -421,8 +455,7 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
421
455
  }
422
456
  }
423
457
  const imgQuality = quality ?? 75;
424
- const isSvg = isSvgUrl(src);
425
- const skipOptimization = _unoptimized === true || isSvg && !__dangerouslyAllowSVG;
458
+ const skipOptimization = isSvgUrl(src) && !__dangerouslyAllowSVG;
426
459
  const srcSet = imgWidth && !fill && !skipOptimization ? generateSrcSet(src, imgWidth, imgQuality) : imgWidth && !fill ? RESPONSIVE_WIDTHS.filter((w) => w <= imgWidth * 2).map((w) => `${src} ${w}w`).join(", ") || `${src} ${imgWidth}w` : void 0;
427
460
  const optimizedSrc = skipOptimization ? src : imgWidth ? imageOptimizationUrl(src, imgWidth, imgQuality) : imageOptimizationUrl(src, RESPONSIVE_WIDTHS[0], imgQuality);
428
461
  const sanitizedLocalBlur = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
@@ -467,7 +500,7 @@ const Image = forwardRef(function Image({ src: srcProp, alt, width, height, fill
467
500
  * Returns the props that would be passed to the underlying <img> element.
468
501
  */
469
502
  function getImageProps(props) {
470
- const { src: srcProp, alt, width, height, fill, preload: _preload, priority, quality: _quality, placeholder, blurDataURL: blurDataURLProp, loader, sizes, className, style, onLoad: _onLoad, onLoadingComplete: _onLoadingComplete, unoptimized: _unoptimized, overrideSrc: _overrideSrc, loading, ...rest } = props;
503
+ const { src: srcProp, alt, width, height, fill, preload: _preload, priority, quality: _quality, placeholder, blurDataURL: blurDataURLProp, loader, sizes, className, style, onLoad: _onLoad, onLoadingComplete: _onLoadingComplete, unoptimized: _unoptimized, overrideSrc, loading, ...rest } = props;
471
504
  const { src, width: imgWidth, height: imgHeight, blurDataURL: imgBlurDataURL } = resolveImageSource({
472
505
  src: srcProp,
473
506
  width,
@@ -475,6 +508,32 @@ function getImageProps(props) {
475
508
  blurDataURL: blurDataURLProp
476
509
  });
477
510
  const shouldPreload = _preload === true || priority === true;
511
+ if (_unoptimized === true) {
512
+ const renderedSrc = overrideSrc || src;
513
+ const sanitizedBlurURL = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
514
+ const blurStyle = placeholder === "blur" && sanitizedBlurURL ? {
515
+ backgroundImage: `url(${sanitizedBlurURL})`,
516
+ backgroundSize: "cover",
517
+ backgroundRepeat: "no-repeat",
518
+ backgroundPosition: "center"
519
+ } : void 0;
520
+ return { props: {
521
+ src: renderedSrc,
522
+ alt,
523
+ width: fill ? void 0 : imgWidth,
524
+ height: fill ? void 0 : imgHeight,
525
+ loading: priority ? "eager" : shouldPreload ? loading : loading ?? "lazy",
526
+ fetchPriority: priority ? "high" : void 0,
527
+ decoding: "async",
528
+ className,
529
+ "data-nimg": fill ? "fill" : "1",
530
+ style: fill ? getFillStyle(style, blurStyle) : {
531
+ ...blurStyle,
532
+ ...style
533
+ },
534
+ ...rest
535
+ } };
536
+ }
478
537
  let blockedInProd = false;
479
538
  if (isRemoteUrl(src)) {
480
539
  const validation = validateRemoteUrl(src);
@@ -490,8 +549,7 @@ function getImageProps(props) {
490
549
  width: imgWidth ?? 0,
491
550
  quality: imgQuality
492
551
  }) : src;
493
- const isSvg = isSvgUrl(resolvedSrc);
494
- const skipOpt = _unoptimized === true || isSvg && !__dangerouslyAllowSVG || blockedInProd || !!loader || isRemoteUrl(resolvedSrc);
552
+ const skipOpt = isSvgUrl(resolvedSrc) && !__dangerouslyAllowSVG || blockedInProd || !!loader || isRemoteUrl(resolvedSrc);
495
553
  const optimizedSrc = skipOpt ? resolvedSrc : imgWidth ? imageOptimizationUrl(resolvedSrc, imgWidth, imgQuality) : imageOptimizationUrl(resolvedSrc, RESPONSIVE_WIDTHS[0], imgQuality);
496
554
  const srcSet = imgWidth && !fill && !isRemoteUrl(resolvedSrc) && !loader && !skipOpt ? generateSrcSet(resolvedSrc, imgWidth, imgQuality) : void 0;
497
555
  const sanitizedBlurURL = imgBlurDataURL ? sanitizeBlurDataURL(imgBlurDataURL) : void 0;
@@ -0,0 +1,5 @@
1
+ //#region src/shims/internal/app-page-props-cache-key.d.ts
2
+ declare function markAppPagePropsForUseCache<T extends object>(props: T): T;
3
+ declare function isMarkedAppPagePropsObject(value: object): boolean;
4
+ //#endregion
5
+ export { isMarkedAppPagePropsObject, markAppPagePropsForUseCache };
@@ -0,0 +1,16 @@
1
+ //#region src/shims/internal/app-page-props-cache-key.ts
2
+ const APP_PAGE_PROPS_CACHE_KEY_MARKER = Symbol.for("vinext.appPagePropsCacheKeyMarker");
3
+ function markAppPagePropsForUseCache(props) {
4
+ Object.defineProperty(props, APP_PAGE_PROPS_CACHE_KEY_MARKER, {
5
+ configurable: false,
6
+ enumerable: false,
7
+ value: true,
8
+ writable: false
9
+ });
10
+ return props;
11
+ }
12
+ function isMarkedAppPagePropsObject(value) {
13
+ return Reflect.get(value, APP_PAGE_PROPS_CACHE_KEY_MARKER) === true;
14
+ }
15
+ //#endregion
16
+ export { isMarkedAppPagePropsObject, markAppPagePropsForUseCache };
@@ -1,5 +1,6 @@
1
+ import { getNavigationContext } from "../navigation-context-state.js";
1
2
  import { getPagesNavigationContext } from "./pages-router-accessor.js";
2
- import { getClientNavigationState, getNavigationContext, useClientNavigationRenderSnapshot } from "../navigation.js";
3
+ import { getClientNavigationState, useClientNavigationRenderSnapshot } from "../navigation.js";
3
4
  //#region src/shims/internal/navigation-untracked.ts
4
5
  /**
5
6
  * Internal navigation-untracked pathname hook.
@@ -1,4 +1,4 @@
1
- import { SegmentMap } from "./navigation.js";
1
+ import { SegmentMap } from "./navigation-context-state.js";
2
2
  import { ReactNode } from "react";
3
3
 
4
4
  //#region src/shims/layout-segment-context.d.ts
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- import { getLayoutSegmentContext } from "./navigation.js";
2
+ import { getLayoutSegmentContext } from "./navigation-context-state.js";
3
+ import "./navigation-server.js";
3
4
  import { createElement } from "react";
4
5
  //#region src/shims/layout-segment-context.tsx
5
6
  /**
@@ -14,10 +14,10 @@ import { markAppRouteDetectedOnPrefetch } from "./internal/app-route-detection.j
14
14
  import { isAbsoluteOrProtocolRelativeUrl, normalizePathTrailingSlash, toBrowserNavigationHref, toSameOriginAppPath, withBasePath } from "./url-utils.js";
15
15
  import { getCurrentBrowserLocale } from "./client-locale.js";
16
16
  import { getCurrentRoutePathnameForWarning } from "./internal/route-pattern-for-warning.js";
17
- import { getNavigationRuntime, hasAppNavigationRuntime, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
18
17
  import { createRscRequestHeaders, createRscRequestUrl, stripRscCacheBustingSearchParam, stripRscSuffix } from "../server/app-rsc-cache-busting.js";
19
- import { getMountedSlotsHeader, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, navigateClientSide, prefetchRscResponse } from "./navigation.js";
18
+ import { getNavigationRuntime, hasAppNavigationRuntime, registerNavigationRuntimeFunctions } from "../client/navigation-runtime.js";
20
19
  import { navigatePagesRouterLinkWithFallback, resolvePagesRouterQueryOnlyHref } from "../client/pages-router-link-navigation.js";
20
+ import { getMountedSlotsHeader, getPrefetchCache, getPrefetchInterceptionContext, getPrefetchedUrls, hasPrefetchCacheEntryForNavigation, navigateClientSide, prefetchRscResponse } from "./navigation.js";
21
21
  import { getI18nContext } from "./i18n-context.js";
22
22
  import { canLinkIntentPrefetch, canLinkPrefetch, getLinkPrefetchHref } from "./link-prefetch.js";
23
23
  import { clearLinkForCurrentNavigation, notifyLinkNavigationStart, setLinkForCurrentNavigation } from "./internal/link-status-registry.js";
@@ -0,0 +1,40 @@
1
+ import * as React$1 from "react";
2
+
3
+ //#region src/shims/navigation-context-state.d.ts
4
+ /**
5
+ * Map of parallel route key to child segments below the current layout.
6
+ * The "children" key is always present.
7
+ */
8
+ type SegmentMap = Readonly<Record<string, string[]>> & {
9
+ readonly children: string[];
10
+ };
11
+ type NavigationContext = {
12
+ pathname: string;
13
+ searchParams: URLSearchParams;
14
+ params: Record<string, string | string[]>;
15
+ };
16
+ declare const ServerInsertedHTMLContext: React$1.Context<((callback: () => unknown) => void) | null> | null;
17
+ declare function getLayoutSegmentContext(): React$1.Context<SegmentMap> | null;
18
+ declare function getBfcacheIdMapContext(): React$1.Context<Readonly<Record<string, string>> | null> | null;
19
+ declare function getBfcacheSegmentIdContext(): React$1.Context<string | null> | null;
20
+ type NavigationStateAccessors = {
21
+ getServerContext: () => NavigationContext | null;
22
+ setServerContext: (context: NavigationContext | null) => void;
23
+ getInsertedHTMLCallbacks: () => Array<() => unknown>;
24
+ clearInsertedHTMLCallbacks: () => void;
25
+ };
26
+ declare const GLOBAL_ACCESSORS_KEY: unique symbol;
27
+ declare function clearClientHydrationContext(): void;
28
+ /**
29
+ * Register request-scoped accessors supplied by navigation-state.ts.
30
+ * The global accessor key also bridges separate Vite module instances.
31
+ */
32
+ declare function _registerStateAccessors(accessors: NavigationStateAccessors): void;
33
+ declare function getNavigationContext(): NavigationContext | null;
34
+ declare function setNavigationContext(context: NavigationContext | null): void;
35
+ declare function registerServerInsertedHTMLCallback(callback: () => unknown): void;
36
+ declare function flushServerInsertedHTML(): unknown[];
37
+ declare function renderServerInsertedHTML(): unknown[];
38
+ declare function clearServerInsertedHTML(): void;
39
+ //#endregion
40
+ export { GLOBAL_ACCESSORS_KEY, NavigationContext, NavigationStateAccessors, SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext };
@@ -0,0 +1,116 @@
1
+ import * as React$1 from "react";
2
+ //#region src/shims/navigation-context-state.ts
3
+ const LAYOUT_SEGMENT_CONTEXT_KEY = Symbol.for("vinext.layoutSegmentContext");
4
+ const SERVER_INSERTED_HTML_CONTEXT_KEY = Symbol.for("vinext.serverInsertedHTMLContext");
5
+ const BFCACHE_ID_MAP_CONTEXT_KEY = Symbol.for("vinext.bfcacheIdMapContext");
6
+ const BFCACHE_SEGMENT_ID_CONTEXT_KEY = Symbol.for("vinext.bfcacheSegmentIdContext");
7
+ const GLOBAL_HYDRATION_CONTEXT_KEY = Symbol.for("vinext.navigation.clientHydrationContext");
8
+ const NAVIGATION_FALLBACK_STATE_KEY = Symbol.for("vinext.navigation.fallback");
9
+ function createContextIfAvailable(defaultValue) {
10
+ return typeof React$1.createContext === "function" ? React$1.createContext(defaultValue) : null;
11
+ }
12
+ function getServerInsertedHTMLContext() {
13
+ const globalState = globalThis;
14
+ if (!globalState[SERVER_INSERTED_HTML_CONTEXT_KEY]) globalState[SERVER_INSERTED_HTML_CONTEXT_KEY] = createContextIfAvailable(null);
15
+ return globalState[SERVER_INSERTED_HTML_CONTEXT_KEY] ?? null;
16
+ }
17
+ const ServerInsertedHTMLContext = getServerInsertedHTMLContext();
18
+ function getLayoutSegmentContext() {
19
+ const globalState = globalThis;
20
+ if (!globalState[LAYOUT_SEGMENT_CONTEXT_KEY]) globalState[LAYOUT_SEGMENT_CONTEXT_KEY] = createContextIfAvailable({ children: [] });
21
+ return globalState[LAYOUT_SEGMENT_CONTEXT_KEY] ?? null;
22
+ }
23
+ function getBfcacheIdMapContext() {
24
+ const globalState = globalThis;
25
+ if (!globalState[BFCACHE_ID_MAP_CONTEXT_KEY]) globalState[BFCACHE_ID_MAP_CONTEXT_KEY] = createContextIfAvailable(null);
26
+ return globalState[BFCACHE_ID_MAP_CONTEXT_KEY] ?? null;
27
+ }
28
+ function getBfcacheSegmentIdContext() {
29
+ const globalState = globalThis;
30
+ if (!globalState[BFCACHE_SEGMENT_ID_CONTEXT_KEY]) globalState[BFCACHE_SEGMENT_ID_CONTEXT_KEY] = createContextIfAvailable(null);
31
+ return globalState[BFCACHE_SEGMENT_ID_CONTEXT_KEY] ?? null;
32
+ }
33
+ const GLOBAL_ACCESSORS_KEY = Symbol.for("vinext.navigation.globalAccessors");
34
+ function getFallbackState() {
35
+ const globalState = globalThis;
36
+ return globalState[NAVIGATION_FALLBACK_STATE_KEY] ??= {
37
+ serverContext: null,
38
+ serverInsertedHTMLCallbacks: []
39
+ };
40
+ }
41
+ function getGlobalAccessors() {
42
+ return globalThis[GLOBAL_ACCESSORS_KEY];
43
+ }
44
+ function getClientHydrationContext() {
45
+ const globalState = globalThis;
46
+ if (Object.prototype.hasOwnProperty.call(globalState, GLOBAL_HYDRATION_CONTEXT_KEY)) return globalState[GLOBAL_HYDRATION_CONTEXT_KEY] ?? null;
47
+ }
48
+ function setClientHydrationContext(context) {
49
+ globalThis[GLOBAL_HYDRATION_CONTEXT_KEY] = context;
50
+ }
51
+ function clearClientHydrationContext() {
52
+ if (typeof window !== "undefined") setClientHydrationContext(null);
53
+ }
54
+ let getServerContext = () => {
55
+ if (typeof window !== "undefined") {
56
+ const hydrationContext = getClientHydrationContext();
57
+ return hydrationContext !== void 0 ? hydrationContext : getFallbackState().serverContext;
58
+ }
59
+ return getGlobalAccessors()?.getServerContext() ?? getFallbackState().serverContext;
60
+ };
61
+ let setServerContext = (context) => {
62
+ if (typeof window !== "undefined") {
63
+ getFallbackState().serverContext = context;
64
+ setClientHydrationContext(context);
65
+ return;
66
+ }
67
+ const accessors = getGlobalAccessors();
68
+ if (accessors) accessors.setServerContext(context);
69
+ else getFallbackState().serverContext = context;
70
+ };
71
+ let getInsertedHTMLCallbacks = () => getGlobalAccessors()?.getInsertedHTMLCallbacks() ?? getFallbackState().serverInsertedHTMLCallbacks;
72
+ let clearInsertedHTMLCallbacks = () => {
73
+ const accessors = getGlobalAccessors();
74
+ if (accessors) accessors.clearInsertedHTMLCallbacks();
75
+ else getFallbackState().serverInsertedHTMLCallbacks = [];
76
+ };
77
+ /**
78
+ * Register request-scoped accessors supplied by navigation-state.ts.
79
+ * The global accessor key also bridges separate Vite module instances.
80
+ */
81
+ function _registerStateAccessors(accessors) {
82
+ getServerContext = accessors.getServerContext;
83
+ setServerContext = accessors.setServerContext;
84
+ getInsertedHTMLCallbacks = accessors.getInsertedHTMLCallbacks;
85
+ clearInsertedHTMLCallbacks = accessors.clearInsertedHTMLCallbacks;
86
+ }
87
+ function getNavigationContext() {
88
+ return getServerContext();
89
+ }
90
+ function setNavigationContext(context) {
91
+ setServerContext(context);
92
+ }
93
+ function registerServerInsertedHTMLCallback(callback) {
94
+ getInsertedHTMLCallbacks().push(callback);
95
+ }
96
+ function renderInsertedHTMLCallbacks(clear) {
97
+ const callbacks = getInsertedHTMLCallbacks();
98
+ const results = [];
99
+ for (const callback of callbacks) try {
100
+ const result = callback();
101
+ if (result != null) results.push(result);
102
+ } catch {}
103
+ if (clear) callbacks.length = 0;
104
+ return results;
105
+ }
106
+ function flushServerInsertedHTML() {
107
+ return renderInsertedHTMLCallbacks(true);
108
+ }
109
+ function renderServerInsertedHTML() {
110
+ return renderInsertedHTMLCallbacks(false);
111
+ }
112
+ function clearServerInsertedHTML() {
113
+ clearInsertedHTMLCallbacks();
114
+ }
115
+ //#endregion
116
+ export { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext };
@@ -0,0 +1,55 @@
1
+ //#region src/shims/navigation-errors.d.ts
2
+ /**
3
+ * Server-safe navigation control-flow errors and predicates.
4
+ *
5
+ * This module intentionally has no React or browser-runtime dependencies so
6
+ * RSC, SSR, and the public next/navigation shim can share one implementation.
7
+ */
8
+ declare const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
9
+ declare function isHTTPAccessFallbackError(error: unknown): boolean;
10
+ declare function getAccessFallbackHTTPStatus(error: unknown): number;
11
+ declare enum RedirectType {
12
+ push = "push",
13
+ replace = "replace"
14
+ }
15
+ /**
16
+ * The omitted redirect type is resolved by the catch site: push for Server
17
+ * Actions and replace for ordinary SSR/RSC rendering.
18
+ */
19
+ declare function redirect(url: string, type?: "replace" | "push" | RedirectType): never;
20
+ declare function permanentRedirect(url: string, type?: "replace" | "push" | RedirectType): never;
21
+ declare function notFound(): never;
22
+ declare function forbidden(): never;
23
+ declare function unauthorized(): never;
24
+ type RedirectErrorShape = Error & {
25
+ digest: string;
26
+ };
27
+ /**
28
+ * vinext accepts its three-part redirect digest and Next.js's five-part form.
29
+ * A prefix check is deliberate because vinext permits an empty redirect type.
30
+ */
31
+ declare function isRedirectError(error: unknown): error is RedirectErrorShape;
32
+ declare function decodeRedirectError(digest: string): {
33
+ url: string;
34
+ type: "push" | "replace";
35
+ } | null;
36
+ declare function isNextRouterError(error: unknown): boolean;
37
+ declare class BailoutToCSRError extends Error {
38
+ readonly digest = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
39
+ readonly reason: string;
40
+ constructor(reason: string);
41
+ }
42
+ declare function isBailoutToCSRError(error: unknown): error is BailoutToCSRError;
43
+ declare class DynamicServerError extends Error {
44
+ readonly digest = "DYNAMIC_SERVER_USAGE";
45
+ readonly description: string;
46
+ constructor(description: string);
47
+ }
48
+ declare function isDynamicServerError(error: unknown): error is DynamicServerError;
49
+ /**
50
+ * Rethrow framework control-flow signals before user error handling consumes
51
+ * them. This covers the categories vinext can currently produce.
52
+ */
53
+ declare function unstable_rethrow(error: unknown): void;
54
+ //#endregion
55
+ export { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow };
@@ -0,0 +1,110 @@
1
+ //#region src/shims/navigation-errors.ts
2
+ /**
3
+ * Server-safe navigation control-flow errors and predicates.
4
+ *
5
+ * This module intentionally has no React or browser-runtime dependencies so
6
+ * RSC, SSR, and the public next/navigation shim can share one implementation.
7
+ */
8
+ const HTTP_ERROR_FALLBACK_ERROR_CODE = "NEXT_HTTP_ERROR_FALLBACK";
9
+ function isHTTPAccessFallbackError(error) {
10
+ if (!error || typeof error !== "object" || !("digest" in error)) return false;
11
+ const digest = String(error.digest);
12
+ return digest === "NEXT_NOT_FOUND" || digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`);
13
+ }
14
+ function getAccessFallbackHTTPStatus(error) {
15
+ if (error && typeof error === "object" && "digest" in error) {
16
+ const digest = String(error.digest);
17
+ if (digest === "NEXT_NOT_FOUND") return 404;
18
+ if (digest.startsWith(`NEXT_HTTP_ERROR_FALLBACK;`)) return Number.parseInt(digest.split(";")[1], 10);
19
+ }
20
+ return 404;
21
+ }
22
+ let RedirectType = /* @__PURE__ */ function(RedirectType) {
23
+ RedirectType["push"] = "push";
24
+ RedirectType["replace"] = "replace";
25
+ return RedirectType;
26
+ }({});
27
+ var VinextNavigationError = class extends Error {
28
+ digest;
29
+ constructor(message, digest) {
30
+ super(message);
31
+ this.digest = digest;
32
+ }
33
+ };
34
+ /**
35
+ * The omitted redirect type is resolved by the catch site: push for Server
36
+ * Actions and replace for ordinary SSR/RSC rendering.
37
+ */
38
+ function redirect(url, type) {
39
+ throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type ?? ""};${encodeURIComponent(url)}`);
40
+ }
41
+ function permanentRedirect(url, type = "replace") {
42
+ throw new VinextNavigationError(`NEXT_REDIRECT:${url}`, `NEXT_REDIRECT;${type};${encodeURIComponent(url)};308`);
43
+ }
44
+ function notFound() {
45
+ throw new VinextNavigationError("NEXT_NOT_FOUND", `${HTTP_ERROR_FALLBACK_ERROR_CODE};404`);
46
+ }
47
+ function forbidden() {
48
+ throw new VinextNavigationError("NEXT_FORBIDDEN", `${HTTP_ERROR_FALLBACK_ERROR_CODE};403`);
49
+ }
50
+ function unauthorized() {
51
+ throw new VinextNavigationError("NEXT_UNAUTHORIZED", `${HTTP_ERROR_FALLBACK_ERROR_CODE};401`);
52
+ }
53
+ /**
54
+ * vinext accepts its three-part redirect digest and Next.js's five-part form.
55
+ * A prefix check is deliberate because vinext permits an empty redirect type.
56
+ */
57
+ function isRedirectError(error) {
58
+ return !!error && typeof error === "object" && "digest" in error && typeof error.digest === "string" && error.digest.startsWith("NEXT_REDIRECT;");
59
+ }
60
+ function decodeRedirectError(digest) {
61
+ if (!digest.startsWith("NEXT_REDIRECT;")) return null;
62
+ const parts = digest.split(";");
63
+ const encodedTarget = parts.length >= 5 ? parts.slice(2, -2).join(";") : parts[2];
64
+ if (!encodedTarget) return null;
65
+ try {
66
+ return {
67
+ url: decodeURIComponent(encodedTarget),
68
+ type: parts[1] === "push" ? "push" : "replace"
69
+ };
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+ function isNextRouterError(error) {
75
+ return isRedirectError(error) || isHTTPAccessFallbackError(error);
76
+ }
77
+ const BAILOUT_TO_CSR_DIGEST = "BAILOUT_TO_CLIENT_SIDE_RENDERING";
78
+ var BailoutToCSRError = class extends Error {
79
+ digest = BAILOUT_TO_CSR_DIGEST;
80
+ reason;
81
+ constructor(reason) {
82
+ super(`Bail out to client-side rendering: ${reason}`);
83
+ this.reason = reason;
84
+ }
85
+ };
86
+ function isBailoutToCSRError(error) {
87
+ return !!error && typeof error === "object" && "digest" in error && error.digest === BAILOUT_TO_CSR_DIGEST;
88
+ }
89
+ const DYNAMIC_SERVER_USAGE_DIGEST = "DYNAMIC_SERVER_USAGE";
90
+ var DynamicServerError = class extends Error {
91
+ digest = DYNAMIC_SERVER_USAGE_DIGEST;
92
+ description;
93
+ constructor(description) {
94
+ super(`Dynamic server usage: ${description}`);
95
+ this.description = description;
96
+ }
97
+ };
98
+ function isDynamicServerError(error) {
99
+ return !!error && typeof error === "object" && "digest" in error && error.digest === DYNAMIC_SERVER_USAGE_DIGEST;
100
+ }
101
+ /**
102
+ * Rethrow framework control-flow signals before user error handling consumes
103
+ * them. This covers the categories vinext can currently produce.
104
+ */
105
+ function unstable_rethrow(error) {
106
+ if (isNextRouterError(error) || isBailoutToCSRError(error) || isDynamicServerError(error)) throw error;
107
+ if (error instanceof Error && "cause" in error) unstable_rethrow(error.cause);
108
+ }
109
+ //#endregion
110
+ export { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow };
@@ -0,0 +1,3 @@
1
+ import { GLOBAL_ACCESSORS_KEY, NavigationContext, NavigationStateAccessors, SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
2
+ import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
3
+ export { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, type NavigationContext, type NavigationStateAccessors, RedirectType, type SegmentMap, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow };
@@ -0,0 +1,3 @@
1
+ import { GLOBAL_ACCESSORS_KEY, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, flushServerInsertedHTML, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext } from "./navigation-context-state.js";
2
+ import { BailoutToCSRError, DynamicServerError, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, decodeRedirectError, forbidden, getAccessFallbackHTTPStatus, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, unauthorized, unstable_rethrow } from "./navigation-errors.js";
3
+ export { BailoutToCSRError, DynamicServerError, GLOBAL_ACCESSORS_KEY, HTTP_ERROR_FALLBACK_ERROR_CODE, RedirectType, ServerInsertedHTMLContext, _registerStateAccessors, clearClientHydrationContext, clearServerInsertedHTML, decodeRedirectError, flushServerInsertedHTML, forbidden, getAccessFallbackHTTPStatus, getBfcacheIdMapContext, getBfcacheSegmentIdContext, getLayoutSegmentContext, getNavigationContext, isBailoutToCSRError, isDynamicServerError, isHTTPAccessFallbackError, isNextRouterError, isRedirectError, notFound, permanentRedirect, redirect, registerServerInsertedHTMLCallback, renderServerInsertedHTML, setNavigationContext, unauthorized, unstable_rethrow };
@@ -1,5 +1,4 @@
1
- import { NavigationContext } from "./navigation.js";
2
-
1
+ import { NavigationContext } from "./navigation-context-state.js";
3
2
  //#region src/shims/navigation-state.d.ts
4
3
  type NavigationState = {
5
4
  serverContext: NavigationContext | null;
@@ -1,6 +1,7 @@
1
1
  import { getOrCreateAls } from "./internal/als-registry.js";
2
2
  import { getRequestContext, isInsideUnifiedScope, runWithUnifiedStateMutation } from "./unified-request-context.js";
3
- import { GLOBAL_ACCESSORS_KEY, _registerStateAccessors } from "./navigation.js";
3
+ import { GLOBAL_ACCESSORS_KEY, _registerStateAccessors } from "./navigation-context-state.js";
4
+ import "./navigation-server.js";
4
5
  //#region src/shims/navigation-state.ts
5
6
  /**
6
7
  * Server-only navigation state backed by AsyncLocalStorage.