vinext 0.0.29 → 0.0.30

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 (128) hide show
  1. package/dist/check.d.ts.map +1 -1
  2. package/dist/check.js +11 -7
  3. package/dist/check.js.map +1 -1
  4. package/dist/cloudflare/kv-cache-handler.d.ts.map +1 -1
  5. package/dist/cloudflare/kv-cache-handler.js +44 -30
  6. package/dist/cloudflare/kv-cache-handler.js.map +1 -1
  7. package/dist/entries/app-rsc-entry.d.ts +1 -1
  8. package/dist/entries/app-rsc-entry.d.ts.map +1 -1
  9. package/dist/entries/app-rsc-entry.js +208 -164
  10. package/dist/entries/app-rsc-entry.js.map +1 -1
  11. package/dist/entries/pages-server-entry.d.ts.map +1 -1
  12. package/dist/entries/pages-server-entry.js +151 -100
  13. package/dist/entries/pages-server-entry.js.map +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +10 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/routing/app-router.d.ts.map +1 -1
  18. package/dist/routing/app-router.js +43 -29
  19. package/dist/routing/app-router.js.map +1 -1
  20. package/dist/server/app-router-entry.js +1 -1
  21. package/dist/server/app-router-entry.js.map +1 -1
  22. package/dist/server/dev-server.d.ts +2 -1
  23. package/dist/server/dev-server.d.ts.map +1 -1
  24. package/dist/server/dev-server.js +163 -163
  25. package/dist/server/dev-server.js.map +1 -1
  26. package/dist/server/image-optimization.d.ts.map +1 -1
  27. package/dist/server/image-optimization.js +23 -11
  28. package/dist/server/image-optimization.js.map +1 -1
  29. package/dist/server/isr-cache.d.ts.map +1 -1
  30. package/dist/server/isr-cache.js +8 -3
  31. package/dist/server/isr-cache.js.map +1 -1
  32. package/dist/server/metadata-routes.d.ts.map +1 -1
  33. package/dist/server/metadata-routes.js +56 -18
  34. package/dist/server/metadata-routes.js.map +1 -1
  35. package/dist/server/middleware-codegen.d.ts.map +1 -1
  36. package/dist/server/middleware-codegen.js +37 -4
  37. package/dist/server/middleware-codegen.js.map +1 -1
  38. package/dist/server/middleware.d.ts.map +1 -1
  39. package/dist/server/middleware.js +50 -6
  40. package/dist/server/middleware.js.map +1 -1
  41. package/dist/server/pages-i18n.d.ts +50 -0
  42. package/dist/server/pages-i18n.d.ts.map +1 -0
  43. package/dist/server/pages-i18n.js +152 -0
  44. package/dist/server/pages-i18n.js.map +1 -0
  45. package/dist/shims/cache-runtime.d.ts +3 -0
  46. package/dist/shims/cache-runtime.d.ts.map +1 -1
  47. package/dist/shims/cache-runtime.js +22 -5
  48. package/dist/shims/cache-runtime.js.map +1 -1
  49. package/dist/shims/cache.d.ts +3 -0
  50. package/dist/shims/cache.d.ts.map +1 -1
  51. package/dist/shims/cache.js +21 -12
  52. package/dist/shims/cache.js.map +1 -1
  53. package/dist/shims/constants.d.ts.map +1 -1
  54. package/dist/shims/constants.js +0 -1
  55. package/dist/shims/constants.js.map +1 -1
  56. package/dist/shims/fetch-cache.d.ts +14 -0
  57. package/dist/shims/fetch-cache.d.ts.map +1 -1
  58. package/dist/shims/fetch-cache.js +102 -37
  59. package/dist/shims/fetch-cache.js.map +1 -1
  60. package/dist/shims/head-state.d.ts +4 -0
  61. package/dist/shims/head-state.d.ts.map +1 -1
  62. package/dist/shims/head-state.js +14 -11
  63. package/dist/shims/head-state.js.map +1 -1
  64. package/dist/shims/head.d.ts +4 -2
  65. package/dist/shims/head.d.ts.map +1 -1
  66. package/dist/shims/head.js +162 -52
  67. package/dist/shims/head.js.map +1 -1
  68. package/dist/shims/headers.d.ts +8 -1
  69. package/dist/shims/headers.d.ts.map +1 -1
  70. package/dist/shims/headers.js +21 -29
  71. package/dist/shims/headers.js.map +1 -1
  72. package/dist/shims/i18n-context.d.ts +27 -0
  73. package/dist/shims/i18n-context.d.ts.map +1 -0
  74. package/dist/shims/i18n-context.js +57 -0
  75. package/dist/shims/i18n-context.js.map +1 -0
  76. package/dist/shims/i18n-state.d.ts +20 -0
  77. package/dist/shims/i18n-state.d.ts.map +1 -0
  78. package/dist/shims/i18n-state.js +53 -0
  79. package/dist/shims/i18n-state.js.map +1 -0
  80. package/dist/shims/image.d.ts +2 -0
  81. package/dist/shims/image.d.ts.map +1 -1
  82. package/dist/shims/image.js +14 -6
  83. package/dist/shims/image.js.map +1 -1
  84. package/dist/shims/internal/utils.d.ts +1 -0
  85. package/dist/shims/internal/utils.d.ts.map +1 -1
  86. package/dist/shims/internal/utils.js.map +1 -1
  87. package/dist/shims/link.d.ts.map +1 -1
  88. package/dist/shims/link.js +27 -11
  89. package/dist/shims/link.js.map +1 -1
  90. package/dist/shims/metadata.d.ts +22 -22
  91. package/dist/shims/metadata.d.ts.map +1 -1
  92. package/dist/shims/metadata.js +34 -32
  93. package/dist/shims/metadata.js.map +1 -1
  94. package/dist/shims/navigation-state.d.ts +14 -0
  95. package/dist/shims/navigation-state.d.ts.map +1 -1
  96. package/dist/shims/navigation-state.js +33 -15
  97. package/dist/shims/navigation-state.js.map +1 -1
  98. package/dist/shims/navigation.d.ts.map +1 -1
  99. package/dist/shims/navigation.js +39 -22
  100. package/dist/shims/navigation.js.map +1 -1
  101. package/dist/shims/request-context.d.ts.map +1 -1
  102. package/dist/shims/request-context.js +9 -0
  103. package/dist/shims/request-context.js.map +1 -1
  104. package/dist/shims/request-state-types.d.ts +11 -0
  105. package/dist/shims/request-state-types.d.ts.map +1 -0
  106. package/dist/shims/request-state-types.js +2 -0
  107. package/dist/shims/request-state-types.js.map +1 -0
  108. package/dist/shims/router-state.d.ts +11 -0
  109. package/dist/shims/router-state.d.ts.map +1 -1
  110. package/dist/shims/router-state.js +10 -8
  111. package/dist/shims/router-state.js.map +1 -1
  112. package/dist/shims/router.d.ts +4 -0
  113. package/dist/shims/router.d.ts.map +1 -1
  114. package/dist/shims/router.js +117 -21
  115. package/dist/shims/router.js.map +1 -1
  116. package/dist/shims/server.d.ts +8 -1
  117. package/dist/shims/server.d.ts.map +1 -1
  118. package/dist/shims/server.js +52 -6
  119. package/dist/shims/server.js.map +1 -1
  120. package/dist/shims/unified-request-context.d.ts +66 -0
  121. package/dist/shims/unified-request-context.d.ts.map +1 -0
  122. package/dist/shims/unified-request-context.js +116 -0
  123. package/dist/shims/unified-request-context.js.map +1 -0
  124. package/dist/utils/domain-locale.d.ts +18 -0
  125. package/dist/utils/domain-locale.d.ts.map +1 -0
  126. package/dist/utils/domain-locale.js +64 -0
  127. package/dist/utils/domain-locale.js.map +1 -0
  128. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"pages-server-entry.d.ts","sourceRoot":"","sources":["../../src/entries/pages-server-entry.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAmBnE;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,kBAAkB,EAC9B,WAAW,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,EACtD,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,mBAAmB,EAAE,MAAM,GAAG,IAAI,GACjC,OAAO,CAAC,MAAM,CAAC,CA8kCjB"}
1
+ {"version":3,"file":"pages-server-entry.d.ts","sourceRoot":"","sources":["../../src/entries/pages-server-entry.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAuBnE;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,kBAAkB,EAC9B,WAAW,EAAE,UAAU,CAAC,OAAO,sBAAsB,CAAC,EACtD,cAAc,EAAE,MAAM,GAAG,IAAI,EAC7B,mBAAmB,EAAE,MAAM,GAAG,IAAI,GACjC,OAAO,CAAC,MAAM,CAAC,CAioCjB"}
@@ -16,6 +16,7 @@ import { findFileWithExts } from "./pages-entry-helpers.js";
16
16
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
17
17
  const _requestContextShimPath = fileURLToPath(new URL("../shims/request-context.js", import.meta.url)).replace(/\\/g, "/");
18
18
  const _routeTriePath = fileURLToPath(new URL("../routing/route-trie.js", import.meta.url)).replace(/\\/g, "/");
19
+ const _pagesI18nPath = fileURLToPath(new URL("../server/pages-i18n.js", import.meta.url)).replace(/\\/g, "/");
19
20
  /**
20
21
  * Generate the virtual SSR server entry module.
21
22
  * This is the entry point for `vite build --ssr`.
@@ -44,12 +45,10 @@ export async function generateServerEntry(pagesDir, nextConfig, fileMatcher, mid
44
45
  // Check for _app and _document
45
46
  const appFilePath = findFileWithExts(pagesDir, "_app", fileMatcher);
46
47
  const docFilePath = findFileWithExts(pagesDir, "_document", fileMatcher);
47
- const hasApp = appFilePath !== null;
48
- const hasDoc = docFilePath !== null;
49
- const appImportCode = hasApp
48
+ const appImportCode = appFilePath !== null
50
49
  ? `import { default as AppComponent } from ${JSON.stringify(appFilePath.replace(/\\/g, "/"))};`
51
50
  : `const AppComponent = null;`;
52
- const docImportCode = hasDoc
51
+ const docImportCode = docFilePath !== null
53
52
  ? `import { default as DocumentComponent } from ${JSON.stringify(docFilePath.replace(/\\/g, "/"))};`
54
53
  : `const DocumentComponent = null;`;
55
54
  // Serialize i18n config for embedding in the server entry
@@ -58,6 +57,7 @@ export async function generateServerEntry(pagesDir, nextConfig, fileMatcher, mid
58
57
  locales: nextConfig.i18n.locales,
59
58
  defaultLocale: nextConfig.i18n.defaultLocale,
60
59
  localeDetection: nextConfig.i18n.localeDetection,
60
+ domains: nextConfig.i18n.domains,
61
61
  })
62
62
  : "null";
63
63
  // Embed the resolved build ID at build time
@@ -223,12 +223,15 @@ import { renderToReadableStream } from "react-dom/server.edge";
223
223
  import { resetSSRHead, getSSRHeadHTML } from "next/head";
224
224
  import { flushPreloads } from "next/dynamic";
225
225
  import { setSSRContext, wrapWithRouterContext } from "next/router";
226
- import { getCacheHandler } from "next/cache";
227
- import { runWithFetchCache } from "vinext/fetch-cache";
228
- import { _runWithCacheState } from "next/cache";
226
+ import { getCacheHandler, _runWithCacheState } from "next/cache";
229
227
  import { runWithPrivateCache } from "vinext/cache-runtime";
230
- import { runWithRouterState } from "vinext/router-state";
228
+ import { ensureFetchPatch, runWithFetchCache } from "vinext/fetch-cache";
229
+ import { runWithRequestContext as _runWithUnifiedCtx, createRequestContext as _createUnifiedCtx } from "vinext/unified-request-context";
230
+ import "vinext/router-state";
231
+ import { runWithServerInsertedHTMLState } from "vinext/navigation-state";
231
232
  import { runWithHeadState } from "vinext/head-state";
233
+ import "vinext/i18n-state";
234
+ import { setI18nContext } from "vinext/i18n-context";
232
235
  import { safeJsonStringify } from "vinext/html";
233
236
  import { decode as decodeQueryString } from "node:querystring";
234
237
  import { getSSRFontLinks as _getSSRFontLinks, getSSRFontStyles as _getSSRFontStylesGoogle, getSSRFontPreloads as _getSSRFontPreloadsGoogle } from "next/font/google";
@@ -237,6 +240,7 @@ import { parseCookies } from ${JSON.stringify(path.resolve(__dirname, "../config
237
240
  import { runWithExecutionContext as _runWithExecutionContext, getRequestExecutionContext as _getRequestExecutionContext } from ${JSON.stringify(_requestContextShimPath)};
238
241
  import { buildRouteTrie as _buildRouteTrie, trieMatch as _trieMatch } from ${JSON.stringify(_routeTriePath)};
239
242
  import { reportRequestError as _reportRequestError } from "vinext/instrumentation";
243
+ import { resolvePagesI18nRequest } from ${JSON.stringify(_pagesI18nPath)};
240
244
  ${instrumentationImportCode}
241
245
  ${middlewareImportCode}
242
246
 
@@ -322,6 +326,21 @@ async function renderToStringAsync(element) {
322
326
  return new Response(stream).text();
323
327
  }
324
328
 
329
+ async function renderIsrPassToStringAsync(element) {
330
+ // The cache-fill render is a second render pass for the same request.
331
+ // Reset render-scoped state so it cannot leak from the streamed response
332
+ // render or affect async work that is still draining from that stream.
333
+ // Keep request identity state (pathname/query/locale/executionContext)
334
+ // intact: this second pass still belongs to the same request.
335
+ return await runWithServerInsertedHTMLState(() =>
336
+ runWithHeadState(() =>
337
+ _runWithCacheState(() =>
338
+ runWithPrivateCache(() => runWithFetchCache(async () => renderToStringAsync(element))),
339
+ ),
340
+ ),
341
+ );
342
+ }
343
+
325
344
  ${pageImports.join("\n")}
326
345
  ${apiImports.join("\n")}
327
346
 
@@ -651,23 +670,25 @@ export async function renderPage(request, url, manifest, ctx) {
651
670
  }
652
671
 
653
672
  async function _renderPage(request, url, manifest) {
654
- const localeInfo = extractLocale(url);
673
+ const localeInfo = i18nConfig
674
+ ? resolvePagesI18nRequest(
675
+ url,
676
+ i18nConfig,
677
+ request.headers,
678
+ new URL(request.url).hostname,
679
+ vinextConfig.basePath,
680
+ vinextConfig.trailingSlash,
681
+ )
682
+ : { locale: undefined, url, hadPrefix: false, domainLocale: undefined, redirectUrl: undefined };
655
683
  const locale = localeInfo.locale;
656
684
  const routeUrl = localeInfo.url;
657
- const cookieHeader = request.headers.get("cookie") || "";
685
+ const currentDefaultLocale = i18nConfig
686
+ ? (localeInfo.domainLocale ? localeInfo.domainLocale.defaultLocale : i18nConfig.defaultLocale)
687
+ : undefined;
688
+ const domainLocales = i18nConfig ? i18nConfig.domains : undefined;
658
689
 
659
- // i18n redirect: check NEXT_LOCALE cookie first, then Accept-Language
660
- if (i18nConfig && !localeInfo.hadPrefix) {
661
- const cookieLocale = parseCookieLocaleFromHeader(cookieHeader);
662
- if (cookieLocale && cookieLocale !== i18nConfig.defaultLocale) {
663
- return new Response(null, { status: 307, headers: { Location: "/" + cookieLocale + routeUrl } });
664
- }
665
- if (!cookieLocale && i18nConfig.localeDetection !== false) {
666
- const detected = detectLocaleFromHeaders(request.headers);
667
- if (detected && detected !== i18nConfig.defaultLocale) {
668
- return new Response(null, { status: 307, headers: { Location: "/" + detected + routeUrl } });
669
- }
670
- }
690
+ if (localeInfo.redirectUrl) {
691
+ return new Response(null, { status: 307, headers: { Location: localeInfo.redirectUrl } });
671
692
  }
672
693
 
673
694
  const match = matchRoute(routeUrl, pageRoutes);
@@ -677,12 +698,12 @@ async function _renderPage(request, url, manifest) {
677
698
  }
678
699
 
679
700
  const { route, params } = match;
680
- return runWithRouterState(() =>
681
- runWithHeadState(() =>
682
- _runWithCacheState(() =>
683
- runWithPrivateCache(() =>
684
- runWithFetchCache(async () => {
685
- try {
701
+ const __uCtx = _createUnifiedCtx({
702
+ executionContext: _getRequestExecutionContext(),
703
+ });
704
+ return _runWithUnifiedCtx(__uCtx, async () => {
705
+ ensureFetchPatch();
706
+ try {
686
707
  if (typeof setSSRContext === "function") {
687
708
  setSSRContext({
688
709
  pathname: patternToNextFormat(route.pattern),
@@ -690,14 +711,19 @@ async function _renderPage(request, url, manifest) {
690
711
  asPath: routeUrl,
691
712
  locale: locale,
692
713
  locales: i18nConfig ? i18nConfig.locales : undefined,
693
- defaultLocale: i18nConfig ? i18nConfig.defaultLocale : undefined,
714
+ defaultLocale: currentDefaultLocale,
715
+ domainLocales: domainLocales,
694
716
  });
695
717
  }
696
718
 
697
719
  if (i18nConfig) {
698
- globalThis.__VINEXT_LOCALE__ = locale;
699
- globalThis.__VINEXT_LOCALES__ = i18nConfig.locales;
700
- globalThis.__VINEXT_DEFAULT_LOCALE__ = i18nConfig.defaultLocale;
720
+ setI18nContext({
721
+ locale: locale,
722
+ locales: i18nConfig.locales,
723
+ defaultLocale: currentDefaultLocale,
724
+ domainLocales: domainLocales,
725
+ hostname: new URL(request.url).hostname,
726
+ });
701
727
  }
702
728
 
703
729
  const pageModule = route.module;
@@ -710,7 +736,7 @@ async function _renderPage(request, url, manifest) {
710
736
  if (typeof pageModule.getStaticPaths === "function" && route.isDynamic) {
711
737
  const pathsResult = await pageModule.getStaticPaths({
712
738
  locales: i18nConfig ? i18nConfig.locales : [],
713
- defaultLocale: i18nConfig ? i18nConfig.defaultLocale : "",
739
+ defaultLocale: currentDefaultLocale || "",
714
740
  });
715
741
  const fallback = pathsResult && pathsResult.fallback !== undefined ? pathsResult.fallback : false;
716
742
 
@@ -743,7 +769,7 @@ async function _renderPage(request, url, manifest) {
743
769
  resolvedUrl: routeUrl,
744
770
  locale: locale,
745
771
  locales: i18nConfig ? i18nConfig.locales : undefined,
746
- defaultLocale: i18nConfig ? i18nConfig.defaultLocale : undefined,
772
+ defaultLocale: currentDefaultLocale,
747
773
  };
748
774
  const result = await pageModule.getServerSideProps(ctx);
749
775
  // If gSSP called res.end() directly (short-circuit), return that response.
@@ -792,61 +818,89 @@ async function _renderPage(request, url, manifest) {
792
818
 
793
819
  if (cached && cached.isStale && cached.value.value && cached.value.value.kind === "PAGES") {
794
820
  triggerBackgroundRegeneration(cacheKey, async function() {
795
- var freshResult = await pageModule.getStaticProps({
796
- params: params,
797
- locale: locale,
798
- locales: i18nConfig ? i18nConfig.locales : undefined,
799
- defaultLocale: i18nConfig ? i18nConfig.defaultLocale : undefined,
821
+ var revalCtx = _createUnifiedCtx({
822
+ executionContext: _getRequestExecutionContext(),
800
823
  });
801
- if (freshResult && freshResult.props && typeof freshResult.revalidate === "number" && freshResult.revalidate > 0) {
802
- var _fp = freshResult.props;
803
- // Re-render the page with fresh props
804
- var _el = AppComponent
805
- ? React.createElement(AppComponent, { Component: PageComponent, pageProps: _fp })
806
- : React.createElement(PageComponent, _fp);
807
- _el = wrapWithRouterContext(_el);
808
- var _freshBody = await renderToStringAsync(_el);
809
- // Rebuild __NEXT_DATA__ with fresh props
810
- var _regenPayload = {
811
- props: { pageProps: _fp }, page: patternToNextFormat(route.pattern),
812
- query: params, buildId: buildId, isFallback: false,
813
- };
814
- if (i18nConfig) {
815
- _regenPayload.locale = locale;
816
- _regenPayload.locales = i18nConfig.locales;
817
- _regenPayload.defaultLocale = i18nConfig.defaultLocale;
818
- }
819
- var _lGlobals = i18nConfig
820
- ? ";window.__VINEXT_LOCALE__=" + safeJsonStringify(locale) +
821
- ";window.__VINEXT_LOCALES__=" + safeJsonStringify(i18nConfig.locales) +
822
- ";window.__VINEXT_DEFAULT_LOCALE__=" + safeJsonStringify(i18nConfig.defaultLocale)
823
- : "";
824
- var _freshNDS = "<script>window.__NEXT_DATA__ = " + safeJsonStringify(_regenPayload) + _lGlobals + "</script>";
825
- // Reconstruct ISR HTML preserving the document shell from the
826
- // cached entry (head, fonts, assets, custom _document markup).
827
- var _cachedStr = cached.value.value.html;
828
- var _btag = '<div id="__next">';
829
- var _bstart = _cachedStr.indexOf(_btag);
830
- var _bodyStart = _bstart >= 0 ? _bstart + _btag.length : -1;
831
- // Locate __NEXT_DATA__ script to split body from suffix
832
- var _ndMarker = '<script>window.__NEXT_DATA__';
833
- var _ndStart = _cachedStr.indexOf(_ndMarker);
834
- var _freshHtml;
835
- if (_bodyStart >= 0 && _ndStart >= 0) {
836
- // Region between body start and __NEXT_DATA__ contains:
837
- // BODY_HTML + </div> + optional gap (custom _document content)
838
- var _region = _cachedStr.slice(_bodyStart, _ndStart);
839
- var _lastClose = _region.lastIndexOf('</div>');
840
- var _gap = _lastClose >= 0 ? _region.slice(_lastClose + 6) : '';
841
- // Tail: everything after the old __NEXT_DATA__ </script>
842
- var _ndEnd = _cachedStr.indexOf('</script>', _ndStart) + 9;
843
- var _tail = _cachedStr.slice(_ndEnd);
844
- _freshHtml = _cachedStr.slice(0, _bodyStart) + _freshBody + '</div>' + _gap + _freshNDS + _tail;
845
- } else {
846
- _freshHtml = '<!DOCTYPE html>\\n<html>\\n<head>\\n</head>\\n<body>\\n <div id="__next">' + _freshBody + '</div>\\n ' + _freshNDS + '\\n</body>\\n</html>';
847
- }
848
- await isrSet(cacheKey, { kind: "PAGES", html: _freshHtml, pageData: _fp, headers: undefined, status: undefined }, freshResult.revalidate);
849
- }
824
+ return _runWithUnifiedCtx(revalCtx, async () => {
825
+ ensureFetchPatch();
826
+ var freshResult = await pageModule.getStaticProps({
827
+ params: params,
828
+ locale: locale,
829
+ locales: i18nConfig ? i18nConfig.locales : undefined,
830
+ defaultLocale: currentDefaultLocale,
831
+ });
832
+ if (freshResult && freshResult.props && typeof freshResult.revalidate === "number" && freshResult.revalidate > 0) {
833
+ var _fp = freshResult.props;
834
+ if (typeof setSSRContext === "function") {
835
+ setSSRContext({
836
+ pathname: patternToNextFormat(route.pattern),
837
+ query: { ...params, ...parseQuery(routeUrl) },
838
+ asPath: routeUrl,
839
+ locale: locale,
840
+ locales: i18nConfig ? i18nConfig.locales : undefined,
841
+ defaultLocale: currentDefaultLocale,
842
+ domainLocales: domainLocales,
843
+ });
844
+ }
845
+ if (i18nConfig) {
846
+ setI18nContext({
847
+ locale: locale,
848
+ locales: i18nConfig.locales,
849
+ defaultLocale: currentDefaultLocale,
850
+ domainLocales: domainLocales,
851
+ hostname: new URL(request.url).hostname,
852
+ });
853
+ }
854
+ // Re-render the page with fresh props inside fresh render sub-scopes
855
+ // so head/cache state cannot leak across passes.
856
+ var _el = AppComponent
857
+ ? React.createElement(AppComponent, { Component: PageComponent, pageProps: _fp })
858
+ : React.createElement(PageComponent, _fp);
859
+ _el = wrapWithRouterContext(_el);
860
+ var _freshBody = await renderIsrPassToStringAsync(_el);
861
+ // Rebuild __NEXT_DATA__ with fresh props
862
+ var _regenPayload = {
863
+ props: { pageProps: _fp }, page: patternToNextFormat(route.pattern),
864
+ query: params, buildId: buildId, isFallback: false,
865
+ };
866
+ if (i18nConfig) {
867
+ _regenPayload.locale = locale;
868
+ _regenPayload.locales = i18nConfig.locales;
869
+ _regenPayload.defaultLocale = currentDefaultLocale;
870
+ _regenPayload.domainLocales = domainLocales;
871
+ }
872
+ var _lGlobals = i18nConfig
873
+ ? ";window.__VINEXT_LOCALE__=" + safeJsonStringify(locale) +
874
+ ";window.__VINEXT_LOCALES__=" + safeJsonStringify(i18nConfig.locales) +
875
+ ";window.__VINEXT_DEFAULT_LOCALE__=" + safeJsonStringify(currentDefaultLocale)
876
+ : "";
877
+ var _freshNDS = "<script>window.__NEXT_DATA__ = " + safeJsonStringify(_regenPayload) + _lGlobals + "</script>";
878
+ // Reconstruct ISR HTML preserving the document shell from the
879
+ // cached entry (head, fonts, assets, custom _document markup).
880
+ var _cachedStr = cached.value.value.html;
881
+ var _btag = '<div id="__next">';
882
+ var _bstart = _cachedStr.indexOf(_btag);
883
+ var _bodyStart = _bstart >= 0 ? _bstart + _btag.length : -1;
884
+ // Locate __NEXT_DATA__ script to split body from suffix
885
+ var _ndMarker = '<script>window.__NEXT_DATA__';
886
+ var _ndStart = _cachedStr.indexOf(_ndMarker);
887
+ var _freshHtml;
888
+ if (_bodyStart >= 0 && _ndStart >= 0) {
889
+ // Region between body start and __NEXT_DATA__ contains:
890
+ // BODY_HTML + </div> + optional gap (custom _document content)
891
+ var _region = _cachedStr.slice(_bodyStart, _ndStart);
892
+ var _lastClose = _region.lastIndexOf('</div>');
893
+ var _gap = _lastClose >= 0 ? _region.slice(_lastClose + 6) : '';
894
+ // Tail: everything after the old __NEXT_DATA__ </script>
895
+ var _ndEnd = _cachedStr.indexOf('</script>', _ndStart) + 9;
896
+ var _tail = _cachedStr.slice(_ndEnd);
897
+ _freshHtml = _cachedStr.slice(0, _bodyStart) + _freshBody + '</div>' + _gap + _freshNDS + _tail;
898
+ } else {
899
+ _freshHtml = '<!DOCTYPE html>\\n<html>\\n<head>\\n</head>\\n<body>\\n <div id="__next">' + _freshBody + '</div>\\n ' + _freshNDS + '\\n</body>\\n</html>';
900
+ }
901
+ await isrSet(cacheKey, { kind: "PAGES", html: _freshHtml, pageData: _fp, headers: undefined, status: undefined }, freshResult.revalidate);
902
+ }
903
+ });
850
904
  });
851
905
  var _staleHeaders = {
852
906
  "Content-Type": "text/html", "X-Vinext-Cache": "STALE",
@@ -860,7 +914,7 @@ async function _renderPage(request, url, manifest) {
860
914
  params,
861
915
  locale: locale,
862
916
  locales: i18nConfig ? i18nConfig.locales : undefined,
863
- defaultLocale: i18nConfig ? i18nConfig.defaultLocale : undefined,
917
+ defaultLocale: currentDefaultLocale,
864
918
  };
865
919
  const result = await pageModule.getStaticProps(ctx);
866
920
  if (result && result.props) pageProps = result.props;
@@ -913,12 +967,13 @@ async function _renderPage(request, url, manifest) {
913
967
  if (i18nConfig) {
914
968
  nextDataPayload.locale = locale;
915
969
  nextDataPayload.locales = i18nConfig.locales;
916
- nextDataPayload.defaultLocale = i18nConfig.defaultLocale;
970
+ nextDataPayload.defaultLocale = currentDefaultLocale;
971
+ nextDataPayload.domainLocales = domainLocales;
917
972
  }
918
973
  const localeGlobals = i18nConfig
919
974
  ? ";window.__VINEXT_LOCALE__=" + safeJsonStringify(locale) +
920
975
  ";window.__VINEXT_LOCALES__=" + safeJsonStringify(i18nConfig.locales) +
921
- ";window.__VINEXT_DEFAULT_LOCALE__=" + safeJsonStringify(i18nConfig.defaultLocale)
976
+ ";window.__VINEXT_DEFAULT_LOCALE__=" + safeJsonStringify(currentDefaultLocale)
922
977
  : "";
923
978
  const nextDataScript = "<script>window.__NEXT_DATA__ = " + safeJsonStringify(nextDataPayload) + localeGlobals + "</script>";
924
979
 
@@ -981,7 +1036,7 @@ async function _renderPage(request, url, manifest) {
981
1036
  isrElement = React.createElement(PageComponent, pageProps);
982
1037
  }
983
1038
  isrElement = wrapWithRouterContext(isrElement);
984
- var isrHtml = await renderToStringAsync(isrElement);
1039
+ var isrHtml = await renderIsrPassToStringAsync(isrElement);
985
1040
  var fullHtml = shellPrefix + isrHtml + shellSuffix;
986
1041
  var isrPathname = url.split("?")[0];
987
1042
  var _cacheKey = isrCacheKey("pages", isrPathname);
@@ -1015,20 +1070,16 @@ async function _renderPage(request, url, manifest) {
1015
1070
  responseHeaders.set("Link", _fontLinkHeader);
1016
1071
  }
1017
1072
  return new Response(compositeStream, { status: finalStatus, headers: responseHeaders });
1018
- } catch (e) {
1073
+ } catch (e) {
1019
1074
  console.error("[vinext] SSR error:", e);
1020
1075
  _reportRequestError(
1021
1076
  e instanceof Error ? e : new Error(String(e)),
1022
1077
  { path: url, method: request.method, headers: Object.fromEntries(request.headers.entries()) },
1023
1078
  { routerKind: "Pages Router", routePath: route.pattern, routeType: "render" },
1024
- );
1079
+ ).catch(() => { /* ignore reporting errors */ });
1025
1080
  return new Response("Internal Server Error", { status: 500 });
1026
- }
1027
- }) // end runWithFetchCache
1028
- ) // end runWithPrivateCache
1029
- ) // end _runWithCacheState
1030
- ) // end runWithHeadState
1031
- ); // end runWithRouterState
1081
+ }
1082
+ });
1032
1083
  }
1033
1084
 
1034
1085
  export async function handleApiRoute(request, url) {