vike 0.4.235-commit-8f42b16 → 0.4.235-commit-d2ac38a

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 (40) hide show
  1. package/dist/cjs/node/runtime/globalContext.js +21 -6
  2. package/dist/cjs/node/runtime/html/serializeContext.js +58 -13
  3. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -7
  4. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +8 -5
  5. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +28 -2
  6. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
  7. package/dist/cjs/node/runtime/renderPage.js +1 -0
  8. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +4 -0
  9. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
  10. package/dist/cjs/shared/createGlobalContextShared.js +20 -7
  11. package/dist/cjs/shared/route/loadPageRoutes.js +7 -1
  12. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  13. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +8 -0
  14. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +2 -0
  15. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +2 -2
  16. package/dist/esm/node/prerender/runPrerender.d.ts +2 -1
  17. package/dist/esm/node/runtime/globalContext.d.ts +14 -12
  18. package/dist/esm/node/runtime/globalContext.js +23 -8
  19. package/dist/esm/node/runtime/html/serializeContext.d.ts +7 -1
  20. package/dist/esm/node/runtime/html/serializeContext.js +58 -13
  21. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +3 -3
  22. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -7
  23. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -0
  24. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +8 -5
  25. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +8 -4
  26. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +29 -3
  27. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +4 -2
  28. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -0
  29. package/dist/esm/node/runtime/renderPage.js +1 -0
  30. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +4 -0
  31. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +4 -6
  32. package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
  33. package/dist/esm/shared/createGlobalContextShared.js +20 -7
  34. package/dist/esm/shared/route/loadPageRoutes.d.ts +5 -0
  35. package/dist/esm/shared/route/loadPageRoutes.js +7 -1
  36. package/dist/esm/types/Config.d.ts +9 -1
  37. package/dist/esm/types/PageContext.d.ts +8 -2
  38. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  39. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  40. package/package.json +1 -1
@@ -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,18 +370,29 @@ 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);
374
379
  assertGlobalContextIsDefined();
375
380
  (0, utils_js_1.onSetupRuntime)();
381
+ debug('setGlobalContext() - done');
376
382
  // Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
377
383
  return globalContext;
378
384
  }
379
- async function addGlobalContext(globalContext) {
385
+ async function addGlobalContextAsync(globalContext) {
386
+ debug('addGlobalContextAsync()');
380
387
  const { pageRoutes, onBeforeRouteHook } = await (0, loadPageRoutes_js_1.loadPageRoutes)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
388
+ return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
389
+ }
390
+ function addGlobalContextSync(globalContext) {
391
+ debug('addGlobalContextSync()');
392
+ const { pageRoutes, onBeforeRouteHook } = (0, loadPageRoutes_js_1.loadPageRoutesSync)(globalContext._pageFilesAll, globalContext._pageConfigs, globalContext._pageConfigGlobal, globalContext._allPageIds);
393
+ return addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook);
394
+ }
395
+ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
381
396
  const globalContextBase = {
382
397
  isClientSide: false,
383
398
  _pageRoutes: pageRoutes,
@@ -436,10 +451,10 @@ async function addGlobalContext(globalContext) {
436
451
  }
437
452
  function clearGlobalContext() {
438
453
  debug('clearGlobalContext()');
439
- (0, utils_js_1.objectReplace)(globalObject, getInitialGlobalContext(), ['buildEntryPrevious']);
454
+ (0, utils_js_1.objectReplace)(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
440
455
  }
441
- function getInitialGlobalContext() {
442
- debug('getInitialGlobalContext()');
456
+ function getInitialGlobalObject() {
457
+ debug('getInitialGlobalObject()');
443
458
  const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = (0, utils_js_1.genPromise)();
444
459
  return {
445
460
  viteDevServerPromise,
@@ -32,20 +32,41 @@ const passToClientBuiltInPageContext = [
32
32
  const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError_js_1.isServerSideError];
33
33
  function getPageContextClientSerialized(pageContext) {
34
34
  const passToClientPageContext = getPassToClientPageContext(pageContext);
35
- const pageContextClient = applyPassToClient(passToClientPageContext, pageContext);
36
- if (passToClientPageContext.some((prop) => (0, propKeys_js_1.getPropVal)(pageContext._pageContextInit, prop))) {
35
+ const getObj = (passToClientEntry) => {
36
+ if (passToClientEntry.once)
37
+ return undefined; // pass it to client-side globalContext
38
+ return { obj: pageContext, objName: 'pageContext' };
39
+ };
40
+ const res = applyPassToClient(passToClientPageContext, getObj);
41
+ const pageContextClient = res.objClient;
42
+ const pageContextClientProps = res.objClientProps;
43
+ if (pageContextClientProps.some((prop) => (0, propKeys_js_1.getPropVal)(pageContext._pageContextInit, prop))) {
37
44
  pageContextClient[pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient] = true;
38
45
  }
39
- const pageContextClientSerialized = serializeObject(pageContextClient, 'pageContext', passToClientPageContext);
46
+ const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, getObj);
40
47
  return pageContextClientSerialized;
41
48
  }
42
49
  function getGlobalContextClientSerialized(pageContext) {
43
50
  const passToClient = pageContext._passToClient;
44
- const globalContextClient = applyPassToClient(passToClient, pageContext._globalContext);
45
- const globalContextClientSerialized = serializeObject(globalContextClient, 'globalContext', passToClient);
51
+ const globalContext = pageContext._globalContext;
52
+ const getObj = ({ prop, once }) => {
53
+ if (once && (0, propKeys_js_1.getPropVal)(pageContext, prop)) {
54
+ (0, utils_js_1.assert)(typeof pageContext.isClientSideNavigation === 'boolean');
55
+ if (!pageContext.isClientSideNavigation) {
56
+ return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
57
+ }
58
+ else {
59
+ return undefined; // already passed to client-side
60
+ }
61
+ }
62
+ return { obj: globalContext, objName: 'globalContext' };
63
+ };
64
+ const res = applyPassToClient(passToClient, getObj);
65
+ const globalContextClient = res.objClient;
66
+ const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, getObj);
46
67
  return globalContextClientSerialized;
47
68
  }
48
- function serializeObject(obj, objName, passToClient) {
69
+ function serializeObject(obj, passToClient, getObj) {
49
70
  let serialized;
50
71
  try {
51
72
  serialized = serializeValue(obj);
@@ -54,11 +75,15 @@ function serializeObject(obj, objName, passToClient) {
54
75
  const h = (s) => picocolors_1.default.cyan(s);
55
76
  let hasWarned = false;
56
77
  const propsNonSerializable = [];
57
- passToClient.forEach((prop) => {
78
+ passToClient.forEach((entry) => {
79
+ const entryNormalized = normalizePassToClientEntry(entry);
80
+ const { prop } = entryNormalized;
58
81
  const res = (0, propKeys_js_1.getPropVal)(obj, prop);
59
82
  if (!res)
60
83
  return;
61
84
  const { value } = res;
85
+ const { objName } = getObj(entryNormalized) ?? {};
86
+ (0, utils_js_1.assert)(objName);
62
87
  const varName = `${objName}${(0, propKeys_js_1.getPropKeys)(prop).map(utils_js_1.getPropAccessNotation).join('')}`;
63
88
  try {
64
89
  serializeValue(value, varName);
@@ -168,16 +193,36 @@ function getPageContextClientSerializedAbort(pageContext) {
168
193
  }
169
194
  return serializeValue(pageContext);
170
195
  }
171
- function applyPassToClient(passToClient, pageContext) {
172
- const pageContextClient = {};
173
- passToClient.forEach((prop) => {
196
+ function applyPassToClient(passToClient, getObj) {
197
+ const objClient = {};
198
+ const objClientProps = [];
199
+ passToClient.forEach((entry) => {
200
+ const entryNormalized = normalizePassToClientEntry(entry);
201
+ const { prop } = entryNormalized;
202
+ const { obj } = getObj(entryNormalized) ?? {};
203
+ if (!obj)
204
+ return;
174
205
  // Get value from pageContext
175
- const res = (0, propKeys_js_1.getPropVal)(pageContext, prop);
206
+ const res = (0, propKeys_js_1.getPropVal)(obj, prop);
176
207
  if (!res)
177
208
  return;
178
209
  const { value } = res;
179
210
  // Set value to pageContextClient
180
- (0, propKeys_js_1.setPropVal)(pageContextClient, prop, value);
211
+ (0, propKeys_js_1.setPropVal)(objClient, prop, value);
212
+ objClientProps.push(prop);
181
213
  });
182
- return pageContextClient;
214
+ return { objClient, objClientProps };
215
+ }
216
+ function normalizePassToClientEntry(entry) {
217
+ let once;
218
+ let prop;
219
+ if (typeof entry === 'string') {
220
+ prop = entry;
221
+ once = false;
222
+ }
223
+ else {
224
+ prop = entry.prop;
225
+ once = entry.once ?? false;
226
+ }
227
+ return { prop, once };
183
228
  }
@@ -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;
@@ -38,8 +41,9 @@ async function loadPageConfigsLazyServerSide(pageContext) {
38
41
  }
39
42
  else {
40
43
  configPublicPageLazy.from.configsCumulative.passToClient?.values.forEach((v) => {
41
- const { value, definedAt } = v;
42
- (0, utils_js_1.assertUsage)((0, utils_js_1.isArrayOfStrings)(value), `+passToClient value defined at ${definedAt}${errMsg}`);
44
+ const { value } = v;
45
+ // const { definedAt } = v
46
+ // assertUsage(isArrayOfStrings(value), `+passToClient value defined at ${definedAt}${errMsg}`)
43
47
  passToClient.push(...value);
44
48
  });
45
49
  }
@@ -50,6 +54,7 @@ async function loadPageConfigsLazyServerSide(pageContext) {
50
54
  _isHtmlOnly: isHtmlOnly,
51
55
  _passToClient: passToClient,
52
56
  _pageFilePathsLoaded: pageFilesLoaded.map((p) => p.filePath),
57
+ headersResponse: resolveHeadersResponse(pageContext, pageContextAddendum),
53
58
  });
54
59
  (0, utils_js_1.objectAssign)(pageContextAddendum, {
55
60
  __getPageAssets: async () => {
@@ -102,6 +107,7 @@ async function loadPageConfigsLazyServerSide(pageContext) {
102
107
  });
103
108
  return pageContextAddendum;
104
109
  }
110
+ // TODO/now: rename?
105
111
  async function loadPageUserFiles(pageFilesAll, pageConfig, pageConfigGlobal, pageId, isDev) {
106
112
  const pageFilesServerSide = (0, getPageFiles_js_1.getPageFilesServerSide)(pageFilesAll, pageId);
107
113
  const pageConfigLoaded = !pageConfig ? null : await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, isDev);
@@ -112,3 +118,23 @@ async function loadPageUserFiles(pageFilesAll, pageConfig, pageConfigGlobal, pag
112
118
  pageFilesLoaded: pageFilesServerSide,
113
119
  };
114
120
  }
121
+ function resolveHeadersResponse(
122
+ // TODO/now: merge pageContextAddendum with pageContext
123
+ pageContext, pageContextAddendum) {
124
+ const headersResponse = mergeHeaders(pageContextAddendum.config.headersResponse);
125
+ if (!headersResponse.get('Cache-Control')) {
126
+ const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._globalContext._pageConfigs);
127
+ if (cacheControl)
128
+ headersResponse.set('Cache-Control', cacheControl);
129
+ }
130
+ return headersResponse;
131
+ }
132
+ function mergeHeaders(headersList = []) {
133
+ const headersMerged = new Headers();
134
+ headersList.forEach((headers) => {
135
+ new Headers(headers).forEach((value, key) => {
136
+ headersMerged.append(key, value);
137
+ });
138
+ });
139
+ return headersMerged;
140
+ }
@@ -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,26 @@ 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 &&
24
+ // TODO/next-major-release: remove
25
+ globalContext._pageConfigs.length > 0) {
26
+ const globalContextAddendum = addGlobalContextSync?.(globalContext);
27
+ (0, utils_js_1.objectAssign)(globalContext, globalContextAddendum);
28
+ }
29
+ else {
30
+ const globalContextAddendum = await addGlobalContextAsync?.(globalContext);
31
+ (0, utils_js_1.objectAssign)(globalContext, globalContextAddendum);
32
+ }
17
33
  const onCreateGlobalContextHooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
18
34
  let hooksCalled = false;
19
35
  if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
@@ -21,10 +37,7 @@ async function createGlobalContextShared(virtualFileExports, globalObject, addGl
21
37
  await (0, execHook_js_1.execHookGlobal)('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage);
22
38
  hooksCalled = true;
23
39
  }
24
- if (!globalObject.globalContext) {
25
- globalObject.globalContext = globalContext;
26
- }
27
- else {
40
+ if (isNewGlobalContext) {
28
41
  // Singleton: ensure all `globalContext` user-land references are preserved & updated.
29
42
  if (hooksCalled) {
30
43
  (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-8f42b16';
5
+ exports.PROJECT_VERSION = '0.4.235-commit-d2ac38a';
@@ -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;
@@ -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;
@@ -559,8 +559,9 @@ declare function createPageContextPrerendering(urlOriginal: string, prerenderCon
559
559
  })) & import("../../shared/getPageFiles.js").VikeConfigPublicPageLazy) & {
560
560
  Page: unknown;
561
561
  _isHtmlOnly: boolean;
562
- _passToClient: string[];
562
+ _passToClient: import("../runtime/html/serializeContext.js").PassToClient;
563
563
  _pageFilePathsLoaded: string[];
564
+ headersResponse: Headers;
564
565
  } & {
565
566
  __getPageAssets: () => Promise<import("../runtime/renderPage/getPageAssets.js").PageAsset[]>;
566
567
  })) & {
@@ -21,8 +21,10 @@ export type { GlobalContextServerInternal as GlobalContextServerInternal };
21
21
  export type { GlobalContextServer };
22
22
  import type { ViteManifest } from '../../types/ViteManifest.js';
23
23
  import type { ResolvedConfig, ViteDevServer } from 'vite';
24
+ import { type PageRoutes } from '../../shared/route/loadPageRoutes.js';
24
25
  import type { ViteConfigRuntime } from '../vite/shared/getViteConfigRuntime.js';
25
26
  import type { GlobalContext } from '../../types/PageContext.js';
27
+ import type { Hook } from '../../shared/hooks/getHook.js';
26
28
  declare const vikeConfigErrorRecoverMsg: "Vike config loaded";
27
29
  type GlobalContextServer = Pick<GlobalContextServerInternal, 'assetsManifest' | 'config' | 'viteConfig' | 'viteConfigRuntime' | 'pages' | 'baseServer' | 'baseAssets' | 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextServer;
28
30
  type GlobalContextServerInternal = Awaited<ReturnType<typeof setGlobalContext>>;
@@ -64,8 +66,8 @@ declare function getGlobalContextServerInternal(): Promise<{
64
66
  baseServer: string;
65
67
  baseAssets: string;
66
68
  isClientSide: false;
67
- _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
68
- _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
69
+ _pageRoutes: PageRoutes;
70
+ _onBeforeRouteHook: Hook | null;
69
71
  }) | (Record<string, unknown> & {
70
72
  isGlobalContext: true;
71
73
  _isOriginalObject: true;
@@ -104,8 +106,8 @@ declare function getGlobalContextServerInternal(): Promise<{
104
106
  baseServer: string;
105
107
  baseAssets: string;
106
108
  isClientSide: false;
107
- _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
108
- _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
109
+ _pageRoutes: PageRoutes;
110
+ _onBeforeRouteHook: Hook | null;
109
111
  }) | (Record<string, unknown> & {
110
112
  isGlobalContext: true;
111
113
  _isOriginalObject: true;
@@ -144,8 +146,8 @@ declare function getGlobalContextServerInternal(): Promise<{
144
146
  baseServer: string;
145
147
  baseAssets: string;
146
148
  isClientSide: false;
147
- _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
148
- _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
149
+ _pageRoutes: PageRoutes;
150
+ _onBeforeRouteHook: Hook | null;
149
151
  });
150
152
  }>;
151
153
  /**
@@ -222,8 +224,8 @@ declare function setGlobalContext(virtualFileExports: unknown): Promise<{
222
224
  baseServer: string;
223
225
  baseAssets: string;
224
226
  isClientSide: false;
225
- _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
226
- _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
227
+ _pageRoutes: PageRoutes;
228
+ _onBeforeRouteHook: Hook | null;
227
229
  } | {
228
230
  _isPrerendering: true;
229
231
  viteConfig: ResolvedConfig;
@@ -244,8 +246,8 @@ declare function setGlobalContext(virtualFileExports: unknown): Promise<{
244
246
  baseServer: string;
245
247
  baseAssets: string;
246
248
  isClientSide: false;
247
- _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
248
- _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
249
+ _pageRoutes: PageRoutes;
250
+ _onBeforeRouteHook: Hook | null;
249
251
  } | {
250
252
  _isPrerendering: false;
251
253
  viteConfig: null;
@@ -266,7 +268,7 @@ declare function setGlobalContext(virtualFileExports: unknown): Promise<{
266
268
  baseServer: string;
267
269
  baseAssets: string;
268
270
  isClientSide: false;
269
- _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
270
- _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
271
+ _pageRoutes: PageRoutes;
272
+ _onBeforeRouteHook: Hook | null;
271
273
  })>;
272
274
  declare function clearGlobalContext(): void;