vike 0.4.235 → 0.4.236-commit-64431e7

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 (227) hide show
  1. package/dist/cjs/__internal/index.js +1 -1
  2. package/dist/cjs/client/shared/createGetGlobalContextClient.js +2 -3
  3. package/dist/cjs/client/shared/preparePageContextForPublicUsageClientShared.js +4 -4
  4. package/dist/cjs/node/api/prepareViteApiCall.js +1 -1
  5. package/dist/cjs/node/cli/index.js +1 -1
  6. package/dist/cjs/node/createPageRenderer.js +1 -1
  7. package/dist/cjs/node/importBuild.js +1 -1
  8. package/dist/cjs/node/prerender/context.js +1 -1
  9. package/dist/cjs/node/prerender/index.js +1 -1
  10. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +2 -2
  11. package/dist/cjs/node/prerender/runPrerender.js +9 -13
  12. package/dist/cjs/node/runtime/globalContext.js +109 -28
  13. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
  14. package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
  15. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +2 -0
  16. package/dist/cjs/node/runtime/html/serializeContext.js +73 -15
  17. package/dist/cjs/node/runtime/index-deprecated.js +1 -1
  18. package/dist/cjs/node/runtime/index.js +1 -1
  19. package/dist/cjs/node/runtime/page-files/setup.js +1 -1
  20. package/dist/cjs/node/runtime/renderPage/assertArguments.js +1 -1
  21. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +9 -6
  22. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -4
  23. package/dist/cjs/node/runtime/renderPage/execHookDataAndOnBeforeRender.js +2 -2
  24. package/dist/cjs/node/runtime/renderPage/{createHttpResponse/getCacheControl.js → getCacheControl.js} +9 -9
  25. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +4 -4
  26. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
  27. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -12
  28. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +35 -16
  29. package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +1 -1
  30. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
  31. package/dist/cjs/node/runtime/renderPage.js +4 -6
  32. package/dist/cjs/node/runtime/utils.js +1 -0
  33. package/dist/cjs/node/vite/index.js +2 -0
  34. package/dist/cjs/node/vite/onLoad.js +1 -1
  35. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
  36. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +3 -2
  37. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildEntry.js +1 -1
  38. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
  39. package/dist/cjs/node/vite/plugins/pluginCommon/assertResolveAlias.js +1 -1
  40. package/dist/cjs/node/vite/plugins/pluginCommon.js +9 -4
  41. package/dist/cjs/node/vite/plugins/pluginDev.js +1 -1
  42. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +4 -4
  43. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
  44. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +1 -1
  45. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
  46. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +1 -1
  47. package/dist/cjs/node/vite/plugins/pluginViteRPC.js +42 -0
  48. package/dist/cjs/node/vite/shared/addSsrMiddleware.js +1 -1
  49. package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +1 -0
  50. package/dist/cjs/node/vite/shared/loggerNotProd.js +10 -6
  51. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +5 -1
  52. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
  53. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
  54. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +1 -1
  55. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +6 -6
  56. package/dist/cjs/shared/RenderErrorPage.js +1 -1
  57. package/dist/cjs/shared/abort.js +1 -1
  58. package/dist/cjs/shared/createGlobalContextShared.js +28 -7
  59. package/dist/cjs/shared/createPageContextShared.js +1 -2
  60. package/dist/cjs/shared/determinePageIdOld.js +1 -1
  61. package/dist/cjs/shared/error-page.js +3 -3
  62. package/dist/cjs/shared/getPageContextUrlComputed.js +4 -4
  63. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +1 -1
  64. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +1 -1
  65. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -1
  66. package/dist/cjs/shared/getPageFiles/analyzePageClientSide.js +2 -2
  67. package/dist/cjs/shared/getPageFiles/assert_exports_old_design.js +1 -1
  68. package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
  69. package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +1 -1
  70. package/dist/cjs/shared/getPageFiles/getPageFileObject.js +1 -1
  71. package/dist/cjs/shared/getPageFiles/parseVirtualFileExports.js +1 -1
  72. package/dist/cjs/shared/getProxyForPublicUsage.js +3 -3
  73. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +4 -3
  74. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +10 -10
  75. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  76. package/dist/cjs/shared/preparePageContextForPublicUsage.js +5 -5
  77. package/dist/cjs/shared/route/abort.js +1 -1
  78. package/dist/cjs/shared/route/deduceRouteStringFromFilesystemPath.js +1 -1
  79. package/dist/cjs/shared/route/execHookGuard.js +1 -1
  80. package/dist/cjs/shared/route/execHookOnBeforeRoute.js +1 -1
  81. package/dist/cjs/shared/route/index.js +1 -1
  82. package/dist/cjs/shared/route/loadPageRoutes.js +10 -4
  83. package/dist/cjs/shared/route/resolveRouteFunction.js +3 -3
  84. package/dist/cjs/shared/route/resolveRouteString.js +1 -1
  85. package/dist/cjs/shared/route/routing.js +1 -1
  86. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  87. package/dist/cjs/utils/assertSetup.js +11 -8
  88. package/dist/cjs/utils/debug.js +1 -0
  89. package/dist/cjs/utils/debugGlob.js +1 -1
  90. package/dist/cjs/utils/getViteRPC.js +79 -0
  91. package/dist/cjs/utils/parseNpmPackage.js +1 -1
  92. package/dist/esm/__internal/index.d.ts +1 -1
  93. package/dist/esm/__internal/index.js +1 -1
  94. package/dist/esm/client/node.js +1 -1
  95. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
  96. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +2 -2
  97. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +10 -2
  98. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +6 -6
  99. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
  100. package/dist/esm/client/runtime-client-routing/index.js +1 -1
  101. package/dist/esm/client/runtime-client-routing/isClientSideRoutable.js +1 -1
  102. package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.js +6 -6
  103. package/dist/esm/client/runtime-client-routing/prefetch.js +10 -10
  104. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +3 -1
  105. package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +3 -3
  106. package/dist/esm/client/runtime-client-routing/skipLink.js +1 -1
  107. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
  108. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +2 -2
  109. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
  110. package/dist/esm/client/runtime-server-routing/index.js +1 -1
  111. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +5 -4
  112. package/dist/esm/client/shared/createGetGlobalContextClient.js +1 -2
  113. package/dist/esm/client/shared/execHookOnRenderClient.js +1 -1
  114. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -2
  115. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +4 -4
  116. package/dist/esm/node/api/prepareViteApiCall.js +1 -1
  117. package/dist/esm/node/cli/index.js +1 -1
  118. package/dist/esm/node/createPageRenderer.js +1 -1
  119. package/dist/esm/node/importBuild.js +1 -1
  120. package/dist/esm/node/prerender/context.js +1 -1
  121. package/dist/esm/node/prerender/index.js +1 -1
  122. package/dist/esm/node/prerender/resolvePrerenderConfig.js +2 -2
  123. package/dist/esm/node/prerender/runPrerender.d.ts +42 -133
  124. package/dist/esm/node/prerender/runPrerender.js +9 -13
  125. package/dist/esm/node/runtime/globalContext.d.ts +39 -59
  126. package/dist/esm/node/runtime/globalContext.js +112 -31
  127. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +8 -1
  128. package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
  129. package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +2 -0
  130. package/dist/esm/node/runtime/html/serializeContext.d.ts +7 -1
  131. package/dist/esm/node/runtime/html/serializeContext.js +73 -15
  132. package/dist/esm/node/runtime/index-deprecated.js +1 -1
  133. package/dist/esm/node/runtime/index.js +1 -1
  134. package/dist/esm/node/runtime/page-files/setup.js +1 -1
  135. package/dist/esm/node/runtime/renderPage/assertArguments.js +1 -1
  136. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -0
  137. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +9 -6
  138. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +12 -35
  139. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -4
  140. package/dist/esm/node/runtime/renderPage/execHookDataAndOnBeforeRender.js +2 -2
  141. package/dist/esm/node/runtime/renderPage/getCacheControl.d.ts +5 -0
  142. package/dist/esm/node/runtime/renderPage/{createHttpResponse/getCacheControl.js → getCacheControl.js} +8 -9
  143. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +4 -4
  144. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
  145. package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -13
  146. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +8 -4
  147. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +36 -17
  148. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +1 -1
  149. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +24 -68
  150. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
  151. package/dist/esm/node/runtime/renderPage.d.ts +13 -36
  152. package/dist/esm/node/runtime/renderPage.js +4 -6
  153. package/dist/esm/node/runtime/utils.d.ts +1 -0
  154. package/dist/esm/node/runtime/utils.js +1 -0
  155. package/dist/esm/node/vite/index.js +3 -1
  156. package/dist/esm/node/vite/onLoad.js +1 -1
  157. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
  158. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -3
  159. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +1 -1
  160. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +3 -2
  161. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildEntry.js +1 -1
  162. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +16 -7
  163. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +0 -1
  164. package/dist/esm/node/vite/plugins/pluginCommon/assertResolveAlias.js +1 -1
  165. package/dist/esm/node/vite/plugins/pluginCommon.d.ts +3 -0
  166. package/dist/esm/node/vite/plugins/pluginCommon.js +9 -4
  167. package/dist/esm/node/vite/plugins/pluginDev.js +1 -1
  168. package/dist/esm/node/vite/plugins/pluginEnvVars.js +1 -1
  169. package/dist/esm/node/vite/plugins/pluginFileEnv.js +1 -1
  170. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +1 -1
  171. package/dist/esm/node/vite/plugins/pluginViteRPC.d.ts +25 -0
  172. package/dist/esm/node/vite/plugins/pluginViteRPC.js +40 -0
  173. package/dist/esm/node/vite/shared/addSsrMiddleware.js +1 -1
  174. package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +1 -0
  175. package/dist/esm/node/vite/shared/loggerNotProd.js +10 -0
  176. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +5 -1
  177. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -3
  178. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
  179. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +1 -1
  180. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +6 -6
  181. package/dist/esm/shared/RenderErrorPage.js +1 -1
  182. package/dist/esm/shared/abort.js +1 -1
  183. package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
  184. package/dist/esm/shared/createGlobalContextShared.js +28 -7
  185. package/dist/esm/shared/createPageContextShared.d.ts +2 -3
  186. package/dist/esm/shared/createPageContextShared.js +1 -2
  187. package/dist/esm/shared/determinePageIdOld.js +1 -1
  188. package/dist/esm/shared/error-page.js +3 -3
  189. package/dist/esm/shared/getPageContextUrlComputed.js +4 -4
  190. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
  191. package/dist/esm/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +1 -1
  192. package/dist/esm/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -1
  193. package/dist/esm/shared/getPageFiles/analyzePageClientSide.js +2 -2
  194. package/dist/esm/shared/getPageFiles/assert_exports_old_design.js +1 -1
  195. package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
  196. package/dist/esm/shared/getPageFiles/getAllPageIdFiles.js +1 -1
  197. package/dist/esm/shared/getPageFiles/getPageFileObject.js +1 -1
  198. package/dist/esm/shared/getPageFiles/parseVirtualFileExports.js +1 -1
  199. package/dist/esm/shared/getProxyForPublicUsage.js +1 -1
  200. package/dist/esm/shared/hooks/getHook.js +1 -1
  201. package/dist/esm/shared/page-configs/getConfigDefinedAt.js +4 -3
  202. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +12 -12
  203. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  204. package/dist/esm/shared/preparePageContextForPublicUsage.js +5 -5
  205. package/dist/esm/shared/route/abort.js +1 -1
  206. package/dist/esm/shared/route/deduceRouteStringFromFilesystemPath.js +1 -1
  207. package/dist/esm/shared/route/execHookGuard.js +1 -1
  208. package/dist/esm/shared/route/execHookOnBeforeRoute.js +1 -1
  209. package/dist/esm/shared/route/index.js +1 -1
  210. package/dist/esm/shared/route/loadPageRoutes.d.ts +5 -0
  211. package/dist/esm/shared/route/loadPageRoutes.js +10 -4
  212. package/dist/esm/shared/route/resolveRouteFunction.js +3 -3
  213. package/dist/esm/shared/route/resolveRouteString.js +1 -1
  214. package/dist/esm/shared/route/routing.js +1 -1
  215. package/dist/esm/types/Config.d.ts +9 -1
  216. package/dist/esm/types/PageContext.d.ts +8 -2
  217. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  218. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  219. package/dist/esm/utils/assertSetup.js +11 -8
  220. package/dist/esm/utils/debug.d.ts +1 -1
  221. package/dist/esm/utils/debug.js +1 -0
  222. package/dist/esm/utils/debugGlob.js +1 -1
  223. package/dist/esm/utils/getViteRPC.d.ts +6 -0
  224. package/dist/esm/utils/getViteRPC.js +77 -0
  225. package/dist/esm/utils/parseNpmPackage.js +1 -1
  226. package/package.json +12 -6
  227. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +0 -5
@@ -13,7 +13,7 @@ export { setGlobalContext_viteDevServer };
13
13
  export { setGlobalContext_viteConfig };
14
14
  export { setGlobalContext_isPrerendering };
15
15
  export { setGlobalContext_isProduction };
16
- export { setGlobalContext_buildEntry };
16
+ export { setGlobalContext_buildEntry }; // production entry
17
17
  export { clearGlobalContext };
18
18
  export { assertBuildInfo };
19
19
  export { updateUserFiles };
@@ -26,11 +26,11 @@ export { vikeConfigErrorRecoverMsg };
26
26
  // - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
27
27
  // - In development: globalObject.viteDevServer which is Vite's development server
28
28
  // - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExports
29
- import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, } from './utils.js';
29
+ import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, } from './utils.js';
30
30
  import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
31
31
  import { virtualFileIdEntryServer } from '../shared/virtualFiles/virtualFileEntry.js';
32
32
  import pc from '@brillout/picocolors';
33
- import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
33
+ import { loadPageRoutes, loadPageRoutesSync } from '../../shared/route/loadPageRoutes.js';
34
34
  import { assertV1Design } from '../shared/assertV1Design.js';
35
35
  import { resolveBase } from '../shared/resolveBase.js';
36
36
  import { createGlobalContextShared, getGlobalContextSyncErrMsg, } from '../../shared/createGlobalContextShared.js';
@@ -39,7 +39,7 @@ import { logRuntimeError, logRuntimeInfo } from './loggerRuntime.js';
39
39
  import { getVikeConfigErrorBuild, setVikeConfigError } from '../shared/getVikeConfigError.js';
40
40
  import { hasAlreadyLogged } from './renderPage/isNewError.js';
41
41
  const debug = createDebugger('vike:globalContext');
42
- const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalContext());
42
+ const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalObject());
43
43
  // Trick to break down TypeScript circular dependency
44
44
  // https://chat.deepseek.com/a/chat/s/d7e9f90a-c7f3-4108-9cd5-4ad6caed3539
45
45
  const globalObjectTyped = globalObject;
@@ -99,17 +99,19 @@ async function getGlobalContextAsync(isProduction) {
99
99
  * Get runtime information about your app.
100
100
  *
101
101
  * https://vike.dev/getGlobalContext
102
- *
103
- * @deprecated
104
102
  */
105
103
  function getGlobalContextSync() {
106
104
  debug('getGlobalContextSync()');
107
105
  const { globalContext } = globalObjectTyped;
108
106
  assertUsage(globalContext, getGlobalContextSyncErrMsg);
109
- assertWarning(false,
110
- // We discourage users from using it because `pageContext.globalContext` is safer: I ain't sure but there could be race conditions when using `getGlobalContextSync()` inside React/Vue components upon HMR.
111
- // We're lying about "is going to be deprecated in the next major release": let's keep it and see if users need it (so far I can't see a use case for it).
112
- 'getGlobalContextSync() is going to be deprecated in the next major release, see https://vike.dev/getGlobalContext', { onlyOnce: true });
107
+ const isProd = globalContext._isProduction;
108
+ assert(typeof isProd === 'boolean');
109
+ assertWarning(isProd,
110
+ // - We discourage users from using it in development because `pageContext.globalContext` is safer: I ain't sure but there could be race conditions when using `getGlobalContextSync()` inside React/Vue components upon HMR.
111
+ // - I don't see any issues with getGlobalContextSync() in production.
112
+ // - getGlobalContextSync() is used in production by vike-vercel
113
+ // - https://discord.com/channels/@me/942519153502339072/1389546794676916344 (PM between Rom and Joël)
114
+ "getGlobalContextSync() shouldn't be used in development, see https://vike.dev/getGlobalContext", { onlyOnce: true });
113
115
  return getGlobalContextForPublicUsage();
114
116
  }
115
117
  function getGlobalContextForPublicUsage() {
@@ -148,7 +150,12 @@ function setGlobalContext_isPrerendering() {
148
150
  globalObject.isPrerendering = true;
149
151
  setIsProduction(true);
150
152
  }
151
- function setGlobalContext_isProduction(isProduction, tolerateContraditction) {
153
+ function setGlobalContext_isProduction(isProduction, tolerateContraditction = false) {
154
+ // TODO/now: try to remove globalObject.isProduction ?
155
+ // TODO/now: `rename tolerateContraditction tolerateContradiction`
156
+ tolerateContraditction = true;
157
+ if (debug.isActivated)
158
+ debug('setGlobalContext_isProduction()', { isProduction, tolerateContraditction });
152
159
  if (globalObject.isProduction === undefined) {
153
160
  setIsProduction(isProduction);
154
161
  }
@@ -197,7 +204,12 @@ async function initGlobalContext() {
197
204
  const { isProduction } = globalObject;
198
205
  assert(typeof isProduction === 'boolean');
199
206
  if (!isProduction) {
200
- await globalObject.viteDevServerPromise;
207
+ if (isProcessSharedWithVite()) {
208
+ await globalObject.viteDevServerPromise;
209
+ }
210
+ else {
211
+ await updateUserFiles();
212
+ }
201
213
  assert(globalObject.waitForUserFilesUpdate);
202
214
  await globalObject.waitForUserFilesUpdate;
203
215
  }
@@ -230,6 +242,7 @@ function assertViteManifest(manifest) {
230
242
  async function loadBuildEntry(outDir) {
231
243
  debug('loadBuildEntry()');
232
244
  if (globalObject.globalContext) {
245
+ debug('loadBuildEntry() - already done');
233
246
  return;
234
247
  }
235
248
  if (!globalObject.buildEntry) {
@@ -255,6 +268,8 @@ async function loadBuildEntry(outDir) {
255
268
  globalObject.buildInfo = buildEntry.buildInfo;
256
269
  await setGlobalContext(buildEntry.virtualFileExports);
257
270
  }
271
+ // This is the production entry, see:
272
+ // https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
258
273
  async function setGlobalContext_buildEntry(buildEntry) {
259
274
  debug('setGlobalContext_buildEntry()');
260
275
  setIsProduction(true);
@@ -264,6 +279,7 @@ async function setGlobalContext_buildEntry(buildEntry) {
264
279
  assert(globalObject.buildEntry); // ensure no infinite loop
265
280
  await loadBuildEntry();
266
281
  assertGlobalContextIsDefined();
282
+ debug('setGlobalContext_buildEntry() - done');
267
283
  }
268
284
  function assertBuildEntry(buildEntry) {
269
285
  assert(isObject(buildEntry));
@@ -327,16 +343,27 @@ async function updateUserFiles() {
327
343
  // Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
328
344
  viteDevServer !== globalObject.viteDevServer;
329
345
  const { viteDevServer } = globalObject;
330
- assert(viteDevServer);
331
346
  let hasError = false;
332
347
  let virtualFileExports;
333
348
  let err;
334
- try {
335
- virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileIdEntryServer);
349
+ if (viteDevServer) {
350
+ try {
351
+ virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileIdEntryServer);
352
+ }
353
+ catch (err_) {
354
+ hasError = true;
355
+ err = err_;
356
+ }
336
357
  }
337
- catch (err_) {
338
- hasError = true;
339
- err = err_;
358
+ else {
359
+ try {
360
+ // We don't directly use import() to workaround what seems to be a Vite HMR bug: using import() breaks the HMR of normal non-worker apps.
361
+ virtualFileExports = await __VIKE__DYNAMIC_IMPORT('virtual:vike:entry:server');
362
+ }
363
+ catch (err_) {
364
+ hasError = true;
365
+ err = err_;
366
+ }
340
367
  }
341
368
  if (isOutdated())
342
369
  return { success: false };
@@ -360,40 +387,46 @@ async function updateUserFiles() {
360
387
  return onSuccess();
361
388
  }
362
389
  async function setGlobalContext(virtualFileExports) {
390
+ debug('setGlobalContext()');
363
391
  assert(!getVikeConfigErrorBuild());
364
- const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext);
392
+ const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
365
393
  assertV1Design(
366
394
  // pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
367
395
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
368
396
  assertGlobalContextIsDefined();
369
397
  onSetupRuntime();
398
+ debug('setGlobalContext() - done');
370
399
  // Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
371
400
  return globalContext;
372
401
  }
373
- async function addGlobalContext(globalContext) {
402
+ async function addGlobalContextTmp(globalContext) {
403
+ debug('addGlobalContextTmp()');
374
404
  const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
405
+ return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
406
+ }
407
+ function addGlobalContext(globalContext) {
408
+ debug('addGlobalContext()');
409
+ const { pageRoutes, onBeforeRouteHook } = loadPageRoutesSync(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
410
+ return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
411
+ }
412
+ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
375
413
  const globalContextBase = {
376
414
  isClientSide: false,
377
415
  _pageRoutes: pageRoutes,
378
416
  _onBeforeRouteHook: onBeforeRouteHook,
379
417
  };
380
- const { viteDevServer, viteConfig, viteConfigRuntime, isPrerendering, isProduction } = globalObject;
418
+ const { viteDevServer, viteConfig, isPrerendering, isProduction } = globalObject;
381
419
  assert(typeof isProduction === 'boolean');
382
420
  if (!isProduction) {
383
- assert(viteDevServer);
384
421
  assert(globalContext); // main common requirement
385
- assert(viteConfig);
386
- assert(viteConfigRuntime);
387
422
  assert(!isPrerendering);
388
423
  return {
389
424
  ...globalContextBase,
390
- ...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
391
425
  _isProduction: false,
392
426
  _isPrerendering: false,
393
427
  assetsManifest: null,
394
428
  _viteDevServer: viteDevServer,
395
429
  viteConfig,
396
- viteConfigRuntime,
397
430
  };
398
431
  }
399
432
  else {
@@ -404,11 +437,9 @@ async function addGlobalContext(globalContext) {
404
437
  assert(assetsManifest);
405
438
  const globalContextBase2 = {
406
439
  ...globalContextBase,
407
- ...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
408
440
  _isProduction: true,
409
441
  assetsManifest,
410
442
  _viteDevServer: null,
411
- viteConfigRuntime: buildInfo.viteConfigRuntime,
412
443
  _usesClientRouter: buildInfo.usesClientRouter,
413
444
  };
414
445
  if (isPrerendering) {
@@ -428,14 +459,45 @@ async function addGlobalContext(globalContext) {
428
459
  }
429
460
  }
430
461
  }
462
+ async function addGlobalContextAsync(globalContext) {
463
+ debug('addGlobalContextAsync()');
464
+ let { viteConfigRuntime, buildInfo } = globalObject;
465
+ if (!viteConfigRuntime) {
466
+ if (buildInfo) {
467
+ viteConfigRuntime = buildInfo.viteConfigRuntime;
468
+ }
469
+ else {
470
+ if (!isProcessSharedWithVite()) {
471
+ if (!globalObject.isProduction) {
472
+ const rpc = getViteRPC();
473
+ viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
474
+ }
475
+ else {
476
+ assert(false); // production => globalObject.buildInfo should be set
477
+ }
478
+ }
479
+ else {
480
+ assert(false); // process shared with Vite => globalObject.viteConfigRuntime should be set
481
+ }
482
+ }
483
+ }
484
+ assert(viteConfigRuntime);
485
+ return {
486
+ viteConfigRuntime,
487
+ ...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
488
+ };
489
+ }
431
490
  function clearGlobalContext() {
432
491
  debug('clearGlobalContext()');
433
- objectReplace(globalObject, getInitialGlobalContext(), ['buildEntryPrevious']);
492
+ objectReplace(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
434
493
  }
435
- function getInitialGlobalContext() {
436
- debug('getInitialGlobalContext()');
494
+ function getInitialGlobalObject() {
495
+ const isProduction = getIsProductionStatic();
496
+ if (debug.isActivated)
497
+ debug('getInitialGlobalObject()', { isProduction });
437
498
  const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
438
499
  return {
500
+ isProduction,
439
501
  viteDevServerPromise,
440
502
  viteDevServerPromiseResolve,
441
503
  };
@@ -446,3 +508,22 @@ function resolveBaseRuntime(viteConfigRuntime, config) {
446
508
  const baseAssetsUnresolved = config.baseAssets ?? null;
447
509
  return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
448
510
  }
511
+ function getIsProductionStatic() {
512
+ // TODO/now add @ts-ignore comments
513
+ // @ts-ignore
514
+ if (!import.meta.env)
515
+ return undefined;
516
+ // @ts-ignore
517
+ const PROD = import.meta.env.PROD;
518
+ return PROD;
519
+ }
520
+ function isProcessSharedWithVite() {
521
+ const ret = globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE;
522
+ if (globalObject.isProcessSharedWithVite !== undefined) {
523
+ assert(globalObject.isProcessSharedWithVite === ret);
524
+ }
525
+ else {
526
+ globalObject.isProcessSharedWithVite = ret;
527
+ }
528
+ return ret;
529
+ }
@@ -1,4 +1,5 @@
1
1
  export { getViteDevScript };
2
+ import { getViteRPC } from '../../../../utils/getViteRPC.js';
2
3
  import { assert, assertUsage, assertWarning } from '../../utils.js';
3
4
  import pc from '@brillout/picocolors';
4
5
  const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
@@ -11,7 +12,13 @@ async function getViteDevScript(pageContext) {
11
12
  const fakeHtmlBegin = '<html> <head>'; // White space to test whether user is using a minifier
12
13
  const fakeHtmlEnd = '</head><body></body></html>';
13
14
  let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
14
- fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
15
+ if (viteDevServer) {
16
+ fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
17
+ }
18
+ else {
19
+ const rpc = getViteRPC();
20
+ fakeHtml = await rpc.transformIndexHtmlRPC(fakeHtml);
21
+ }
15
22
  assertUsage(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${pc.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
16
23
  assertUsage(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
17
24
  assertUsage(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
@@ -1,7 +1,7 @@
1
1
  export { injectAssets__public };
2
2
  import { assertUsage, assertWarning, castProp, hasProp } from '../../utils.js';
3
3
  import { injectHtmlTagsToString } from '../injectAssets.js';
4
- // TODO/v1-release: remove
4
+ // TO-DO/next-major-release: remove
5
5
  async function injectAssets__public(htmlString, pageContext) {
6
6
  assertWarning(false, '`_injectAssets()` is deprecated and will be removed.', { onlyOnce: true, showStackTrace: true });
7
7
  assertUsage(typeof htmlString === 'string', '[injectAssets(htmlString, pageContext)]: Argument `htmlString` should be a string.', { showStackTrace: true });
@@ -149,6 +149,8 @@ function getTagClosing(tag) {
149
149
  return tagClosing;
150
150
  }
151
151
  function injectAtPlaceholder(htmlFragment, htmlString, isFirst) {
152
+ // TO-DO/eventually: soft deprecate in favor of https://github.com/vikejs/vike/issues/695
153
+ // Used by BurdaForward https://github.com/vikejs/vike/discussions/2528#discussioncomment-13637156
152
154
  const placeholder = isFirst ? '__VITE_PLUGIN_SSR__ASSETS_FIRST__' : '__VITE_PLUGIN__SSR_ASSETS_LAST__';
153
155
  const parts = htmlString.split(placeholder);
154
156
  if (parts.length === 1)
@@ -2,19 +2,25 @@ export { getPageContextClientSerialized };
2
2
  export { getPageContextClientSerializedAbort };
3
3
  export { getGlobalContextClientSerialized };
4
4
  export type { PageContextSerialization };
5
+ export type { PassToClient };
5
6
  import type { UrlRedirect } from '../../../shared/route/abort.js';
6
7
  import type { GlobalContextServerInternal } from '../globalContext.js';
7
8
  type PageContextSerialization = {
8
9
  pageId: string;
9
10
  routeParams: Record<string, string>;
10
- _passToClient: string[];
11
+ _passToClient: PassToClient;
11
12
  is404: null | boolean;
12
13
  pageProps?: Record<string, unknown>;
13
14
  _pageContextInit: Record<string, unknown>;
14
15
  _globalContext: GlobalContextServerInternal;
16
+ isClientSideNavigation: boolean;
15
17
  };
16
18
  declare function getPageContextClientSerialized(pageContext: PageContextSerialization): string;
17
19
  declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization): string;
20
+ type PassToClient = (string | {
21
+ prop: string;
22
+ once?: boolean;
23
+ })[];
18
24
  declare function getPageContextClientSerializedAbort(pageContext: Record<string, unknown> & ({
19
25
  _urlRedirect: UrlRedirect;
20
26
  } | {
@@ -27,20 +27,41 @@ const passToClientBuiltInPageContext = [
27
27
  const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError];
28
28
  function getPageContextClientSerialized(pageContext) {
29
29
  const passToClientPageContext = getPassToClientPageContext(pageContext);
30
- const pageContextClient = applyPassToClient(passToClientPageContext, pageContext);
31
- if (passToClientPageContext.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
30
+ const getObj = (passToClientEntry) => {
31
+ if (passToClientEntry.once)
32
+ return undefined; // pass it to client-side globalContext
33
+ return { obj: pageContext, objName: 'pageContext' };
34
+ };
35
+ const res = applyPassToClient(passToClientPageContext, getObj);
36
+ const pageContextClient = res.objClient;
37
+ const pageContextClientProps = res.objClientProps;
38
+ if (pageContextClientProps.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
32
39
  pageContextClient[pageContextInitIsPassedToClient] = true;
33
40
  }
34
- const pageContextClientSerialized = serializeObject(pageContextClient, 'pageContext', passToClientPageContext);
41
+ const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj);
35
42
  return pageContextClientSerialized;
36
43
  }
37
44
  function getGlobalContextClientSerialized(pageContext) {
38
45
  const passToClient = pageContext._passToClient;
39
- const globalContextClient = applyPassToClient(passToClient, pageContext._globalContext);
40
- const globalContextClientSerialized = serializeObject(globalContextClient, 'globalContext', passToClient);
46
+ const globalContext = pageContext._globalContext;
47
+ const getObj = ({ prop, once }) => {
48
+ if (once && getPropVal(pageContext, prop)) {
49
+ assert(typeof pageContext.isClientSideNavigation === 'boolean');
50
+ if (!pageContext.isClientSideNavigation) {
51
+ return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
52
+ }
53
+ else {
54
+ return undefined; // already passed to client-side
55
+ }
56
+ }
57
+ return { obj: globalContext, objName: 'globalContext' };
58
+ };
59
+ const res = applyPassToClient(passToClient, getObj);
60
+ const globalContextClient = res.objClient;
61
+ const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj);
41
62
  return globalContextClientSerialized;
42
63
  }
43
- function serializeObject(obj, objName, passToClient) {
64
+ function serializeObject(obj, passToClient, getObj) {
44
65
  let serialized;
45
66
  try {
46
67
  serialized = serializeValue(obj);
@@ -49,11 +70,15 @@ function serializeObject(obj, objName, passToClient) {
49
70
  const h = (s) => pc.cyan(s);
50
71
  let hasWarned = false;
51
72
  const propsNonSerializable = [];
52
- passToClient.forEach((prop) => {
73
+ passToClient.forEach((entry) => {
74
+ const entryNormalized = normalizePassToClientEntry(entry);
75
+ const { prop } = entryNormalized;
53
76
  const res = getPropVal(obj, prop);
54
77
  if (!res)
55
78
  return;
56
79
  const { value } = res;
80
+ const { objName } = getObj(entryNormalized) ?? {};
81
+ assert(objName);
57
82
  const varName = `${objName}${getPropKeys(prop).map(getPropAccessNotation).join('')}`;
58
83
  try {
59
84
  serializeValue(value, varName);
@@ -103,7 +128,20 @@ function serializeObject(obj, objName, passToClient) {
103
128
  return serialized;
104
129
  }
105
130
  function serializeValue(value, varName) {
106
- return stringify(value, { forbidReactElements: true, valueName: varName });
131
+ return stringify(value, {
132
+ forbidReactElements: true,
133
+ valueName: varName,
134
+ // Prevent Google from crawling URLs in JSON:
135
+ // - https://github.com/vikejs/vike/discussions/2541#discussioncomment-13660198
136
+ // - https://github.com/vikejs/vike/discussions/2277
137
+ // - https://github.com/vikejs/vike/pull/2542
138
+ replacer(_key, value) {
139
+ if (typeof value === 'string' && value.startsWith('/')) {
140
+ // No need to use a reviver: https://github.com/brillout/json-serializer/blob/70fc8ed3741306391b51655b05df24e6963d1fdb/test/main.spec.ts#L74-L80
141
+ return { replacement: (value = '!' + value) };
142
+ }
143
+ },
144
+ });
107
145
  }
108
146
  function getPassToClientPageContext(pageContext) {
109
147
  let passToClient = [...pageContext._passToClient, ...passToClientBuiltInPageContext];
@@ -139,7 +177,7 @@ function getPageContextClientSerializedAbort(pageContext) {
139
177
  assert(unknownProps.length === 0);
140
178
  }
141
179
  else {
142
- // TODO/v1-release: remove
180
+ // TO-DO/next-major-release: remove
143
181
  assertWarning(unknownProps.length === 0, [
144
182
  "The following pageContext values won't be available on the client-side:",
145
183
  unknownProps.map((p) => ` pageContext[${JSON.stringify(p)}]`),
@@ -150,16 +188,36 @@ function getPageContextClientSerializedAbort(pageContext) {
150
188
  }
151
189
  return serializeValue(pageContext);
152
190
  }
153
- function applyPassToClient(passToClient, pageContext) {
154
- const pageContextClient = {};
155
- passToClient.forEach((prop) => {
191
+ function applyPassToClient(passToClient, getObj) {
192
+ const objClient = {};
193
+ const objClientProps = [];
194
+ passToClient.forEach((entry) => {
195
+ const entryNormalized = normalizePassToClientEntry(entry);
196
+ const { prop } = entryNormalized;
197
+ const { obj } = getObj(entryNormalized) ?? {};
198
+ if (!obj)
199
+ return;
156
200
  // Get value from pageContext
157
- const res = getPropVal(pageContext, prop);
201
+ const res = getPropVal(obj, prop);
158
202
  if (!res)
159
203
  return;
160
204
  const { value } = res;
161
205
  // Set value to pageContextClient
162
- setPropVal(pageContextClient, prop, value);
206
+ setPropVal(objClient, prop, value);
207
+ objClientProps.push(prop);
163
208
  });
164
- return pageContextClient;
209
+ return { objClient, objClientProps };
210
+ }
211
+ function normalizePassToClientEntry(entry) {
212
+ let once;
213
+ let prop;
214
+ if (typeof entry === 'string') {
215
+ prop = entry;
216
+ once = false;
217
+ }
218
+ else {
219
+ prop = entry.prop;
220
+ once = entry.once ?? false;
221
+ }
222
+ return { prop, once };
165
223
  }
@@ -1,4 +1,4 @@
1
- // TO-DO/soon: point package.json#exports['./server'] to this file.
1
+ // TO-DO/eventually: point package.json#exports['./server'] to this file.
2
2
  // - Write migration guide, see comment below.
3
3
  export * from './index.js';
4
4
  import { assertWarning } from './utils.js';
@@ -7,7 +7,7 @@ export { pipeWebStream, pipeNodeStream, pipeStream, stampPipe } from './html/str
7
7
  export { PROJECT_VERSION as version } from './utils.js';
8
8
  export { getGlobalContext, getGlobalContextSync, getGlobalContextAsync } from './globalContext.js';
9
9
  export { createDevMiddleware } from '../runtime-dev/index.js';
10
- // TODO/v1-release: remove
10
+ // TO-DO/next-major-release: remove
11
11
  // Deprecated exports
12
12
  export * from '../../types/index-dreprecated.js';
13
13
  export { injectAssets__public as _injectAssets } from './html/injectAssets/injectAssets__public.js';
@@ -1,3 +1,3 @@
1
1
  export {};
2
- // TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
2
+ // TO-DO/next-major-release: remove https://github.com/vikejs/vike/issues/2122
3
3
  // This doesn't do anything anymore. (It's kept to avoid introducing a breaking change.)
@@ -10,7 +10,7 @@ function assertArguments(...args) {
10
10
  showStackTrace: true,
11
11
  });
12
12
  assertUsage(isObject(pageContextInit), `${prefix} called with ${pc.code(`typeof pageContextInit === ${JSON.stringify(typeof pageContextInit)}`)} but ${pc.code('pageContextInit')} should be an object.`, { showStackTrace: true });
13
- // TODO/v1-release: remove
13
+ // TO-DO/next-major-release: remove
14
14
  if ('url' in pageContextInit) {
15
15
  assertWarning(false, '`pageContextInit.url` has been renamed to `pageContextInit.urlOriginal`: replace `renderPage({ url })` with `renderPage({ urlOriginal })`. (See https://vike.dev/migration/0.4.23 for more information.)', { showStackTrace: true, onlyOnce: true });
16
16
  pageContextInit.urlOriginal = pageContextInit.url;
@@ -28,6 +28,7 @@ declare function createHttpResponsePage(htmlRender: HtmlRender, renderHook: null
28
28
  __getPageAssets: GetPageAssets;
29
29
  _globalContext: GlobalContextServerInternal;
30
30
  abortStatusCode?: AbortStatusCode;
31
+ headersResponse?: Headers;
31
32
  }): Promise<HttpResponse>;
32
33
  declare function createHttpResponse404(errMsg404: string): HttpResponse;
33
34
  declare function createHttpResponseBaseIsMissing(urlOriginal: string, baseServer: string): HttpResponse;
@@ -9,8 +9,8 @@ import { assert, assertWarning, escapeHtml } from '../utils.js';
9
9
  import { getErrorPageId, isErrorPage } from '../../../shared/error-page.js';
10
10
  import { getHttpResponseBody, getHttpResponseBodyStreamHandlers } from './getHttpResponseBody.js';
11
11
  import { getEarlyHints } from './getEarlyHints.js';
12
- import { getCacheControl } from './createHttpResponse/getCacheControl.js';
13
12
  import { assertNoInfiniteHttpRedirect } from './createHttpResponse/assertNoInfiniteHttpRedirect.js';
13
+ import { cacheControlDisable } from './getCacheControl.js';
14
14
  async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
15
15
  let statusCode = pageContext.abortStatusCode;
16
16
  if (!statusCode) {
@@ -29,10 +29,13 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
29
29
  }
30
30
  const earlyHints = getEarlyHints(await pageContext.__getPageAssets());
31
31
  const headers = [];
32
- const cacheControl = getCacheControl(pageContext.pageId, pageContext._globalContext._pageConfigs, statusCode);
33
- if (cacheControl) {
34
- headers.push(['Cache-Control', cacheControl]);
35
- }
32
+ const headersResponse = pageContext.headersResponse || new Headers();
33
+ headersResponse.forEach((value, key) => {
34
+ headers.push([key, value]);
35
+ });
36
+ // An 5xx error page shouldn't be cached (it should be temporary)
37
+ if (statusCode >= 500)
38
+ headersResponse.set('Cache-Control', cacheControlDisable);
36
39
  return createHttpResponse(statusCode, 'text/html;charset=utf-8', headers, htmlRender, earlyHints, renderHook);
37
40
  }
38
41
  function createHttpResponse404(errMsg404) {
@@ -102,7 +105,7 @@ function createHttpResponse(statusCode, contentType, headers, htmlRender, earlyH
102
105
  return {
103
106
  statusCode,
104
107
  headers,
105
- // TODO/v1-release: remove
108
+ // TO-DO/next-major-release: remove
106
109
  get contentType() {
107
110
  assertWarning(false, 'pageContext.httpResponse.contentType is deprecated and will be removed in the next major release. Use pageContext.httpResponse.headers instead, see https://vike.dev/migration/0.4.134', { onlyOnce: true });
108
111
  return contentType;