vike 0.4.236-commit-64431e7 → 0.4.236-commit-e752d12

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 (60) hide show
  1. package/dist/cjs/client/shared/createGetGlobalContextClient.js +1 -1
  2. package/dist/cjs/node/runtime/globalContext.js +17 -79
  3. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +1 -8
  4. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -3
  5. package/dist/cjs/node/runtime/utils.js +0 -1
  6. package/dist/cjs/node/vite/index.js +0 -2
  7. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +1 -2
  8. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +0 -2
  9. package/dist/cjs/node/vite/plugins/pluginCommon.js +0 -1
  10. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +3 -3
  11. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +2 -2
  12. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +1 -1
  13. package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +0 -1
  14. package/dist/cjs/shared/createGlobalContextShared.js +1 -5
  15. package/dist/cjs/shared/getProxyForPublicUsage.js +2 -2
  16. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  17. package/dist/cjs/utils/assertSetup.js +0 -3
  18. package/dist/cjs/utils/debug.js +0 -1
  19. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
  20. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
  21. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +1 -1
  22. package/dist/esm/client/runtime-client-routing/history.d.ts +2 -4
  23. package/dist/esm/client/runtime-client-routing/history.js +35 -13
  24. package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
  25. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
  26. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
  27. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +1 -1
  28. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -1
  29. package/dist/esm/node/prerender/runPrerender.d.ts +132 -40
  30. package/dist/esm/node/runtime/globalContext.d.ts +52 -32
  31. package/dist/esm/node/runtime/globalContext.js +18 -80
  32. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +1 -8
  33. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +33 -10
  34. package/dist/esm/node/runtime/renderPage/getPageAssets.js +2 -4
  35. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +66 -20
  36. package/dist/esm/node/runtime/renderPage.d.ts +33 -10
  37. package/dist/esm/node/runtime/utils.d.ts +0 -1
  38. package/dist/esm/node/runtime/utils.js +0 -1
  39. package/dist/esm/node/vite/index.js +0 -2
  40. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +1 -1
  41. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +1 -1
  42. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +1 -2
  43. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +0 -2
  44. package/dist/esm/node/vite/plugins/pluginCommon.d.ts +0 -3
  45. package/dist/esm/node/vite/plugins/pluginCommon.js +0 -1
  46. package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +0 -1
  47. package/dist/esm/shared/createGlobalContextShared.d.ts +3 -3
  48. package/dist/esm/shared/createGlobalContextShared.js +1 -5
  49. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  50. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  51. package/dist/esm/utils/assertSetup.js +0 -3
  52. package/dist/esm/utils/debug.d.ts +1 -1
  53. package/dist/esm/utils/debug.js +0 -1
  54. package/package.json +1 -10
  55. package/dist/cjs/node/vite/plugins/pluginViteRPC.js +0 -42
  56. package/dist/cjs/utils/getViteRPC.js +0 -79
  57. package/dist/esm/node/vite/plugins/pluginViteRPC.d.ts +0 -25
  58. package/dist/esm/node/vite/plugins/pluginViteRPC.js +0 -40
  59. package/dist/esm/utils/getViteRPC.d.ts +0 -6
  60. package/dist/esm/utils/getViteRPC.js +0 -77
@@ -32,7 +32,7 @@ function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGl
32
32
  /**
33
33
  * Whether the environment is client-side or server-side / pre-rendering.
34
34
  *
35
- * We recommend using `({}).SSR` instead, see https://vike.dev/globalContext
35
+ * We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
36
36
  */
37
37
  isClientSide: true,
38
38
  };
@@ -155,9 +155,6 @@ function setGlobalContext_isPrerendering() {
155
155
  setIsProduction(true);
156
156
  }
157
157
  function setGlobalContext_isProduction(isProduction, tolerateContraditction = false) {
158
- // TODO/now: try to remove globalObject.isProduction ?
159
- // TODO/now: `rename tolerateContraditction tolerateContradiction`
160
- tolerateContraditction = true;
161
158
  if (debug.isActivated)
162
159
  debug('setGlobalContext_isProduction()', { isProduction, tolerateContraditction });
163
160
  if (globalObject.isProduction === undefined) {
@@ -208,12 +205,7 @@ async function initGlobalContext() {
208
205
  const { isProduction } = globalObject;
209
206
  (0, utils_js_1.assert)(typeof isProduction === 'boolean');
210
207
  if (!isProduction) {
211
- if (isProcessSharedWithVite()) {
212
- await globalObject.viteDevServerPromise;
213
- }
214
- else {
215
- await updateUserFiles();
216
- }
208
+ await globalObject.viteDevServerPromise;
217
209
  (0, utils_js_1.assert)(globalObject.waitForUserFilesUpdate);
218
210
  await globalObject.waitForUserFilesUpdate;
219
211
  }
@@ -347,27 +339,16 @@ async function updateUserFiles() {
347
339
  // Avoid race condition: abort if there is a new globalObject.viteDevServer (happens when vite.config.js is modified => Vite's dev server is fully reloaded).
348
340
  viteDevServer !== globalObject.viteDevServer;
349
341
  const { viteDevServer } = globalObject;
342
+ (0, utils_js_1.assert)(viteDevServer);
350
343
  let hasError = false;
351
344
  let virtualFileExports;
352
345
  let err;
353
- if (viteDevServer) {
354
- try {
355
- virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileEntry_js_1.virtualFileIdEntryServer);
356
- }
357
- catch (err_) {
358
- hasError = true;
359
- err = err_;
360
- }
346
+ try {
347
+ virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileEntry_js_1.virtualFileIdEntryServer);
361
348
  }
362
- else {
363
- try {
364
- // We don't directly use import() to workaround what seems to be a Vite HMR bug: using import() breaks the HMR of normal non-worker apps.
365
- virtualFileExports = await __VIKE__DYNAMIC_IMPORT('virtual:vike:entry:server');
366
- }
367
- catch (err_) {
368
- hasError = true;
369
- err = err_;
370
- }
349
+ catch (err_) {
350
+ hasError = true;
351
+ err = err_;
371
352
  }
372
353
  if (isOutdated())
373
354
  return { success: false };
@@ -393,7 +374,7 @@ async function updateUserFiles() {
393
374
  async function setGlobalContext(virtualFileExports) {
394
375
  debug('setGlobalContext()');
395
376
  (0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
396
- const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
377
+ const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp);
397
378
  (0, assertV1Design_js_1.assertV1Design)(
398
379
  // pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
399
380
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
@@ -419,18 +400,23 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
419
400
  _pageRoutes: pageRoutes,
420
401
  _onBeforeRouteHook: onBeforeRouteHook,
421
402
  };
422
- const { viteDevServer, viteConfig, isPrerendering, isProduction } = globalObject;
403
+ const { viteDevServer, viteConfig, viteConfigRuntime, isPrerendering, isProduction } = globalObject;
423
404
  (0, utils_js_1.assert)(typeof isProduction === 'boolean');
424
405
  if (!isProduction) {
406
+ (0, utils_js_1.assert)(viteDevServer);
425
407
  (0, utils_js_1.assert)(globalContext); // main common requirement
408
+ (0, utils_js_1.assert)(viteConfig);
409
+ (0, utils_js_1.assert)(viteConfigRuntime);
426
410
  (0, utils_js_1.assert)(!isPrerendering);
427
411
  return {
428
412
  ...globalContextBase,
413
+ ...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
429
414
  _isProduction: false,
430
415
  _isPrerendering: false,
431
416
  assetsManifest: null,
432
417
  _viteDevServer: viteDevServer,
433
418
  viteConfig,
419
+ viteConfigRuntime,
434
420
  };
435
421
  }
436
422
  else {
@@ -441,9 +427,11 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
441
427
  (0, utils_js_1.assert)(assetsManifest);
442
428
  const globalContextBase2 = {
443
429
  ...globalContextBase,
430
+ ...resolveBaseRuntime(buildInfo.viteConfigRuntime, globalContext.config),
444
431
  _isProduction: true,
445
432
  assetsManifest,
446
433
  _viteDevServer: null,
434
+ viteConfigRuntime: buildInfo.viteConfigRuntime,
447
435
  _usesClientRouter: buildInfo.usesClientRouter,
448
436
  };
449
437
  if (isPrerendering) {
@@ -463,45 +451,14 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
463
451
  }
464
452
  }
465
453
  }
466
- async function addGlobalContextAsync(globalContext) {
467
- debug('addGlobalContextAsync()');
468
- let { viteConfigRuntime, buildInfo } = globalObject;
469
- if (!viteConfigRuntime) {
470
- if (buildInfo) {
471
- viteConfigRuntime = buildInfo.viteConfigRuntime;
472
- }
473
- else {
474
- if (!isProcessSharedWithVite()) {
475
- if (!globalObject.isProduction) {
476
- const rpc = (0, utils_js_1.getViteRPC)();
477
- viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
478
- }
479
- else {
480
- (0, utils_js_1.assert)(false); // production => globalObject.buildInfo should be set
481
- }
482
- }
483
- else {
484
- (0, utils_js_1.assert)(false); // process shared with Vite => globalObject.viteConfigRuntime should be set
485
- }
486
- }
487
- }
488
- (0, utils_js_1.assert)(viteConfigRuntime);
489
- return {
490
- viteConfigRuntime,
491
- ...resolveBaseRuntime(viteConfigRuntime, globalContext.config),
492
- };
493
- }
494
454
  function clearGlobalContext() {
495
455
  debug('clearGlobalContext()');
496
456
  (0, utils_js_1.objectReplace)(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
497
457
  }
498
458
  function getInitialGlobalObject() {
499
- const isProduction = getIsProductionStatic();
500
- if (debug.isActivated)
501
- debug('getInitialGlobalObject()', { isProduction });
459
+ debug('getInitialGlobalObject()');
502
460
  const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = (0, utils_js_1.genPromise)();
503
461
  return {
504
- isProduction,
505
462
  viteDevServerPromise,
506
463
  viteDevServerPromiseResolve,
507
464
  };
@@ -512,22 +469,3 @@ function resolveBaseRuntime(viteConfigRuntime, config) {
512
469
  const baseAssetsUnresolved = config.baseAssets ?? null;
513
470
  return (0, resolveBase_js_1.resolveBase)(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
514
471
  }
515
- function getIsProductionStatic() {
516
- // TODO/now add @ts-ignore comments
517
- // @ts-ignore
518
- if (!({}))
519
- return undefined;
520
- // @ts-ignore
521
- const PROD = ({}).PROD;
522
- return PROD;
523
- }
524
- function isProcessSharedWithVite() {
525
- const ret = globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE;
526
- if (globalObject.isProcessSharedWithVite !== undefined) {
527
- (0, utils_js_1.assert)(globalObject.isProcessSharedWithVite === ret);
528
- }
529
- else {
530
- globalObject.isProcessSharedWithVite = ret;
531
- }
532
- return ret;
533
- }
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getViteDevScript = getViteDevScript;
7
- const getViteRPC_js_1 = require("../../../../utils/getViteRPC.js");
8
7
  const utils_js_1 = require("../../utils.js");
9
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
9
  const reachOutCTA = 'Create a new GitHub issue to discuss a solution.';
@@ -17,13 +16,7 @@ async function getViteDevScript(pageContext) {
17
16
  const fakeHtmlBegin = '<html> <head>'; // White space to test whether user is using a minifier
18
17
  const fakeHtmlEnd = '</head><body></body></html>';
19
18
  let fakeHtml = fakeHtmlBegin + fakeHtmlEnd;
20
- if (viteDevServer) {
21
- fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
22
- }
23
- else {
24
- const rpc = (0, getViteRPC_js_1.getViteRPC)();
25
- fakeHtml = await rpc.transformIndexHtmlRPC(fakeHtml);
26
- }
19
+ fakeHtml = await viteDevServer.transformIndexHtml('/', fakeHtml);
27
20
  (0, utils_js_1.assertUsage)(!fakeHtml.includes('vite-plugin-pwa'), `The HTML transformer of ${picocolors_1.default.cyan('vite-plugin-pwa')} cannot be applied, see workaround at https://github.com/vikejs/vike/issues/388#issuecomment-1199280084`);
28
21
  (0, utils_js_1.assertUsage)(!fakeHtml.startsWith(fakeHtmlBegin.replace(' ', '')), `Vite plugins that minify the HTML cannot be applied, see https://github.com/vikejs/vike/issues/224`);
29
22
  (0, utils_js_1.assertUsage)(fakeHtml.startsWith(fakeHtmlBegin) && fakeHtml.endsWith(fakeHtmlEnd), `You are using a Vite Plugin that transforms the HTML in a way that conflicts with Vike. ${reachOutCTA}`);
@@ -17,9 +17,7 @@ async function getPageAssets(pageContext, clientDependencies, clientEntries) {
17
17
  const { _isProduction: isProduction } = globalContext;
18
18
  const isDev = !isProduction;
19
19
  const { assetUrls, clientEntriesSrc } = isDev
20
- ? !globalContext._viteDevServer
21
- ? await (0, utils_js_1.getViteRPC)().retrievePageAssetsDevRPC(clientDependencies, clientEntries)
22
- : await retrievePageAssetsDev(globalContext._viteDevServer, clientDependencies, clientEntries)
20
+ ? await retrievePageAssetsDev(globalContext._viteDevServer, clientDependencies, clientEntries)
23
21
  : retrievePageAssetsProd(globalContext.assetsManifest, clientDependencies, clientEntries, resolveIncludeAssetsImportedByServer(globalContext.config));
24
22
  let pageAssets = [];
25
23
  (0, utils_js_1.unique)([...clientEntriesSrc, ...assetUrls]).forEach((src) => {
@@ -76,4 +76,3 @@ __exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
76
76
  __exportStar(require("../../utils/genPromise.js"), exports);
77
77
  __exportStar(require("../../utils/augmentType.js"), exports);
78
78
  __exportStar(require("../../utils/changeEnumerable.js"), exports);
79
- __exportStar(require("../../utils/getViteRPC.js"), exports);
@@ -29,7 +29,6 @@ const resolveClientEntriesDev_js_1 = require("./shared/resolveClientEntriesDev.j
29
29
  const pluginWorkaroundCssModuleHmr_js_1 = require("./plugins/pluginWorkaroundCssModuleHmr.js");
30
30
  const pluginWorkaroundVite6HmrRegression_js_1 = require("./plugins/pluginWorkaroundVite6HmrRegression.js");
31
31
  const pluginReplaceConstants_js_1 = require("./plugins/pluginReplaceConstants.js");
32
- const pluginViteRPC_js_1 = require("./plugins/pluginViteRPC.js");
33
32
  // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
34
33
  (0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
35
34
  // Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
@@ -49,7 +48,6 @@ function plugin(vikeVitePluginOptions = {}) {
49
48
  (0, pluginWorkaroundCssModuleHmr_js_1.pluginWorkaroundCssModuleHmr)(),
50
49
  (0, pluginWorkaroundVite6HmrRegression_js_1.pluginWorkaroundVite6HmrRegression)(),
51
50
  (0, pluginReplaceConstants_js_1.pluginReplaceConstants)(),
52
- (0, pluginViteRPC_js_1.pluginViteRPC)(),
53
51
  ];
54
52
  Object.assign(plugins, { _vikeVitePluginOptions: vikeVitePluginOptions });
55
53
  return plugins;
@@ -16,8 +16,7 @@ const isViteServerBuild_js_1 = require("../../shared/isViteServerBuild.js");
16
16
  const getOutDirs_js_1 = require("../../shared/getOutDirs.js");
17
17
  const handleAssetsManifest_js_1 = require("./handleAssetsManifest.js");
18
18
  const getPageAssets_js_1 = require("../../../runtime/renderPage/getPageAssets.js");
19
- // TODO/now: stop setting `manifest` altogether and use the resolved value instead? So that other tools can easily read the manifest (e.g. @cloudflare/plugin-vite reads the manifest).
20
- const manifestTempFile = '.vite/manifest.json';
19
+ const manifestTempFile = '_temp_manifest.json';
21
20
  exports.manifestTempFile = manifestTempFile;
22
21
  function pluginBuildConfig() {
23
22
  let config;
@@ -18,8 +18,6 @@ function pluginDistFileNames() {
18
18
  apply: 'build',
19
19
  enforce: 'post',
20
20
  configResolved(config) {
21
- // TODO/now remove
22
- // if (true as boolean) return
23
21
  const rollupOutputs = getRollupOutputs(config);
24
22
  // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
25
23
  rollupOutputs.forEach((rollupOutput) => {
@@ -16,7 +16,6 @@ const resolveVikeConfigInternal_js_1 = require("../shared/resolveVikeConfigInter
16
16
  const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
17
17
  const context_js_2 = require("../../prerender/context.js");
18
18
  const pluginName = 'vike:pluginCommon';
19
- globalThis.__VIKE__IS_PROCESS_SHARED_WITH_VITE = true;
20
19
  function pluginCommon(vikeVitePluginOptions) {
21
20
  return [
22
21
  {
@@ -12,7 +12,7 @@ const normalizeId_js_1 = require("../shared/normalizeId.js");
12
12
  const isViteServerBuild_js_1 = require("../shared/isViteServerBuild.js");
13
13
  const applyRegExWithMagicString_js_1 = require("../shared/applyRegExWithMagicString.js");
14
14
  // TO-DO/eventually:
15
- // - Make ({}) work inside +config.js
15
+ // - Make import.meta.env work inside +config.js
16
16
  // - For it to work, we'll probably need the user to define the settings (e.g. `envDir`) for loadEnv() inside vike.config.js instead of vite.config.js
17
17
  // - Or stop using Vite's `mode` implementation and have Vike implement its own `mode` feature? (So that the only dependencies are `$ vike build --mode staging` and `$ MODE=staging vike build`.)
18
18
  const PUBLIC_ENV_PREFIX = 'PUBLIC_ENV__';
@@ -39,7 +39,7 @@ function pluginEnvVars() {
39
39
  (0, utils_js_1.assertPosixPath)(config.root);
40
40
  if (!id.startsWith(config.root))
41
41
  return;
42
- if (!code.includes('({}).'))
42
+ if (!code.includes('import.meta.env.'))
43
43
  return;
44
44
  const isBuild = config.command === 'build';
45
45
  const isClientSide = !(0, isViteServerBuild_js_1.isViteServerBuild_safe)(config, options);
@@ -52,7 +52,7 @@ function pluginEnvVars() {
52
52
  return !envPrefix.some((prefix) => key.startsWith(prefix));
53
53
  })
54
54
  .map(([envName, envVal]) => {
55
- const envStatement = `({}).${envName}`;
55
+ const envStatement = `import.meta.env.${envName}`;
56
56
  const envStatementRegExpStr = (0, utils_js_1.escapeRegex)(envStatement) + '\\b';
57
57
  // Security check
58
58
  {
@@ -81,12 +81,12 @@ function injectHmr(code, isClientSide, isProduction) {
81
81
  }
82
82
  if (isClientSide) {
83
83
  code += '\n';
84
- code += `if ((undefined)) (undefined).accept((mod) => { exportNames.length=0; exportNames.push(...mod.exportNames); });`;
84
+ code += `if (import.meta.hot) import.meta.hot.accept((mod) => { exportNames.length=0; exportNames.push(...mod.exportNames); });`;
85
85
  }
86
86
  else {
87
87
  // Ensure Vite considers the module as `isSelfAccepting`. (Needed because Vite's module graph erroneously conflates the Vite server-side modules with their client-side counterparts.)
88
88
  code += '\n';
89
- code += 'if(false){(undefined).accept(()=>{})};';
89
+ code += 'if(false){import.meta.hot.accept(()=>{})};';
90
90
  }
91
91
  return code;
92
92
  }
@@ -26,7 +26,7 @@ function pluginReplaceConstants() {
26
26
  (0, utils_js_1.assertPosixPath)(config.root);
27
27
  if (!id.startsWith(config.root))
28
28
  return;
29
- if (!code.includes('({}).'))
29
+ if (!code.includes('import.meta.env.'))
30
30
  return;
31
31
  const isBuild = config.command === 'build';
32
32
  (0, utils_js_1.assert)(isBuild);
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyRegExpWithMagicString = applyRegExpWithMagicString;
4
- // TODO/now: replace with .replaceAll() ?
5
4
  function applyRegExpWithMagicString(magicString, regExp, replacement) {
6
5
  const envStatementRegEx = typeof regExp === 'string' ? new RegExp(regExp, 'g') : regExp;
7
6
  let match;
@@ -12,7 +12,7 @@ const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGl
12
12
  exports.getGlobalContextSyncErrMsg = getGlobalContextSyncErrMsg;
13
13
  async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext,
14
14
  // TO-DO/next-major-release: we'll be able to remove addGlobalContextTmp after loadPageRoutes() is sync (it will be sync after we remove the old design)
15
- addGlobalContextTmp, addGlobalContextAsync) {
15
+ addGlobalContextTmp) {
16
16
  const globalContext = createGlobalContextBase(virtualFileExports);
17
17
  let isNewGlobalContext;
18
18
  if (!globalObject.globalContext) {
@@ -34,10 +34,6 @@ addGlobalContextTmp, addGlobalContextAsync) {
34
34
  const globalContextAdded = await addGlobalContextTmp?.(globalContext);
35
35
  (0, utils_js_1.objectAssign)(globalContext, globalContextAdded);
36
36
  }
37
- {
38
- const globalContextAddedAsync = await addGlobalContextAsync?.(globalContext);
39
- (0, utils_js_1.objectAssign)(globalContext, globalContextAddedAsync);
40
- }
41
37
  const onCreateGlobalContextHooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(globalContext._pageConfigGlobal, 'onCreateGlobalContext');
42
38
  let hooksCalled = false;
43
39
  if (!hooksAreEqual(globalObject.onCreateGlobalContextHooks ?? [], onCreateGlobalContextHooks)) {
@@ -43,8 +43,8 @@ function onInternalProp(propStr, objName) {
43
43
  // - We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
44
44
  // - TO-DO/eventually: use import.meta.CLIENT instead of isBrowser()
45
45
  // - Where import.meta.CLIENT is defined by Vike
46
- // - Using ({}).CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_({})
47
- // - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use ({}).SSR
46
+ // - Using import.meta.env.CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_import.meta.env
47
+ // - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use import.meta.env.SSR
48
48
  if ((0, utils_js_1.isBrowser)())
49
49
  return;
50
50
  // TO-DO/soon/proxy: remove this and only warn on built-in access instead
@@ -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.236-commit-64431e7';
5
+ exports.PROJECT_VERSION = '0.4.236-commit-e752d12';
@@ -29,9 +29,6 @@ function assertIsNotProductionRuntime() {
29
29
  setup.shouldNotBeProduction = true;
30
30
  }
31
31
  function onSetupRuntime() {
32
- // TODO/now
33
- if (true)
34
- return;
35
32
  if (debug.isActivated)
36
33
  debug('assertSetup()', new Error().stack);
37
34
  if (isTest())
@@ -35,7 +35,6 @@ const flags = [
35
35
  'vike:setup',
36
36
  'vike:stream',
37
37
  'vike:virtualFiles',
38
- 'vike:vite-rpc',
39
38
  ];
40
39
  const flagsSkipWildcard = ['vike:log'];
41
40
  const flagRegex = /\bvike:[a-zA-Z-]+/g;
@@ -30,7 +30,7 @@ declare function createPageContextClientSide(urlOriginal: string): Promise<{
30
30
  } & {
31
31
  _pageRoutes: import("../../__internal/index.js").PageRoutes;
32
32
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
33
- } & Record<string, any>;
33
+ };
34
34
  _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
35
35
  _urlHandler: null;
36
36
  _urlRewrite: null | string;
@@ -50,7 +50,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
50
50
  } & {
51
51
  _pageRoutes: import("../../__internal/index.js").PageRoutes;
52
52
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
53
- } & Record<string, any>;
53
+ };
54
54
  _pageFilesAll: PageFile[];
55
55
  _urlHandler: null;
56
56
  _urlRewrite: null | string;
@@ -264,7 +264,7 @@ declare function getPageContextFromClientHooks(pageContext: {
264
264
  } & {
265
265
  _pageRoutes: import("../../__internal/index.js").PageRoutes;
266
266
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
267
- } & Record<string, any>;
267
+ };
268
268
  _pageFilesAll: PageFile[];
269
269
  _urlHandler: null;
270
270
  _urlRewrite: null | string;
@@ -27,4 +27,4 @@ declare const getGlobalContextClientInternal: () => Promise<{
27
27
  } & {
28
28
  _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
29
29
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
30
- } & Record<string, any>>;
30
+ }>;
@@ -2,8 +2,7 @@ export { pushHistoryState };
2
2
  export { replaceHistoryStateOriginal };
3
3
  export { onPopStateBegin };
4
4
  export { saveScrollPosition };
5
- export { initHistoryState };
6
- export { monkeyPatchHistoryAPI };
5
+ export { initHistory };
7
6
  export type { HistoryInfo };
8
7
  export type { ScrollPosition };
9
8
  type StateEnhanced = {
@@ -19,7 +18,6 @@ type ScrollPosition = {
19
18
  declare function saveScrollPosition(): void;
20
19
  declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
21
20
  declare function replaceHistoryStateOriginal(state: unknown, url: string): void;
22
- declare function monkeyPatchHistoryAPI(): void;
23
21
  type HistoryInfo = {
24
22
  url: `/${string}`;
25
23
  state: StateEnhanced;
@@ -29,4 +27,4 @@ declare function onPopStateBegin(): {
29
27
  previous: HistoryInfo;
30
28
  current: HistoryInfo;
31
29
  };
32
- declare function initHistoryState(): void;
30
+ declare function initHistory(): void;
@@ -2,12 +2,15 @@ export { pushHistoryState };
2
2
  export { replaceHistoryStateOriginal };
3
3
  export { onPopStateBegin };
4
4
  export { saveScrollPosition };
5
- export { initHistoryState };
6
- export { monkeyPatchHistoryAPI };
5
+ export { initHistory };
7
6
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
8
7
  import { assert, assertUsage, getGlobalObject, isObject } from './utils.js';
9
- initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
10
- const globalObject = getGlobalObject('runtime-client-routing/history.ts', { previous: getHistoryInfo() });
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();
11
14
  // `window.history.state === null` when:
12
15
  // - The very first render
13
16
  // - Click on `<a href="#some-hash" />`
@@ -41,7 +44,7 @@ function enhance(stateNotEnhanced) {
41
44
  _isVikeEnhanced: true,
42
45
  };
43
46
  }
44
- assert(isVikeEnhanced(stateVikeEnhanced));
47
+ assertIsVikeEnhanced(stateVikeEnhanced);
45
48
  return stateVikeEnhanced;
46
49
  }
47
50
  function getState() {
@@ -51,7 +54,7 @@ function getState() {
51
54
  // - Therefore, we have to monkey patch history.pushState() and history.replaceState()
52
55
  // - Therefore, we need the assert() below to ensure history.state has been enhanced by Vike
53
56
  // - If users stumble upon this assert() then let's make it a assertUsage()
54
- assert(isVikeEnhanced(state), { state });
57
+ assertIsVikeEnhanced(state);
55
58
  return state;
56
59
  }
57
60
  function getStateNotEnhanced() {
@@ -90,6 +93,7 @@ function pushHistoryState(url, overwriteLastHistoryEntry) {
90
93
  function replaceHistoryState(state, url) {
91
94
  const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
92
95
  window.history.replaceState(state, '', url_);
96
+ assertIsVikeEnhanced(getState());
93
97
  }
94
98
  function replaceHistoryStateOriginal(state, url) {
95
99
  // Bypass all monkey patches.
@@ -100,7 +104,11 @@ function replaceHistoryStateOriginal(state, url) {
100
104
  // - history.pushState()
101
105
  // - history.replaceState()
102
106
  function monkeyPatchHistoryAPI() {
103
- ;
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);
104
112
  ['pushState', 'replaceState'].forEach((funcName) => {
105
113
  const funcOriginal = window.history[funcName].bind(window.history);
106
114
  window.history[funcName] = (stateOriginal = {}, ...rest) => {
@@ -114,11 +122,14 @@ function monkeyPatchHistoryAPI() {
114
122
  triggeredBy: 'user',
115
123
  ...stateOriginal,
116
124
  };
117
- assert(isVikeEnhanced(stateEnhanced));
118
- const ret = funcOriginal(stateEnhanced, ...rest);
125
+ assertIsVikeEnhanced(stateEnhanced);
126
+ funcOriginal(stateEnhanced, ...rest);
127
+ assertIsVikeEnhanced(getState());
119
128
  globalObject.previous = getHistoryInfo();
120
- return ret;
121
129
  };
130
+ window.history[funcName]._isVikeMonkeyPatch = true;
131
+ // Ensure assert() above isn't a false positive
132
+ assert(window.history.pushState !== History.prototype.pushState);
122
133
  });
123
134
  }
124
135
  function isVikeEnhanced(state) {
@@ -136,6 +147,16 @@ function isVikeEnhanced(state) {
136
147
  }
137
148
  return false;
138
149
  }
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
+ }
139
160
  function getHistoryInfo() {
140
161
  return {
141
162
  url: getCurrentUrl(),
@@ -147,11 +168,12 @@ function onPopStateBegin() {
147
168
  const isHistoryStateEnhanced = window.history.state !== null;
148
169
  if (!isHistoryStateEnhanced)
149
170
  enhanceHistoryState();
150
- assert(isVikeEnhanced(window.history.state));
171
+ assertIsVikeEnhanced(window.history.state);
151
172
  const current = getHistoryInfo();
152
173
  globalObject.previous = current;
153
174
  return { isHistoryStateEnhanced, previous, current };
154
175
  }
155
- function initHistoryState() {
156
- enhanceHistoryState();
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`
157
179
  }
@@ -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 { initHistoryState, monkeyPatchHistoryAPI } from './history.js';
9
+ import { initHistory } from './history.js';
10
10
  async function initClientRouter() {
11
11
  // Init navigation history and scroll restoration
12
12
  initHistoryAndScroll();
@@ -29,8 +29,7 @@ async function renderFirstPage() {
29
29
  }
30
30
  function initHistoryAndScroll() {
31
31
  scrollRestoration_init();
32
- monkeyPatchHistoryAPI();
33
- initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
32
+ initHistory(); // we redundantly call initHistory() to ensure it's called early
34
33
  autoSaveScrollPosition();
35
34
  // Handle back-/forward navigation
36
35
  initOnPopState();
@@ -63,7 +63,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
63
63
  } & {
64
64
  _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
65
65
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
66
- } & Record<string, any>;
66
+ };
67
67
  _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
68
68
  _urlHandler: null;
69
69
  _urlRewrite: null | string;
@@ -26,7 +26,7 @@ declare function createPageContextClientSide(): Promise<{
26
26
  };
27
27
  } & {
28
28
  isClientSide: true;
29
- } & object & Record<string, any>;
29
+ } & object;
30
30
  _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
31
31
  isBackwardNavigation: null;
32
32
  _hasPageContextFromServer: true;
@@ -24,4 +24,4 @@ declare const getGlobalContextClientInternal: () => Promise<{
24
24
  };
25
25
  } & {
26
26
  isClientSide: true;
27
- } & object & Record<string, any>>;
27
+ } & object>;
@@ -30,7 +30,7 @@ declare function createGetGlobalContextClient<GlobalContextAddendum extends obje
30
30
  * We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
31
31
  */
32
32
  isClientSide: true;
33
- } & Awaited<GlobalContextAddendum> & Record<string, any>>;
33
+ } & Awaited<GlobalContextAddendum>>;
34
34
  type NeverExported = never;
35
35
  declare function getGlobalContext(): Promise<NeverExported>;
36
36
  declare function getGlobalContextSync(): NeverExported;