vike 0.4.235-commit-7b1ab35 → 0.4.235-commit-9b9289b

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 (44) hide show
  1. package/dist/cjs/node/runtime/globalContext.js +18 -6
  2. package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +2 -0
  3. package/dist/cjs/node/runtime/html/serializeContext.js +14 -1
  4. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -7
  5. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +8 -5
  6. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +25 -0
  7. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
  8. package/dist/cjs/node/runtime/renderPage.js +1 -0
  9. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +4 -0
  10. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
  11. package/dist/cjs/shared/createGlobalContextShared.js +18 -7
  12. package/dist/cjs/shared/route/loadPageRoutes.js +7 -1
  13. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  14. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +8 -0
  15. package/dist/esm/client/runtime-client-routing/history.d.ts +4 -2
  16. package/dist/esm/client/runtime-client-routing/history.js +13 -35
  17. package/dist/esm/client/runtime-client-routing/initClientRouter.js +3 -2
  18. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +2 -0
  19. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +2 -2
  20. package/dist/esm/node/prerender/runPrerender.d.ts +1 -0
  21. package/dist/esm/node/runtime/globalContext.d.ts +14 -12
  22. package/dist/esm/node/runtime/globalContext.js +20 -8
  23. package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +2 -0
  24. package/dist/esm/node/runtime/html/serializeContext.js +14 -1
  25. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +3 -3
  26. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -7
  27. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -0
  28. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +8 -5
  29. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +5 -2
  30. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +25 -0
  31. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +2 -0
  32. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
  33. package/dist/esm/node/runtime/renderPage.js +1 -0
  34. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +4 -0
  35. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
  36. package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
  37. package/dist/esm/shared/createGlobalContextShared.js +18 -7
  38. package/dist/esm/shared/route/loadPageRoutes.d.ts +5 -0
  39. package/dist/esm/shared/route/loadPageRoutes.js +7 -1
  40. package/dist/esm/types/Config.d.ts +7 -0
  41. package/dist/esm/types/PageContext.d.ts +8 -2
  42. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  43. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  44. package/package.json +2 -2
@@ -42,7 +42,7 @@ const loggerRuntime_js_1 = require("./loggerRuntime.js");
42
42
  const getVikeConfigError_js_1 = require("../shared/getVikeConfigError.js");
43
43
  const isNewError_js_1 = require("./renderPage/isNewError.js");
44
44
  const debug = (0, utils_js_1.createDebugger)('vike:globalContext');
45
- const globalObject = (0, utils_js_1.getGlobalObject)('runtime/globalContext.ts', getInitialGlobalContext());
45
+ const globalObject = (0, utils_js_1.getGlobalObject)('runtime/globalContext.ts', getInitialGlobalObject());
46
46
  // Trick to break down TypeScript circular dependency
47
47
  // https://chat.deepseek.com/a/chat/s/d7e9f90a-c7f3-4108-9cd5-4ad6caed3539
48
48
  const globalObjectTyped = globalObject;
@@ -236,6 +236,7 @@ function assertViteManifest(manifest) {
236
236
  async function loadBuildEntry(outDir) {
237
237
  debug('loadBuildEntry()');
238
238
  if (globalObject.globalContext) {
239
+ debug('loadBuildEntry() - already done');
239
240
  return;
240
241
  }
241
242
  if (!globalObject.buildEntry) {
@@ -261,6 +262,8 @@ async function loadBuildEntry(outDir) {
261
262
  globalObject.buildInfo = buildEntry.buildInfo;
262
263
  await setGlobalContext(buildEntry.virtualFileExports);
263
264
  }
265
+ // This is the production entry, see:
266
+ // https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
264
267
  async function setGlobalContext_buildEntry(buildEntry) {
265
268
  debug('setGlobalContext_buildEntry()');
266
269
  setIsProduction(true);
@@ -270,6 +273,7 @@ async function setGlobalContext_buildEntry(buildEntry) {
270
273
  (0, utils_js_1.assert)(globalObject.buildEntry); // ensure no infinite loop
271
274
  await loadBuildEntry();
272
275
  assertGlobalContextIsDefined();
276
+ debug('setGlobalContext_buildEntry() - done');
273
277
  }
274
278
  function assertBuildEntry(buildEntry) {
275
279
  (0, utils_js_1.assert)((0, utils_js_1.isObject)(buildEntry));
@@ -366,8 +370,9 @@ async function updateUserFiles() {
366
370
  return onSuccess();
367
371
  }
368
372
  async function setGlobalContext(virtualFileExports) {
373
+ debug('setGlobalContext()');
369
374
  (0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
370
- const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext);
375
+ const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContextAsync, addGlobalContextSync);
371
376
  (0, assertV1Design_js_1.assertV1Design)(
372
377
  // pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
373
378
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
@@ -376,8 +381,15 @@ async function setGlobalContext(virtualFileExports) {
376
381
  // Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
377
382
  return globalContext;
378
383
  }
379
- async function addGlobalContext(globalContext) {
384
+ async function addGlobalContextAsync(globalContext) {
380
385
  const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
386
+ return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
387
+ }
388
+ function addGlobalContextSync(globalContext) {
389
+ const { pageRoutes, onBeforeRouteHook } = (0, loadPageRoutes_js_1.loadPageRoutesSync)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
390
+ return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
391
+ }
392
+ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
381
393
  const globalContextBase = {
382
394
  isClientSide: false,
383
395
  _pageRoutes: pageRoutes,
@@ -436,10 +448,10 @@ async function addGlobalContext(globalContext) {
436
448
  }
437
449
  function clearGlobalContext() {
438
450
  debug('clearGlobalContext()');
439
- (0, utils_js_1.objectReplace)(globalObject, getInitialGlobalContext(), ['buildEntryPrevious']);
451
+ (0, utils_js_1.objectReplace)(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
440
452
  }
441
- function getInitialGlobalContext() {
442
- debug('getInitialGlobalContext()');
453
+ function getInitialGlobalObject() {
454
+ debug('getInitialGlobalObject()');
443
455
  const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = (0, utils_js_1.genPromise)();
444
456
  return {
445
457
  viteDevServerPromise,
@@ -150,6 +150,8 @@ function getTagClosing(tag) {
150
150
  return tagClosing;
151
151
  }
152
152
  function injectAtPlaceholder(htmlFragment, htmlString, isFirst) {
153
+ // TO-DO/eventually: soft deprecate in favor of https://github.com/vikejs/vike/issues/695
154
+ // Used by BurdaForward https://github.com/vikejs/vike/discussions/2528#discussioncomment-13637156
153
155
  const placeholder = isFirst ? '__VITE_PLUGIN_SSR__ASSETS_FIRST__' : '__VITE_PLUGIN__SSR_ASSETS_LAST__';
154
156
  const parts = htmlString.split(placeholder);
155
157
  if (parts.length === 1)
@@ -108,7 +108,20 @@ function serializeObject(obj, objName, passToClient) {
108
108
  return serialized;
109
109
  }
110
110
  function serializeValue(value, varName) {
111
- return (0, stringify_1.stringify)(value, { forbidReactElements: true, valueName: varName });
111
+ return (0, stringify_1.stringify)(value, {
112
+ forbidReactElements: true,
113
+ valueName: varName,
114
+ // Prevent Google from crawling URLs in JSON:
115
+ // - https://github.com/vikejs/vike/discussions/2541#discussioncomment-13660198
116
+ // - https://github.com/vikejs/vike/discussions/2277
117
+ // - https://github.com/vikejs/vike/pull/2542
118
+ replacer(_key, value) {
119
+ if (typeof value === 'string' && value.startsWith('/')) {
120
+ // No need to use a reviver: https://github.com/brillout/json-serializer/blob/70fc8ed3741306391b51655b05df24e6963d1fdb/test/main.spec.ts#L74-L80
121
+ return { replacement: (value = '!' + value) };
122
+ }
123
+ },
124
+ });
112
125
  }
113
126
  function getPassToClientPageContext(pageContext) {
114
127
  let passToClient = [...pageContext._passToClient, ...passToClientBuiltInPageContext];
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cacheControlDisable = void 0;
3
4
  exports.getCacheControl = getCacheControl;
4
5
  const helpers_js_1 = require("../../../../shared/page-configs/helpers.js");
5
6
  const getConfigValueRuntime_js_1 = require("../../../../shared/page-configs/getConfigValueRuntime.js");
6
- const defaultValue = 'no-store, max-age=0';
7
- function getCacheControl(pageId, pageConfigs, statusCode) {
8
- // TO-DO/next-major-release: remove
7
+ const cacheControlDisable = 'no-store, max-age=0';
8
+ exports.cacheControlDisable = cacheControlDisable;
9
+ function getCacheControl(pageId, pageConfigs) {
10
+ // TO-DO/next-major-release: remove this line
9
11
  if (pageConfigs.length === 0)
10
- return defaultValue;
11
- if (statusCode > 499)
12
- return defaultValue;
12
+ return cacheControlDisable;
13
13
  if (pageId) {
14
14
  const pageConfig = (0, helpers_js_1.getPageConfig)(pageId, pageConfigs);
15
15
  const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'cacheControl', 'string');
@@ -20,5 +20,5 @@ function getCacheControl(pageId, pageConfigs, statusCode) {
20
20
  // - Disabling caching by default is the safest strategy, because caching is problematic with authentication as described in https://github.com/vikejs/vike/issues/1275#issuecomment-1824366875
21
21
  // - Are there use cases when we don't need to disable caching?
22
22
  // - When there isn't any <script id="vike_pageContext" type="application/json"> then we can safely have caching. (We don't implement this exception because we're lazy and it's quite a rare situation.)
23
- return defaultValue;
23
+ return cacheControlDisable;
24
24
  }
@@ -11,8 +11,8 @@ const utils_js_1 = require("../utils.js");
11
11
  const error_page_js_1 = require("../../../shared/error-page.js");
12
12
  const getHttpResponseBody_js_1 = require("./getHttpResponseBody.js");
13
13
  const getEarlyHints_js_1 = require("./getEarlyHints.js");
14
- const getCacheControl_js_1 = require("./createHttpResponse/getCacheControl.js");
15
14
  const assertNoInfiniteHttpRedirect_js_1 = require("./createHttpResponse/assertNoInfiniteHttpRedirect.js");
15
+ const getCacheControl_js_1 = require("./createHttpResponse/getCacheControl.js");
16
16
  async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
17
17
  let statusCode = pageContext.abortStatusCode;
18
18
  if (!statusCode) {
@@ -31,10 +31,13 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
31
31
  }
32
32
  const earlyHints = (0, getEarlyHints_js_1.getEarlyHints)(await pageContext.__getPageAssets());
33
33
  const headers = [];
34
- const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._globalContext._pageConfigs, statusCode);
35
- if (cacheControl) {
36
- headers.push(['Cache-Control', cacheControl]);
37
- }
34
+ const headersResponse = pageContext.headersResponse || new Headers();
35
+ headersResponse.forEach((value, key) => {
36
+ headers.push([key, value]);
37
+ });
38
+ // An 5xx error page shouldn't be cached (it should be temporary)
39
+ if (statusCode >= 500)
40
+ headersResponse.set('Cache-Control', getCacheControl_js_1.cacheControlDisable);
38
41
  return createHttpResponse(statusCode, 'text/html;charset=utf-8', headers, htmlRender, earlyHints, renderHook);
39
42
  }
40
43
  function createHttpResponse404(errMsg404) {
@@ -11,12 +11,15 @@ const findPageConfig_js_1 = require("../../../shared/page-configs/findPageConfig
11
11
  const analyzePage_js_1 = require("./analyzePage.js");
12
12
  const loadConfigValues_js_1 = require("../../../shared/page-configs/loadConfigValues.js");
13
13
  const execHookServer_js_1 = require("./execHookServer.js");
14
+ const getCacheControl_js_1 = require("./createHttpResponse/getCacheControl.js");
15
+ // TODO/now: rename?
14
16
  async function loadPageConfigsLazyServerSideAndExecHook(pageContext) {
15
17
  const pageContextAddendum = await loadPageConfigsLazyServerSide(pageContext);
16
18
  (0, utils_js_1.objectAssign)(pageContext, pageContextAddendum);
17
19
  await (0, execHookServer_js_1.execHookServer)('onCreatePageContext', pageContext);
18
20
  return pageContext;
19
21
  }
22
+ // TODO/now: rename?
20
23
  async function loadPageConfigsLazyServerSide(pageContext) {
21
24
  const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._globalContext._pageConfigs, pageContext.pageId); // Make pageConfig globally available as pageContext._pageConfig ?
22
25
  const globalContext = pageContext._globalContext;
@@ -50,6 +53,7 @@ async function loadPageConfigsLazyServerSide(pageContext) {
50
53
  _isHtmlOnly: isHtmlOnly,
51
54
  _passToClient: passToClient,
52
55
  _pageFilePathsLoaded: pageFilesLoaded.map((p) => p.filePath),
56
+ headersResponse: resolveHeadersResponse(pageContext, pageContextAddendum),
53
57
  });
54
58
  (0, utils_js_1.objectAssign)(pageContextAddendum, {
55
59
  __getPageAssets: async () => {
@@ -102,6 +106,7 @@ async function loadPageConfigsLazyServerSide(pageContext) {
102
106
  });
103
107
  return pageContextAddendum;
104
108
  }
109
+ // TODO/now: rename?
105
110
  async function loadPageUserFiles(pageFilesAll, pageConfig, pageConfigGlobal, pageId, isDev) {
106
111
  const pageFilesServerSide = (0, getPageFiles_js_1.getPageFilesServerSide)(pageFilesAll, pageId);
107
112
  const pageConfigLoaded = !pageConfig ? null : await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, isDev);
@@ -112,3 +117,23 @@ async function loadPageUserFiles(pageFilesAll, pageConfig, pageConfigGlobal, pag
112
117
  pageFilesLoaded: pageFilesServerSide,
113
118
  };
114
119
  }
120
+ function resolveHeadersResponse(
121
+ // TODO/now: merge pageContextAddendum with pageContext
122
+ pageContext, pageContextAddendum) {
123
+ const headersResponse = mergeHeaders(pageContextAddendum.config.headersResponse);
124
+ if (!headersResponse.get('Cache-Control')) {
125
+ const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._globalContext._pageConfigs);
126
+ if (cacheControl)
127
+ headersResponse.set('Cache-Control', cacheControl);
128
+ }
129
+ return headersResponse;
130
+ }
131
+ function mergeHeaders(headersList = []) {
132
+ const headersMerged = new Headers();
133
+ headersList.forEach((headers) => {
134
+ new Headers(headers).forEach((value, key) => {
135
+ headersMerged.append(key, value);
136
+ });
137
+ });
138
+ return headersMerged;
139
+ }
@@ -19,6 +19,7 @@ const preparePageContextForPublicUsageServer_js_1 = require("./preparePageContex
19
19
  const execHookGuard_js_1 = require("../../../shared/route/execHookGuard.js");
20
20
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
21
21
  const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
22
+ // TODO/now: rename?
22
23
  async function renderPageAlreadyRouted(pageContext) {
23
24
  // pageContext.pageId can either be the:
24
25
  // - ID of the page matching the routing, or the
@@ -175,6 +175,7 @@ async function renderPageOnError(errNominalPage, pageContextBegin, pageContextNo
175
175
  return (0, handleErrorWithoutErrorPage_js_1.handleErrorWithoutErrorPage)(pageContextErrorPageInit);
176
176
  }
177
177
  else {
178
+ // TODO/now: minor refactor
178
179
  (0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: errorPageId });
179
180
  }
180
181
  }
@@ -212,6 +212,10 @@ const configDefinitionsBuiltIn = {
212
212
  env: { server: true },
213
213
  global: true,
214
214
  },
215
+ headersResponse: {
216
+ env: { server: true },
217
+ cumulative: true,
218
+ },
215
219
  };
216
220
  exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
217
221
  function getConfigEnv(configValueSources, configName) {
@@ -36,12 +36,10 @@ function getFilesystemRouteString(locationId) {
36
36
  function getInheritanceRoot(locationId) {
37
37
  return getLogicalPath(locationId, [
38
38
  'renderer',
39
- // - Enable hooks defined by vike-{react,vue,solid} such as +onBeforeRenderClient to be defined at the root directory. In other words, avoid following error:
40
- // ```bash
41
- // [11:09:43.072][/test-preview.test.ts][npm run preview][stderr] Error: [vike][Wrong Usage] /+onBeforeRenderClient.ts sets the value of the config onBeforeRenderClient which is a custom config that is defined with https://vike.dev/meta at a path that doesn't apply to / — see https://vike.dev/config#inheritance
42
- // ```
43
- // - Not sure if it's a good idea? Could it make config inheritance confusing? Let's try for now and see how it goes.
44
- // - TO-DO/eventually: update docs https://github.com/vikejs/vike/blob/5fcdc4d5094f1a4dcbefc0b481cdd30a205aef2d/docs/pages/filesystem-routing/%2BPage.mdx?plain=1#L98
39
+ // Enable hooks defined by vike-{react,vue,solid} such as +onBeforeRenderClient to be defined at the root directory. In other words, avoid following error:
40
+ // ```bash
41
+ // [11:09:43.072][/test-preview.test.ts][npm run preview][stderr] Error: [vike][Wrong Usage] /+onBeforeRenderClient.ts sets the value of the config onBeforeRenderClient which is a custom config that is defined with https://vike.dev/meta at a path that doesn't apply to / — see https://vike.dev/config#inheritance
42
+ // ```
45
43
  'pages',
46
44
  ]);
47
45
  }
@@ -10,10 +10,24 @@ const prepareGlobalContextForPublicUsage_js_1 = require("./prepareGlobalContextF
10
10
  const getHook_js_1 = require("./hooks/getHook.js");
11
11
  const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
12
12
  exports.getGlobalContextSyncErrMsg = getGlobalContextSyncErrMsg;
13
- async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext) {
13
+ async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContextAsync, addGlobalContextSync) {
14
14
  const globalContext = createGlobalContextBase(virtualFileExports);
15
- const globalContextAddendum = await addGlobalContext?.(globalContext);
16
- (0, utils_js_1.objectAssign)(globalContext, globalContextAddendum);
15
+ let isNewGlobalContext;
16
+ if (!globalObject.globalContext) {
17
+ globalObject.globalContext = globalContext;
18
+ isNewGlobalContext = false;
19
+ }
20
+ else {
21
+ isNewGlobalContext = true;
22
+ }
23
+ if (addGlobalContextSync && globalContext._pageConfigs.length > 0) {
24
+ const globalContextAddendum = addGlobalContextSync?.(globalContext);
25
+ (0, utils_js_1.objectAssign)(globalContext, globalContextAddendum);
26
+ }
27
+ else {
28
+ const globalContextAddendum = await addGlobalContextAsync?.(globalContext);
29
+ (0, utils_js_1.objectAssign)(globalContext, globalContextAddendum);
30
+ }
17
31
  const onCreateGlobalContextHooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
18
32
  let hooksCalled = false;
19
33
  if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
@@ -21,10 +35,7 @@ async function createGlobalContextShared(virtualFileExports, globalObject, addGl
21
35
  await (0, execHook_js_1.execHookGlobal)('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage);
22
36
  hooksCalled = true;
23
37
  }
24
- if (!globalObject.globalContext) {
25
- globalObject.globalContext = globalContext;
26
- }
27
- else {
38
+ if (isNewGlobalContext) {
28
39
  // Singleton: ensure all `globalContext` user-land references are preserved & updated.
29
40
  if (hooksCalled) {
30
41
  (0, utils_js_1.objectReplace)(globalObject.globalContext, globalContext);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadPageRoutes = loadPageRoutes;
4
+ exports.loadPageRoutesSync = loadPageRoutesSync;
4
5
  const error_page_js_1 = require("../error-page.js");
5
6
  const utils_js_1 = require("./utils.js");
6
7
  const deduceRouteStringFromFilesystemPath_js_1 = require("./deduceRouteStringFromFilesystemPath.js");
@@ -12,8 +13,13 @@ const getHook_js_1 = require("../hooks/getHook.js");
12
13
  async function loadPageRoutes(
13
14
  // Remove all arguments and use GlobalContextServerInternal instead?
14
15
  pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
15
- // TO-DO/next-major-release: remove & make this function sync
16
+ // TO-DO/next-major-release: remove this line, remove this function, rename loadPageRoutesSync() to loadPageRoutes()
16
17
  await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
18
+ return loadPageRoutesSync(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
19
+ }
20
+ function loadPageRoutesSync(
21
+ // Remove all arguments and use GlobalContextServerInternal instead?
22
+ pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
17
23
  const { onBeforeRouteHook, filesystemRoots } = getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal);
18
24
  const pageRoutes = getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds);
19
25
  return { pageRoutes, onBeforeRouteHook };
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.235-commit-7b1ab35';
5
+ exports.PROJECT_VERSION = '0.4.235-commit-9b9289b';
@@ -85,6 +85,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
85
85
  urlOriginal: string;
86
86
  headers: Record<string, string> | null;
87
87
  headersOriginal?: unknown;
88
+ headersResponse: Headers;
88
89
  is404: boolean | null;
89
90
  isClientSideNavigation: boolean;
90
91
  abortReason?: unknown;
@@ -109,6 +110,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
109
110
  urlOriginal: string;
110
111
  headers: Record<string, string> | null;
111
112
  headersOriginal?: unknown;
113
+ headersResponse: Headers;
112
114
  is404: boolean | null;
113
115
  isClientSideNavigation: boolean;
114
116
  abortReason?: unknown;
@@ -156,6 +158,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
156
158
  urlOriginal: string;
157
159
  headers: Record<string, string> | null;
158
160
  headersOriginal?: unknown;
161
+ headersResponse: Headers;
159
162
  is404: boolean | null;
160
163
  isClientSideNavigation: boolean;
161
164
  abortReason?: unknown;
@@ -180,6 +183,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
180
183
  urlOriginal: string;
181
184
  headers: Record<string, string> | null;
182
185
  headersOriginal?: unknown;
186
+ headersResponse: Headers;
183
187
  is404: boolean | null;
184
188
  isClientSideNavigation: boolean;
185
189
  abortReason?: unknown;
@@ -295,6 +299,7 @@ declare function getPageContextFromClientHooks(pageContext: {
295
299
  urlOriginal: string;
296
300
  headers: Record<string, string> | null;
297
301
  headersOriginal?: unknown;
302
+ headersResponse: Headers;
298
303
  is404: boolean | null;
299
304
  isClientSideNavigation: boolean;
300
305
  abortReason?: unknown;
@@ -319,6 +324,7 @@ declare function getPageContextFromClientHooks(pageContext: {
319
324
  urlOriginal: string;
320
325
  headers: Record<string, string> | null;
321
326
  headersOriginal?: unknown;
327
+ headersResponse: Headers;
322
328
  is404: boolean | null;
323
329
  isClientSideNavigation: boolean;
324
330
  abortReason?: unknown;
@@ -364,6 +370,7 @@ declare function getPageContextFromClientHooks(pageContext: {
364
370
  urlOriginal: string;
365
371
  headers: Record<string, string> | null;
366
372
  headersOriginal?: unknown;
373
+ headersResponse: Headers;
367
374
  is404: boolean | null;
368
375
  isClientSideNavigation: boolean;
369
376
  abortReason?: unknown;
@@ -388,6 +395,7 @@ declare function getPageContextFromClientHooks(pageContext: {
388
395
  urlOriginal: string;
389
396
  headers: Record<string, string> | null;
390
397
  headersOriginal?: unknown;
398
+ headersResponse: Headers;
391
399
  is404: boolean | null;
392
400
  isClientSideNavigation: boolean;
393
401
  abortReason?: unknown;
@@ -2,7 +2,8 @@ export { pushHistoryState };
2
2
  export { replaceHistoryStateOriginal };
3
3
  export { onPopStateBegin };
4
4
  export { saveScrollPosition };
5
- export { initHistory };
5
+ export { initHistoryState };
6
+ export { monkeyPatchHistoryAPI };
6
7
  export type { HistoryInfo };
7
8
  export type { ScrollPosition };
8
9
  type StateEnhanced = {
@@ -18,6 +19,7 @@ type ScrollPosition = {
18
19
  declare function saveScrollPosition(): void;
19
20
  declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
20
21
  declare function replaceHistoryStateOriginal(state: unknown, url: string): void;
22
+ declare function monkeyPatchHistoryAPI(): void;
21
23
  type HistoryInfo = {
22
24
  url: `/${string}`;
23
25
  state: StateEnhanced;
@@ -27,4 +29,4 @@ declare function onPopStateBegin(): {
27
29
  previous: HistoryInfo;
28
30
  current: HistoryInfo;
29
31
  };
30
- declare function initHistory(): void;
32
+ declare function initHistoryState(): void;
@@ -2,15 +2,12 @@ export { pushHistoryState };
2
2
  export { replaceHistoryStateOriginal };
3
3
  export { onPopStateBegin };
4
4
  export { saveScrollPosition };
5
- export { initHistory };
5
+ export { initHistoryState };
6
+ export { monkeyPatchHistoryAPI };
6
7
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
7
8
  import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
8
- const globalObject = getGlobalObject('history.ts', {
9
- monkeyPatched: false,
10
- previous: undefined,
11
- });
12
- initHistory(); // we redundantly call initHistory() to ensure it's called early
13
- globalObject.previous = getHistoryInfo();
9
+ initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
10
+ const globalObject = getGlobalObject('runtime-client-routing/history.ts', { previous: getHistoryInfo() });
14
11
  // `window.history.state === null` when:
15
12
  // - The very first render
16
13
  // - Click on `<a href="#some-hash" />`
@@ -44,7 +41,7 @@ function enhance(stateNotEnhanced) {
44
41
  _isVikeEnhanced: true,
45
42
  };
46
43
  }
47
- assertIsVikeEnhanced(stateVikeEnhanced);
44
+ assert(isVikeEnhanced(stateVikeEnhanced));
48
45
  return stateVikeEnhanced;
49
46
  }
50
47
  function getState() {
@@ -54,7 +51,7 @@ function getState() {
54
51
  // - Therefore, we have to monkey patch history.pushState() and history.replaceState()
55
52
  // - Therefore, we need the assert() below to ensure history.state has been enhanced by Vike
56
53
  // - If users stumble upon this assert() then let's make it a assertUsage()
57
- assertIsVikeEnhanced(state);
54
+ assert(isVikeEnhanced(state), { state });
58
55
  return state;
59
56
  }
60
57
  function getStateNotEnhanced() {
@@ -93,7 +90,6 @@ function pushHistoryState(url, overwriteLastHistoryEntry) {
93
90
  function replaceHistoryState(state, url) {
94
91
  const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
95
92
  window.history.replaceState(state, '', url_);
96
- assertIsVikeEnhanced(getState());
97
93
  }
98
94
  function replaceHistoryStateOriginal(state, url) {
99
95
  // Bypass all monkey patches.
@@ -104,11 +100,7 @@ function replaceHistoryStateOriginal(state, url) {
104
100
  // - history.pushState()
105
101
  // - history.replaceState()
106
102
  function monkeyPatchHistoryAPI() {
107
- if (globalObject.monkeyPatched)
108
- return;
109
- globalObject.monkeyPatched = true;
110
- // Ensure Vike's monkey patch is the first.
111
- assert(window.history.pushState === History.prototype.pushState);
103
+ ;
112
104
  ['pushState', 'replaceState'].forEach((funcName) => {
113
105
  const funcOriginal = window.history[funcName].bind(window.history);
114
106
  window.history[funcName] = (stateOriginal = {}, ...rest) => {
@@ -122,14 +114,11 @@ function monkeyPatchHistoryAPI() {
122
114
  triggeredBy: 'user',
123
115
  ...stateOriginal,
124
116
  };
125
- assertIsVikeEnhanced(stateEnhanced);
126
- funcOriginal(stateEnhanced, ...rest);
127
- assertIsVikeEnhanced(getState());
117
+ assert(isVikeEnhanced(stateEnhanced));
118
+ const ret = funcOriginal(stateEnhanced, ...rest);
128
119
  globalObject.previous = getHistoryInfo();
120
+ return ret;
129
121
  };
130
- window.history[funcName]._isVikeMonkeyPatch = true;
131
- // Ensure assert() above isn't a false positive
132
- assert(window.history.pushState !== History.prototype.pushState);
133
122
  });
134
123
  }
135
124
  function isVikeEnhanced(state) {
@@ -147,16 +136,6 @@ function isVikeEnhanced(state) {
147
136
  }
148
137
  return false;
149
138
  }
150
- function assertIsVikeEnhanced(state) {
151
- if (isVikeEnhanced(state))
152
- return;
153
- assert(false, {
154
- state,
155
- // TO-DO/eventually: remove _isVikeMonkeyPatch debug info to save KBs
156
- pushStateIsVikeMonkeyPatch: window.history.pushState._isVikeMonkeyPatch,
157
- replaceStateIsVikeMonkeyPatch: window.history.replaceState._isVikeMonkeyPatch,
158
- });
159
- }
160
139
  function getHistoryInfo() {
161
140
  return {
162
141
  url: getCurrentUrl(),
@@ -168,12 +147,11 @@ function onPopStateBegin() {
168
147
  const isHistoryStateEnhanced = window.history.state !== null;
169
148
  if (!isHistoryStateEnhanced)
170
149
  enhanceHistoryState();
171
- assertIsVikeEnhanced(window.history.state);
150
+ assert(isVikeEnhanced(window.history.state));
172
151
  const current = getHistoryInfo();
173
152
  globalObject.previous = current;
174
153
  return { isHistoryStateEnhanced, previous, current };
175
154
  }
176
- function initHistory() {
177
- monkeyPatchHistoryAPI(); // the earlier we call it the better (Vike can workaround erroneous library monkey patches if Vike is the last one in the monkey patch chain)
178
- enhanceHistoryState(); // enhance very first window.history.state which is `null`
155
+ function initHistoryState() {
156
+ enhanceHistoryState();
179
157
  }
@@ -6,7 +6,7 @@ import { initOnLinkClick } from './initOnLinkClick.js';
6
6
  import { scrollRestoration_init } from './scrollRestoration.js';
7
7
  import { autoSaveScrollPosition } from './setScrollPosition.js';
8
8
  import { initLinkPrefetchHandlers } from './prefetch.js';
9
- import { initHistory } from './history.js';
9
+ import { initHistoryState, monkeyPatchHistoryAPI } from './history.js';
10
10
  async function initClientRouter() {
11
11
  // Init navigation history and scroll restoration
12
12
  initHistoryAndScroll();
@@ -29,7 +29,8 @@ async function renderFirstPage() {
29
29
  }
30
30
  function initHistoryAndScroll() {
31
31
  scrollRestoration_init();
32
- initHistory(); // we redundantly call initHistory() to ensure it's called early
32
+ monkeyPatchHistoryAPI();
33
+ initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
33
34
  autoSaveScrollPosition();
34
35
  // Handle back-/forward navigation
35
36
  initOnPopState();
@@ -95,6 +95,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
95
95
  urlOriginal: string;
96
96
  headers: Record<string, string> | null;
97
97
  headersOriginal?: unknown;
98
+ headersResponse: Headers;
98
99
  is404: boolean | null;
99
100
  isClientSideNavigation: boolean;
100
101
  abortReason?: unknown;
@@ -119,6 +120,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
119
120
  urlOriginal: string;
120
121
  headers: Record<string, string> | null;
121
122
  headersOriginal?: unknown;
123
+ headersResponse: Headers;
122
124
  is404: boolean | null;
123
125
  isClientSideNavigation: boolean;
124
126
  abortReason?: unknown;
@@ -23,14 +23,14 @@ declare function createGetGlobalContextClient<GlobalContextAddendum extends obje
23
23
  pages: {
24
24
  [k: string]: import("../../shared/page-configs/resolveVikeConfigPublic.js").VikeConfigPublicPageEager;
25
25
  };
26
- } & Awaited<{
26
+ } & {
27
27
  /**
28
28
  * Whether the environment is client-side or server-side / pre-rendering.
29
29
  *
30
30
  * We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
31
31
  */
32
32
  isClientSide: true;
33
- } & Awaited<GlobalContextAddendum>>>;
33
+ } & Awaited<GlobalContextAddendum>>;
34
34
  type NeverExported = never;
35
35
  declare function getGlobalContext(): Promise<NeverExported>;
36
36
  declare function getGlobalContextSync(): NeverExported;
@@ -561,6 +561,7 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
561
561
  _isHtmlOnly: boolean;
562
562
  _passToClient: string[];
563
563
  _pageFilePathsLoaded: string[];
564
+ headersResponse: Headers;
564
565
  } & {
565
566
  __getPageAssets: () => Promise<import("../runtime/renderPage/getPageAssets.js").PageAsset[]>;
566
567
  })) & {