vike 0.4.225 → 0.4.226

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 (152) hide show
  1. package/dist/cjs/client/shared/getPageContextProxyForUser.js +3 -66
  2. package/dist/cjs/node/api/build.js +7 -7
  3. package/dist/cjs/node/api/dev.js +2 -2
  4. package/dist/cjs/node/api/prepareViteApiCall.js +55 -30
  5. package/dist/cjs/node/api/prerender.js +2 -3
  6. package/dist/cjs/node/api/preview.js +27 -6
  7. package/dist/cjs/node/api/utils.js +1 -0
  8. package/dist/cjs/node/cli/entry.js +4 -2
  9. package/dist/cjs/node/cli/parseCli.js +10 -4
  10. package/dist/cjs/node/plugin/plugins/build/pluginAutoFullBuild.js +2 -2
  11. package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +51 -0
  12. package/dist/cjs/node/plugin/plugins/build.js +3 -1
  13. package/dist/cjs/node/plugin/plugins/commonConfig.js +8 -6
  14. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  15. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +14 -10
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -1
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +99 -85
  19. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +10 -1
  20. package/dist/cjs/node/plugin/shared/getEnvVarObject.js +7 -0
  21. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -3
  22. package/dist/cjs/node/prerender/runPrerender.js +8 -12
  23. package/dist/cjs/node/prerender/utils.js +1 -1
  24. package/dist/cjs/node/runtime/globalContext.js +13 -8
  25. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  26. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +67 -14
  27. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
  28. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
  29. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
  30. package/dist/cjs/node/runtime/renderPage.js +13 -28
  31. package/dist/cjs/node/runtime/utils.js +1 -1
  32. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +2 -2
  33. package/dist/cjs/node/shared/assertV1Design.js +1 -1
  34. package/dist/cjs/node/shared/utils.js +1 -1
  35. package/dist/cjs/node/shared/virtual-files.js +14 -10
  36. package/dist/cjs/shared/NOT_SERIALIZABLE.js +5 -0
  37. package/dist/cjs/shared/modifyUrl.js +3 -5
  38. package/dist/cjs/shared/modifyUrlSameOrigin.js +42 -0
  39. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +3 -2
  40. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +5 -5
  41. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +9 -9
  42. package/dist/cjs/shared/utils.js +2 -1
  43. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  44. package/dist/cjs/utils/assert.js +10 -3
  45. package/dist/cjs/utils/assertSetup.js +12 -8
  46. package/dist/cjs/utils/getRandomId.js +1 -1
  47. package/dist/cjs/utils/isNullish.js +16 -0
  48. package/dist/cjs/utils/normalizeHeaders.js +1 -1
  49. package/dist/cjs/utils/objectAssign.js +7 -2
  50. package/dist/cjs/utils/objectFilter.js +10 -0
  51. package/dist/cjs/utils/pick.js +12 -0
  52. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +3 -1
  53. package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
  54. package/dist/esm/client/client-routing-runtime/navigate.d.ts +6 -5
  55. package/dist/esm/client/client-routing-runtime/navigate.js +6 -2
  56. package/dist/esm/client/client-routing-runtime/normalizeUrlArgument.js +1 -1
  57. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
  58. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +6 -3
  59. package/dist/esm/client/server-routing-runtime/getPageContext.js +6 -3
  60. package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +1 -11
  61. package/dist/esm/client/shared/getPageContextProxyForUser.js +4 -67
  62. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
  63. package/dist/esm/node/api/build.js +7 -7
  64. package/dist/esm/node/api/dev.js +2 -2
  65. package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -1
  66. package/dist/esm/node/api/prepareViteApiCall.js +57 -32
  67. package/dist/esm/node/api/prerender.js +2 -3
  68. package/dist/esm/node/api/preview.d.ts +1 -1
  69. package/dist/esm/node/api/preview.js +24 -6
  70. package/dist/esm/node/api/utils.d.ts +1 -0
  71. package/dist/esm/node/api/utils.js +1 -0
  72. package/dist/esm/node/cli/entry.js +4 -2
  73. package/dist/esm/node/cli/parseCli.js +10 -4
  74. package/dist/esm/node/plugin/plugins/build/pluginAutoFullBuild.js +2 -2
  75. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.d.ts +3 -0
  76. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +49 -0
  77. package/dist/esm/node/plugin/plugins/build.js +3 -1
  78. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +3 -1
  79. package/dist/esm/node/plugin/plugins/commonConfig.js +8 -6
  80. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  81. package/dist/esm/node/plugin/plugins/importUserCode/index.js +15 -11
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -1
  83. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +5 -2
  84. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  85. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +11 -2
  86. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +101 -86
  87. package/dist/esm/node/plugin/plugins/setGlobalContext.js +11 -2
  88. package/dist/esm/node/plugin/shared/getEnvVarObject.js +7 -0
  89. package/dist/esm/node/prerender/resolvePrerenderConfig.js +3 -3
  90. package/dist/esm/node/prerender/runPrerender.js +8 -12
  91. package/dist/esm/node/prerender/utils.d.ts +1 -1
  92. package/dist/esm/node/prerender/utils.js +1 -1
  93. package/dist/esm/node/runtime/globalContext.d.ts +2 -3
  94. package/dist/esm/node/runtime/globalContext.js +13 -8
  95. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  96. package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -0
  97. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +69 -15
  98. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +1 -1
  99. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
  100. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -0
  101. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +27 -1
  102. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +18 -12
  103. package/dist/esm/node/runtime/renderPage.js +14 -29
  104. package/dist/esm/node/runtime/utils.d.ts +1 -1
  105. package/dist/esm/node/runtime/utils.js +1 -1
  106. package/dist/esm/node/runtime-dev/createDevMiddleware.js +2 -2
  107. package/dist/esm/node/shared/assertV1Design.js +1 -1
  108. package/dist/esm/node/shared/utils.d.ts +1 -1
  109. package/dist/esm/node/shared/utils.js +1 -1
  110. package/dist/esm/node/shared/virtual-files.d.ts +2 -0
  111. package/dist/esm/node/shared/virtual-files.js +14 -10
  112. package/dist/esm/shared/NOT_SERIALIZABLE.d.ts +1 -0
  113. package/dist/esm/shared/NOT_SERIALIZABLE.js +2 -0
  114. package/dist/esm/shared/modifyUrl.d.ts +2 -2
  115. package/dist/esm/shared/modifyUrl.js +3 -5
  116. package/dist/esm/shared/modifyUrlSameOrigin.d.ts +9 -0
  117. package/dist/esm/shared/modifyUrlSameOrigin.js +40 -0
  118. package/dist/esm/shared/page-configs/Config.d.ts +11 -3
  119. package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -2
  120. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +3 -1
  121. package/dist/esm/shared/page-configs/getConfigDefinedAt.js +3 -2
  122. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +5 -5
  123. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +9 -9
  124. package/dist/esm/shared/route/abort.d.ts +2 -2
  125. package/dist/esm/shared/types.d.ts +39 -3
  126. package/dist/esm/shared/utils.d.ts +2 -1
  127. package/dist/esm/shared/utils.js +2 -1
  128. package/dist/esm/types/index.d.ts +0 -1
  129. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  130. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  131. package/dist/esm/utils/assert.d.ts +2 -1
  132. package/dist/esm/utils/assert.js +10 -3
  133. package/dist/esm/utils/assertSetup.d.ts +2 -2
  134. package/dist/esm/utils/assertSetup.js +12 -8
  135. package/dist/esm/utils/getRandomId.d.ts +1 -1
  136. package/dist/esm/utils/getRandomId.js +1 -1
  137. package/dist/esm/utils/isNullish.d.ts +3 -0
  138. package/dist/esm/utils/isNullish.js +11 -0
  139. package/dist/esm/utils/normalizeHeaders.js +1 -1
  140. package/dist/esm/utils/objectAssign.d.ts +1 -1
  141. package/dist/esm/utils/objectAssign.js +7 -2
  142. package/dist/esm/utils/objectFilter.d.ts +1 -0
  143. package/dist/esm/utils/objectFilter.js +7 -0
  144. package/dist/esm/utils/pick.d.ts +1 -0
  145. package/dist/esm/utils/pick.js +9 -0
  146. package/package.json +4 -2
  147. package/dist/cjs/shared/notSerializable.js +0 -5
  148. package/dist/cjs/utils/isNotNullish.js +0 -5
  149. package/dist/esm/shared/notSerializable.d.ts +0 -1
  150. package/dist/esm/shared/notSerializable.js +0 -2
  151. package/dist/esm/utils/isNotNullish.d.ts +0 -1
  152. package/dist/esm/utils/isNotNullish.js +0 -1
@@ -47,7 +47,7 @@ function assert(condition, debugInfo) {
47
47
  const debugInfoSerialized = typeof debugInfo === 'string' ? debugInfo : JSON.stringify(debugInfo);
48
48
  return picocolors_1.default.dim(`Debug info (for Vike maintainers; you can ignore this): ${debugInfoSerialized}`);
49
49
  })();
50
- const link = picocolors_1.default.blue('https://github.com/vikejs/vike/issues/new?template=bug.yml');
50
+ const link = picocolors_1.default.underline('https://github.com/vikejs/vike/issues/new?template=bug.yml');
51
51
  let errMsg = [
52
52
  `You stumbled upon a Vike bug. Go to ${link} and copy-paste this error. A maintainer will fix the bug (usually within 24 hours).`,
53
53
  debugStr
@@ -61,7 +61,7 @@ function assert(condition, debugInfo) {
61
61
  globalObject.onBeforeLog?.();
62
62
  throw internalError;
63
63
  }
64
- function assertUsage(condition, errMsg, { showStackTrace } = {}) {
64
+ function assertUsage(condition, errMsg, { showStackTrace, exitOnError } = {}) {
65
65
  if (condition)
66
66
  return;
67
67
  showStackTrace = showStackTrace || globalObject.alwaysShowStackTrace;
@@ -73,7 +73,13 @@ function assertUsage(condition, errMsg, { showStackTrace } = {}) {
73
73
  globalObject.showStackTraceList.add(usageError);
74
74
  }
75
75
  globalObject.onBeforeLog?.();
76
- throw usageError;
76
+ if (!exitOnError) {
77
+ throw usageError;
78
+ }
79
+ else {
80
+ console.error(showStackTrace ? usageError : errMsg);
81
+ process.exit(1);
82
+ }
77
83
  }
78
84
  function getProjectError(errMsg) {
79
85
  errMsg = addWhitespace(errMsg);
@@ -187,6 +193,7 @@ function overwriteAssertProductionLogger(logger) {
187
193
  function isBug(err) {
188
194
  return String(err).includes(`[${bugTag}]`);
189
195
  }
196
+ // Called upon `DEBUG=vike:error`
190
197
  function setAlwaysShowStackTrace() {
191
198
  globalObject.alwaysShowStackTrace = true;
192
199
  }
@@ -7,12 +7,12 @@ exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
7
7
  exports.onSetupRuntime = onSetupRuntime;
8
8
  exports.onSetupBuild = onSetupBuild;
9
9
  exports.onSetupPrerender = onSetupPrerender;
10
+ exports.onSetupPreview = onSetupPreview;
10
11
  exports.setNodeEnvProduction = setNodeEnvProduction;
11
12
  exports.markSetup_viteDevServer = markSetup_viteDevServer;
12
13
  exports.markSetup_vitePreviewServer = markSetup_vitePreviewServer;
13
14
  exports.markSetup_vikeVitePlugin = markSetup_vikeVitePlugin;
14
15
  exports.markSetup_isViteDev = markSetup_isViteDev;
15
- exports.markSetup_isPrerendering = markSetup_isPrerendering;
16
16
  const assert_js_1 = require("./assert.js");
17
17
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
18
18
  const debug_js_1 = require("./debug.js");
@@ -34,7 +34,7 @@ function onSetupRuntime() {
34
34
  if (isTest())
35
35
  return;
36
36
  assertNodeEnvIsNotUndefinedString();
37
- if (!isViteLoaded()) {
37
+ if (!setup.viteDevServer && setup.isViteDev === undefined) {
38
38
  // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
39
39
  (0, assert_js_1.assertWarning)(!isNodeEnvDev(), `The ${getEnvDescription()}, which is contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
40
40
  (0, assert_js_1.assertUsage)(!setup.vikeVitePlugin, `Loading Vike's Vite plugin (the ${picocolors_1.default.cyan('vike/plugin')} module) is prohibited in production.`);
@@ -42,11 +42,10 @@ function onSetupRuntime() {
42
42
  (0, assert_js_1.assert)(!setup.shouldNotBeProduction);
43
43
  }
44
44
  else {
45
- if (!setup.vitePreviewServer && !setup.isPrerendering) {
45
+ if (!setup.isPreview && !setup.vitePreviewServer && !setup.isPrerendering) {
46
46
  // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
47
47
  (0, assert_js_1.assertWarning)(isNodeEnvDev(), `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
48
48
  }
49
- // These two assert() calls aren't that interesting
50
49
  (0, assert_js_1.assert)(setup.vikeVitePlugin);
51
50
  (0, assert_js_1.assert)(setup.shouldNotBeProduction);
52
51
  }
@@ -63,15 +62,16 @@ function onSetupBuild() {
63
62
  setNodeEnvProduction()
64
63
  */
65
64
  }
65
+ // Called by ../node/prerender/runPrerender.ts
66
66
  function onSetupPrerender() {
67
67
  markSetup_isPrerendering();
68
68
  if (getNodeEnv())
69
69
  assertUsageNodeEnvIsNotDev('pre-rendering');
70
70
  setNodeEnvProduction();
71
71
  }
72
- function isViteLoaded() {
73
- // Do we need setup.viteDevServer or setup.vitePreviewServer ?
74
- return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
72
+ // Called by ../node/api/preview.ts
73
+ function onSetupPreview() {
74
+ markSetup_isPreview();
75
75
  }
76
76
  function isTest() {
77
77
  return (0, isVitest_js_1.isVitest)() || isNodeEnv('test');
@@ -100,12 +100,16 @@ function markSetup_isViteDev(isViteDev) {
100
100
  debug('markSetup_isViteDev()', new Error().stack);
101
101
  setup.isViteDev = isViteDev;
102
102
  }
103
- // Called by ../node/prerender/runPrerender.ts
104
103
  function markSetup_isPrerendering() {
105
104
  if (debug.isActivated)
106
105
  debug('markSetup_isPrerendering()', new Error().stack);
107
106
  setup.isPrerendering = true;
108
107
  }
108
+ function markSetup_isPreview() {
109
+ if (debug.isActivated)
110
+ debug('markSetup_isPreview()', new Error().stack);
111
+ setup.isPreview = true;
112
+ }
109
113
  function assertUsageNodeEnvIsNotDev(operation) {
110
114
  if (!isNodeEnvDev())
111
115
  return;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRandomId = getRandomId;
4
4
  const assert_js_1 = require("./assert.js");
5
5
  // https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
6
- function getRandomId(length) {
6
+ function getRandomId(length = 12) {
7
7
  let randomId = '';
8
8
  while (randomId.length < length) {
9
9
  randomId += Math.random().toString(36).slice(2);
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNullish = isNullish;
4
+ exports.isNotNullish = isNotNullish;
5
+ exports.isNotNullish_keyVal = isNotNullish_keyVal;
6
+ function isNullish(val) {
7
+ return val === null || val === undefined;
8
+ }
9
+ // someArray.filter(isNotNullish)
10
+ function isNotNullish(p) {
11
+ return !isNullish(p);
12
+ }
13
+ // objectFilter(obj).filter(isNotNullish_keyVal)
14
+ function isNotNullish_keyVal(arg) {
15
+ return !isNullish(arg[1]);
16
+ }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeHeaders = normalizeHeaders;
4
4
  const isObject_js_1 = require("./isObject.js");
5
5
  function normalizeHeaders(
6
- /* This type is precise, too precise which can be annoying: e.g. cannot pass a string[][] argument because it doesn't match the more precise [string,string][] type.
6
+ /* This type is too strict which is annoying: cannot pass `string[][]` because it doesn't match the more precise type `[string,string][]`.
7
7
  headersOriginal ConstructorParameters<typeof Headers>[0]
8
8
  */
9
9
  headersOriginal) {
@@ -5,9 +5,14 @@ const assert_js_1 = require("./assert.js");
5
5
  // Same as Object.assign() but:
6
6
  // - With type inference
7
7
  // - Preserves property descriptors, which we need for preserving the getters added by getPageContextUrlComputed()
8
- function objectAssign(obj, objAddendum) {
8
+ function objectAssign(obj, objAddendum, objAddendumCanBePageContextObject) {
9
9
  if (objAddendum) {
10
- (0, assert_js_1.assert)(!('_isPageContextObject' in objAddendum));
10
+ if (!objAddendumCanBePageContextObject) {
11
+ // We only need this assert() in the rare case when the user is expected to mutate `pageContext` after the Vike hook was executed (and its promise resolved).
12
+ // - The only use case I can think of is the user mutating `pageContext` after the onRenderClient() promise resolved (which can happen when client-side rendering finishes after onRenderClient() resolves). In that case, having Vike await async Vike hooks isn't enough.
13
+ // - IIRC this assert() was mostly needed for preserving the getters added by getPageContextUrlComputed() but we don't need this anymore.
14
+ (0, assert_js_1.assert)(!('_isPageContextObject' in objAddendum));
15
+ }
11
16
  Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
12
17
  }
13
18
  }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectFilter = objectFilter;
4
+ // Type inference for:
5
+ // ```js
6
+ // Object.fromEntries(Object.entries(obj).filter(someFilter))
7
+ // ```
8
+ function objectFilter(obj, filter) {
9
+ return Object.fromEntries(Object.entries(obj).filter(filter));
10
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pick = pick;
4
+ function pick(obj, keys) {
5
+ const result = {};
6
+ for (const key of keys) {
7
+ if (key in obj) {
8
+ result[key] = obj[key];
9
+ }
10
+ }
11
+ return result;
12
+ }
@@ -1,5 +1,8 @@
1
1
  export { createPageContext };
2
2
  declare function createPageContext(urlOriginal: string): Promise<{
3
+ _isPageContextObject: boolean;
4
+ isClientSide: boolean;
5
+ isPrerendering: boolean;
3
6
  urlOriginal: string;
4
7
  _objectCreatedByVike: boolean;
5
8
  _urlHandler: null;
@@ -11,7 +14,6 @@ declare function createPageContext(urlOriginal: string): Promise<{
11
14
  _allPageIds: string[];
12
15
  _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
13
16
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
14
- _isPageContextObject: boolean;
15
17
  } & {
16
18
  urlParsed: import("./utils.js").UrlPublic;
17
19
  urlPathname: string;
@@ -4,7 +4,6 @@ import { getPageContextUrlComputed } from '../../shared/getPageContextUrlCompute
4
4
  import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
5
5
  import { getBaseServer } from './getBaseServer.js';
6
6
  import { assert, isBaseServer, objectAssign } from './utils.js';
7
- // TODO/now: can we avoid optimizeDeps.exclude of client runtime?
8
7
  // @ts-ignore
9
8
  import * as virtualFileExports from 'virtual:vike:importUserCode:client:client-routing';
10
9
  const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal } = getPageConfigsRuntime(virtualFileExports);
@@ -13,6 +12,9 @@ async function createPageContext(urlOriginal) {
13
12
  const baseServer = getBaseServer();
14
13
  assert(isBaseServer(baseServer));
15
14
  const pageContext = {
15
+ _isPageContextObject: true,
16
+ isClientSide: true,
17
+ isPrerendering: false,
16
18
  urlOriginal,
17
19
  _objectCreatedByVike: true,
18
20
  _urlHandler: null,
@@ -23,8 +25,7 @@ async function createPageContext(urlOriginal) {
23
25
  _pageConfigGlobal: pageConfigGlobal,
24
26
  _allPageIds: allPageIds,
25
27
  _pageRoutes: pageRoutes,
26
- _onBeforeRouteHook: onBeforeRouteHook,
27
- _isPageContextObject: true
28
+ _onBeforeRouteHook: onBeforeRouteHook
28
29
  };
29
30
  const pageContextUrlComputed = getPageContextUrlComputed(pageContext);
30
31
  objectAssign(pageContext, pageContextUrlComputed);
@@ -1,5 +1,10 @@
1
1
  export { navigate };
2
2
  export { reload };
3
+ type Options = {
4
+ keepScrollPosition?: boolean;
5
+ overwriteLastHistoryEntry?: boolean;
6
+ pageContext?: Record<string, unknown>;
7
+ };
3
8
  /** Programmatically navigate to a new page.
4
9
  *
5
10
  * https://vike.dev/navigate
@@ -8,9 +13,5 @@ export { reload };
8
13
  * @param keepScrollPosition - Don't scroll to the top of the page, instead keep the current scroll position.
9
14
  * @param overwriteLastHistoryEntry - Don't create a new entry in the browser's history, instead let the new URL replace the current URL. (This effectively removes the current URL from the browser history).
10
15
  */
11
- declare function navigate(url: string, { keepScrollPosition, overwriteLastHistoryEntry, pageContext }?: {
12
- keepScrollPosition?: boolean;
13
- overwriteLastHistoryEntry?: boolean;
14
- pageContext?: Record<string, unknown>;
15
- }): Promise<void>;
16
+ declare function navigate(url: string, options?: Options): Promise<void>;
16
17
  declare function reload(): Promise<void>;
@@ -1,5 +1,6 @@
1
1
  export { navigate };
2
2
  export { reload };
3
+ // import { modifyUrlSameOrigin, ModifyUrlSameOriginOptions } from '../../shared/modifyUrlSameOrigin.js'
3
4
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
4
5
  import { normalizeUrlArgument } from './normalizeUrlArgument.js';
5
6
  import { firstRenderStartPromise, renderPageClientSide } from './renderPageClientSide.js';
@@ -13,11 +14,14 @@ assertClientRouting();
13
14
  * @param keepScrollPosition - Don't scroll to the top of the page, instead keep the current scroll position.
14
15
  * @param overwriteLastHistoryEntry - Don't create a new entry in the browser's history, instead let the new URL replace the current URL. (This effectively removes the current URL from the browser history).
15
16
  */
16
- async function navigate(url, { keepScrollPosition = false, overwriteLastHistoryEntry = false, pageContext } = {}) {
17
+ async function navigate(url, options) {
18
+ // let url = normalizeUrlArgument(options.url ?? getCurrentUrl(), 'navigate')
19
+ // url = modifyUrlSameOrigin(url, options)
17
20
  normalizeUrlArgument(url, 'navigate');
18
21
  // If `hydrationCanBeAborted === false` (e.g. Vue) then we can apply navigate() only after hydration is done
19
22
  await firstRenderStartPromise;
20
- const scrollTarget = { preserveScroll: keepScrollPosition };
23
+ const { keepScrollPosition, overwriteLastHistoryEntry, pageContext } = options ?? {};
24
+ const scrollTarget = { preserveScroll: keepScrollPosition ?? false };
21
25
  await renderPageClientSide({
22
26
  scrollTarget,
23
27
  urlOriginal: url,
@@ -2,7 +2,7 @@ export { normalizeUrlArgument };
2
2
  import { assertUsage, isUrl, isUrlRelative } from './utils.js';
3
3
  function normalizeUrlArgument(url, fnName) {
4
4
  // Succinct error message to save client-side KBs
5
- const errMsg = `[${fnName}(url)] Invalid URL ${url}`;
5
+ const errMsg = `URL ${url} passed to ${fnName}() is invalid`;
6
6
  assertUsage(isUrl(url), errMsg);
7
7
  if (url.startsWith(location.origin)) {
8
8
  // Use normalizeClientSideUrl() instead?
@@ -276,7 +276,7 @@ async function renderPageClientSide(renderArgs) {
276
276
  if ('err' in args) {
277
277
  const { err } = args;
278
278
  assert(!('errorWhileRendering' in pageContext));
279
- pageContext.errorWhileRendering = err;
279
+ objectAssign(pageContext, { errorWhileRendering: err });
280
280
  if (isAbortError(err)) {
281
281
  const errAbort = err;
282
282
  logAbortErrorHandled(err, !import.meta.env.DEV, pageContext);
@@ -1,12 +1,15 @@
1
1
  export { getPageContext };
2
2
  declare function getPageContext(): Promise<{
3
- pageId: string;
4
- routeParams: Record<string, string>;
5
- } & {
3
+ _isPageContextObject: boolean;
4
+ isPrerendering: boolean;
5
+ isClientSide: boolean;
6
6
  isHydration: true;
7
7
  isBackwardNavigation: null;
8
8
  _hasPageContextFromServer: true;
9
9
  _hasPageContextFromClient: false;
10
+ } & {
11
+ pageId: string;
12
+ routeParams: Record<string, string>;
10
13
  } & {
11
14
  _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
12
15
  _pageConfigs: import("../../__internal/index.js").PageConfig[];
@@ -9,13 +9,16 @@ import * as virtualFileExports from 'virtual:vike:importUserCode:client:server-r
9
9
  const { pageFilesAll, pageConfigs, pageConfigGlobal } = getPageConfigsRuntime(virtualFileExports);
10
10
  const urlFirst = getCurrentUrl({ withoutHash: true });
11
11
  async function getPageContext() {
12
- const pageContext = getPageContextSerializedInHtml();
13
- objectAssign(pageContext, {
12
+ const pageContext = {
13
+ _isPageContextObject: true,
14
+ isPrerendering: false,
15
+ isClientSide: true,
14
16
  isHydration: true,
15
17
  isBackwardNavigation: null,
16
18
  _hasPageContextFromServer: true,
17
19
  _hasPageContextFromClient: false
18
- });
20
+ };
21
+ objectAssign(pageContext, getPageContextSerializedInHtml());
19
22
  objectAssign(pageContext, await loadPageUserFiles(pageContext.pageId));
20
23
  assertPristineUrl();
21
24
  return pageContext;
@@ -1,12 +1,2 @@
1
1
  export { getPageContextProxyForUser };
2
- export { PageContextForPassToClientWarning };
3
- type PageContextForPassToClientWarning = {
4
- _hasPageContextFromServer: boolean;
5
- _hasPageContextFromClient: boolean;
6
- };
7
- /**
8
- * Throw error when pageContext value isn't:
9
- * - serializable, or
10
- * - defined.
11
- */
12
- declare function getPageContextProxyForUser<PageContext extends Record<string, unknown> & PageContextForPassToClientWarning>(pageContext: PageContext): PageContext;
2
+ declare function getPageContextProxyForUser<PageContext extends Record<string, unknown>>(pageContext: PageContext): PageContext;
@@ -1,77 +1,14 @@
1
1
  export { getPageContextProxyForUser };
2
- import { assert, assertUsage, assertWarning, getGlobalObject, getPropAccessNotation } from '../server-routing-runtime/utils.js';
3
- import { notSerializable } from '../../shared/notSerializable.js';
4
- const globalObject = getGlobalObject('shared/getPageContextProxyForUser.ts', {});
5
- /**
6
- * Throw error when pageContext value isn't:
7
- * - serializable, or
8
- * - defined.
9
- */
2
+ import { assertUsage, getPropAccessNotation } from '../server-routing-runtime/utils.js';
3
+ import { NOT_SERIALIZABLE } from '../../shared/NOT_SERIALIZABLE.js';
4
+ // Throw error when pageContext value isn't serializable
10
5
  function getPageContextProxyForUser(pageContext) {
11
- assert([true, false].includes(pageContext._hasPageContextFromServer));
12
- assert([true, false].includes(pageContext._hasPageContextFromClient));
13
6
  return new Proxy(pageContext, {
14
7
  get(_, prop) {
15
8
  const val = pageContext[prop];
16
9
  const propName = getPropAccessNotation(prop);
17
- assertUsage(val !== notSerializable, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
18
- passToClientHint(pageContext, prop, propName);
10
+ assertUsage(val !== NOT_SERIALIZABLE, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
19
11
  return val;
20
12
  }
21
13
  });
22
14
  }
23
- function passToClientHint(pageContext, prop, propName) {
24
- if (handleVueReactivity(prop))
25
- return;
26
- // `prop in pageContext` is the trick we use to know the passToClient value on the client-side, as we set a value to all passToClient props, even `undefined` ones:
27
- // ```html
28
- // <script id="vike_pageContext" type="application/json">{"pageProps":"!undefined"}</script>
29
- // ```
30
- if (prop in pageContext)
31
- return;
32
- if (isWhitelisted(prop))
33
- return;
34
- // The trick described above (`prop in pageContext`) doesn't work if Vike doesn't fetch any pageContext from the server.
35
- // - There would still be some value to show a warning, but it isn't worth it because of the confusion that the first recommendation (adding `prop` to `passToClient`) wouldn't actually remove the warning, and only the second recommendation (using `prop in pageContext` instead of `pageContext[prop]`) would work.
36
- if (!pageContext._hasPageContextFromServer)
37
- return;
38
- const errMsg = `pageContext${propName} isn't defined on the client-side, see https://vike.dev/passToClient#error`;
39
- if (
40
- // TODO/next-major-release always make it an error.
41
- // - Remove pageContext._hasPageContextFromClient logic (IIRC this is its only use case).
42
- pageContext._hasPageContextFromClient) {
43
- assertWarning(false, errMsg, { onlyOnce: false, showStackTrace: true });
44
- }
45
- else {
46
- assertUsage(false, errMsg);
47
- }
48
- }
49
- const WHITELIST = [
50
- 'then',
51
- // Vue calls toJSON()
52
- 'toJSON'
53
- ];
54
- function isWhitelisted(prop) {
55
- if (WHITELIST.includes(prop))
56
- return true;
57
- if (typeof prop === 'symbol')
58
- return true; // Vue tries to access some symbols
59
- if (typeof prop !== 'string')
60
- return true;
61
- if (prop.startsWith('__v_'))
62
- return true; // Vue internals upon `reactive(pageContext)`
63
- return false;
64
- }
65
- // Handle Vue's reactivity.
66
- // When changing a reactive object:
67
- // - Vue tries to read its old value first. This triggers a `assertIsDefined()` failure if e.g. `pageContextReactive.routeParams = pageContextNew.routeParams` and `pageContextReactive` has no `routeParams`.
68
- // - Vue seems to read __v_raw before reading the property.
69
- function handleVueReactivity(prop) {
70
- if (globalObject.prev === prop || globalObject.prev === '__v_raw')
71
- return true;
72
- globalObject.prev = prop;
73
- window.setTimeout(() => {
74
- globalObject.prev = undefined;
75
- }, 0);
76
- return false;
77
- }
@@ -2,9 +2,9 @@ export { preparePageContextForUserConsumptionClientSide };
2
2
  export type { PageContextForUserConsumptionClientSide };
3
3
  import type { PageConfigUserFriendlyOld } from '../../shared/getPageFiles.js';
4
4
  import type { PageConfigRuntime } from '../../shared/page-configs/PageConfig.js';
5
- import { PageContextForPassToClientWarning } from './getPageContextProxyForUser.js';
6
- type PageContextForUserConsumptionClientSide = PageConfigUserFriendlyOld & PageContextForPassToClientWarning & {
5
+ type PageContextForUserConsumptionClientSide = PageConfigUserFriendlyOld & {
7
6
  pageId: string;
7
+ _hasPageContextFromServer: boolean;
8
8
  _pageConfigs: PageConfigRuntime[];
9
9
  };
10
10
  declare function preparePageContextForUserConsumptionClientSide<T extends PageContextForUserConsumptionClientSide>(pageContext: T, isClientRouting: boolean): T & {
@@ -11,13 +11,13 @@ import { assertVersion } from './utils.js';
11
11
  * https://vike.dev/api#build
12
12
  */
13
13
  async function build(options = {}) {
14
- const { viteConfigEnhanced, vikeConfig } = await prepareViteApiCall(options, 'build');
14
+ const { viteConfigFromUserEnhanced, vikeConfig } = await prepareViteApiCall(options, 'build');
15
15
  // Pass it to pluginAutoFullBuild()
16
- if (viteConfigEnhanced)
17
- viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
16
+ if (viteConfigFromUserEnhanced)
17
+ viteConfigFromUserEnhanced._viteConfigFromUserEnhanced = viteConfigFromUserEnhanced;
18
18
  if (vikeConfig.global.config.vite6BuilderApp) {
19
19
  assertVersion('Vite', version, '6.0.0');
20
- const builder = await createBuilder(viteConfigEnhanced);
20
+ const builder = await createBuilder(viteConfigFromUserEnhanced);
21
21
  // See Vite plugin vike:build:pluginBuildApp
22
22
  await builder.buildApp();
23
23
  }
@@ -30,14 +30,14 @@ async function build(options = {}) {
30
30
  // > See: https://github.com/vikejs/vike/blob/c6c7533a56b3a16fc43ed644fc5c10c02d0ff375/vike/node/plugin/plugins/autoFullBuild.ts#L98
31
31
  // > We purposely don't start the pre-rendering in this `build()` function but in a Rollup hook instead.
32
32
  // > Rationale: https://github.com/vikejs/vike/issues/2123
33
- await buildVite(viteConfigEnhanced);
33
+ await buildVite(viteConfigFromUserEnhanced);
34
34
  // After pre-rendering, when using the Vike CLI, the process is forcefully exited at the end of the buildVite() call above.
35
35
  if (isVikeCli() && isPrerendering())
36
36
  assert(false);
37
37
  }
38
38
  return {
39
- /* We don't return `viteConfig` because `viteConfigEnhanced` is `InlineConfig` not `ResolvedConfig`
40
- viteConfig: viteConfigEnhanced,
39
+ /* We don't return `viteConfig` because `viteConfigFromUserEnhanced` is `InlineConfig` not `ResolvedConfig`
40
+ viteConfig: viteConfigFromUserEnhanced,
41
41
  */
42
42
  };
43
43
  }
@@ -7,8 +7,8 @@ import { createServer } from 'vite';
7
7
  * https://vike.dev/api#dev
8
8
  */
9
9
  async function dev(options = {}) {
10
- const { viteConfigEnhanced } = await prepareViteApiCall(options, 'dev');
11
- const server = await createServer(viteConfigEnhanced);
10
+ const { viteConfigFromUserEnhanced } = await prepareViteApiCall(options, 'dev');
11
+ const server = await createServer(viteConfigFromUserEnhanced);
12
12
  return {
13
13
  viteServer: server,
14
14
  viteConfig: server.config
@@ -7,7 +7,8 @@ import type { APIOptions, Operation } from './types.js';
7
7
  import { type VikeConfigObject } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
8
8
  declare function prepareViteApiCall(options: APIOptions, operation: Operation): Promise<{
9
9
  vikeConfig: VikeConfigObject;
10
- viteConfigEnhanced: InlineConfig | undefined;
10
+ viteConfigResolved: ResolvedConfig;
11
+ viteConfigFromUserEnhanced: InlineConfig | undefined;
11
12
  }>;
12
13
  declare function getViteRoot(operation: Operation): Promise<string>;
13
14
  declare function normalizeViteRoot(root: string): string;