vike 0.4.236-commit-79f1ef0 → 0.4.236-commit-cd565e9

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.
@@ -278,7 +278,7 @@ async function loadBuildEntry(outDir) {
278
278
  assertBuildEntry(buildEntry);
279
279
  globalObject.assetsManifest = buildEntry.assetsManifest;
280
280
  globalObject.buildInfo = buildEntry.buildInfo;
281
- await setGlobalContext(buildEntry.virtualFileExports);
281
+ await createGlobalContext(buildEntry.virtualFileExports);
282
282
  }
283
283
  // This is the production entry, see:
284
284
  // https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
@@ -323,6 +323,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
323
323
  (0, utils_js_1.assertUsage)(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
324
324
  }
325
325
  async function updateUserFiles() {
326
+ debug('updateUserFiles()');
326
327
  (0, utils_js_1.assert)(!globalObject.isProduction);
327
328
  const { promise, resolve } = (0, utils_js_1.genPromise)();
328
329
  globalObject.waitForUserFilesUpdate = promise;
@@ -405,7 +406,7 @@ async function updateUserFiles() {
405
406
  return { success: false };
406
407
  }
407
408
  try {
408
- await setGlobalContext(virtualFileExports);
409
+ await createGlobalContext(virtualFileExports);
409
410
  }
410
411
  catch (err_) {
411
412
  hasError = true;
@@ -417,8 +418,8 @@ async function updateUserFiles() {
417
418
  return onError(err);
418
419
  return onSuccess();
419
420
  }
420
- async function setGlobalContext(virtualFileExports) {
421
- debug('setGlobalContext()');
421
+ async function createGlobalContext(virtualFileExports) {
422
+ debug('createGlobalContext()');
422
423
  (0, utils_js_1.assert)(!(0, getVikeConfigError_js_1.getVikeConfigErrorBuild)());
423
424
  const globalContext = await (0, createGlobalContextShared_js_1.createGlobalContextShared)(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
424
425
  (0, assertV1Design_js_1.assertV1Design)(
@@ -426,8 +427,8 @@ async function setGlobalContext(virtualFileExports) {
426
427
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
427
428
  assertGlobalContextIsDefined();
428
429
  (0, utils_js_1.onSetupRuntime)();
429
- debug('setGlobalContext() - done');
430
- // Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
430
+ debug('createGlobalContext() - done');
431
+ // Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
431
432
  return globalContext;
432
433
  }
433
434
  async function addGlobalContextTmp(globalContext) {
@@ -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-79f1ef0';
5
+ exports.PROJECT_VERSION = '0.4.236-commit-cd565e9';
@@ -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 = {
@@ -18,8 +17,7 @@ type ScrollPosition = {
18
17
  };
19
18
  declare function saveScrollPosition(): void;
20
19
  declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
21
- declare function replaceHistoryStateOriginal(state: unknown, url: string): void;
22
- declare function monkeyPatchHistoryAPI(): void;
20
+ declare function replaceHistoryStateOriginal(state: unknown, url: Parameters<typeof window.history.replaceState>[2]): 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
- 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() });
7
+ import { assert, assertUsage, getGlobalObject, isObject, deepEqual } from './utils.js';
8
+ const globalObject = getGlobalObject('history.ts', {
9
+ monkeyPatched: false,
10
+ previous: undefined,
11
+ });
12
+ initHistory(); // we redundantly call initHistory() to ensure it's called early
13
+ globalObject.previous = getHistoryInfo();
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,9 @@ 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;
104
110
  ['pushState', 'replaceState'].forEach((funcName) => {
105
111
  const funcOriginal = window.history[funcName].bind(window.history);
106
112
  window.history[funcName] = (stateOriginal = {}, ...rest) => {
@@ -114,11 +120,21 @@ function monkeyPatchHistoryAPI() {
114
120
  triggeredBy: 'user',
115
121
  ...stateOriginal,
116
122
  };
117
- assert(isVikeEnhanced(stateEnhanced));
118
- const ret = funcOriginal(stateEnhanced, ...rest);
123
+ assertIsVikeEnhanced(stateEnhanced);
124
+ funcOriginal(stateEnhanced, ...rest);
125
+ assertIsVikeEnhanced(getState());
119
126
  globalObject.previous = getHistoryInfo();
120
- return ret;
127
+ // Workaround https://github.com/vikejs/vike/issues/2504#issuecomment-3149764736
128
+ assert(deepEqual(window.history.state, stateEnhanced));
129
+ queueMicrotask(() => {
130
+ if (deepEqual(window.history.state, stateEnhanced))
131
+ return;
132
+ Object.assign(stateEnhanced, window.history.state);
133
+ replaceHistoryStateOriginal(stateEnhanced, rest[1]);
134
+ assert(deepEqual(window.history.state, stateEnhanced));
135
+ });
121
136
  };
137
+ window.history[funcName]._isVikeMonkeyPatch = true;
122
138
  });
123
139
  }
124
140
  function isVikeEnhanced(state) {
@@ -136,6 +152,16 @@ function isVikeEnhanced(state) {
136
152
  }
137
153
  return false;
138
154
  }
155
+ function assertIsVikeEnhanced(state) {
156
+ if (isVikeEnhanced(state))
157
+ return;
158
+ assert(false, {
159
+ state,
160
+ // TO-DO/eventually: remove _isVikeMonkeyPatch debug info to save KBs
161
+ pushStateIsVikeMonkeyPatch: window.history.pushState._isVikeMonkeyPatch,
162
+ replaceStateIsVikeMonkeyPatch: window.history.replaceState._isVikeMonkeyPatch,
163
+ });
164
+ }
139
165
  function getHistoryInfo() {
140
166
  return {
141
167
  url: getCurrentUrl(),
@@ -147,11 +173,12 @@ function onPopStateBegin() {
147
173
  const isHistoryStateEnhanced = window.history.state !== null;
148
174
  if (!isHistoryStateEnhanced)
149
175
  enhanceHistoryState();
150
- assert(isVikeEnhanced(window.history.state));
176
+ assertIsVikeEnhanced(window.history.state);
151
177
  const current = getHistoryInfo();
152
178
  globalObject.previous = current;
153
179
  return { isHistoryStateEnhanced, previous, current };
154
180
  }
155
- function initHistoryState() {
156
- enhanceHistoryState();
181
+ function initHistory() {
182
+ 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)
183
+ enhanceHistoryState(); // enhance very first window.history.state which is `null`
157
184
  }
@@ -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();
@@ -111,8 +111,8 @@ async function renderPageClientSide(renderArgs) {
111
111
  if (isFirstRender) {
112
112
  // Set pageContext properties set by onBeforeRoute()
113
113
  // - But we skip pageId and routeParams because routing may have been aborted by a server-side `throw render()`
114
- const { pageId, routeParams, ...pageContextFromRouteRest } = pageContextFromRoute;
115
- objectAssign(pageContext, pageContextFromRouteRest);
114
+ const { pageId, routeParams, ...rest } = pageContextFromRoute;
115
+ objectAssign(pageContext, rest);
116
116
  assert(hasProp(pageContext, 'routeParams', 'string{}')); // Help TS
117
117
  }
118
118
  else {
@@ -22,3 +22,4 @@ export * from '../../utils/PROJECT_VERSION.js';
22
22
  export * from '../../utils/genPromise.js';
23
23
  export * from '../../utils/catchInfiniteLoop.js';
24
24
  export * from '../../utils/changeEnumerable.js';
25
+ export * from '../../utils/deepEqual.js';
@@ -26,3 +26,4 @@ export * from '../../utils/PROJECT_VERSION.js';
26
26
  export * from '../../utils/genPromise.js';
27
27
  export * from '../../utils/catchInfiniteLoop.js';
28
28
  export * from '../../utils/changeEnumerable.js';
29
+ export * from '../../utils/deepEqual.js';
@@ -27,7 +27,7 @@ import type { GlobalContext } from '../../types/PageContext.js';
27
27
  import type { Hook } from '../../shared/hooks/getHook.js';
28
28
  declare const vikeConfigErrorRecoverMsg: "Vike config loaded";
29
29
  type GlobalContextServer = Pick<GlobalContextServerInternal, 'assetsManifest' | 'config' | 'viteConfig' | 'viteConfigRuntime' | 'pages' | 'baseServer' | 'baseAssets' | 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextServer;
30
- type GlobalContextServerInternal = Awaited<ReturnType<typeof setGlobalContext>>;
30
+ type GlobalContextServerInternal = Awaited<ReturnType<typeof createGlobalContext>>;
31
31
  declare function getGlobalContextServerInternal(): Promise<{
32
32
  globalContext: (Record<string, unknown> & {
33
33
  isGlobalContext: true;
@@ -190,7 +190,7 @@ declare function assertBuildInfo(buildInfo: unknown): asserts buildInfo is Build
190
190
  declare function updateUserFiles(): Promise<{
191
191
  success: boolean;
192
192
  }>;
193
- declare function setGlobalContext(virtualFileExports: unknown): Promise<{
193
+ declare function createGlobalContext(virtualFileExports: unknown): Promise<{
194
194
  isGlobalContext: true;
195
195
  _isOriginalObject: true;
196
196
  _virtualFileExports: unknown;
@@ -274,7 +274,7 @@ async function loadBuildEntry(outDir) {
274
274
  assertBuildEntry(buildEntry);
275
275
  globalObject.assetsManifest = buildEntry.assetsManifest;
276
276
  globalObject.buildInfo = buildEntry.buildInfo;
277
- await setGlobalContext(buildEntry.virtualFileExports);
277
+ await createGlobalContext(buildEntry.virtualFileExports);
278
278
  }
279
279
  // This is the production entry, see:
280
280
  // https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
@@ -319,6 +319,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
319
319
  assertUsage(versionAtBuildTime === versionAtRuntime, `Re-build your app (you're using ${pretty(versionAtRuntime)} but your app was built with ${pretty(versionAtBuildTime)})`);
320
320
  }
321
321
  async function updateUserFiles() {
322
+ debug('updateUserFiles()');
322
323
  assert(!globalObject.isProduction);
323
324
  const { promise, resolve } = genPromise();
324
325
  globalObject.waitForUserFilesUpdate = promise;
@@ -401,7 +402,7 @@ async function updateUserFiles() {
401
402
  return { success: false };
402
403
  }
403
404
  try {
404
- await setGlobalContext(virtualFileExports);
405
+ await createGlobalContext(virtualFileExports);
405
406
  }
406
407
  catch (err_) {
407
408
  hasError = true;
@@ -413,8 +414,8 @@ async function updateUserFiles() {
413
414
  return onError(err);
414
415
  return onSuccess();
415
416
  }
416
- async function setGlobalContext(virtualFileExports) {
417
- debug('setGlobalContext()');
417
+ async function createGlobalContext(virtualFileExports) {
418
+ debug('createGlobalContext()');
418
419
  assert(!getVikeConfigErrorBuild());
419
420
  const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
420
421
  assertV1Design(
@@ -422,8 +423,8 @@ async function setGlobalContext(virtualFileExports) {
422
423
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
423
424
  assertGlobalContextIsDefined();
424
425
  onSetupRuntime();
425
- debug('setGlobalContext() - done');
426
- // Never actually used, only used for TypeScript `ReturnType<typeof setGlobalContext>`
426
+ debug('createGlobalContext() - done');
427
+ // Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
427
428
  return globalContext;
428
429
  }
429
430
  async function addGlobalContextTmp(globalContext) {
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.236-commit-79f1ef0";
1
+ export declare const PROJECT_VERSION: "0.4.236-commit-cd565e9";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.236-commit-79f1ef0';
2
+ export const PROJECT_VERSION = '0.4.236-commit-cd565e9';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.236-commit-79f1ef0",
3
+ "version": "0.4.236-commit-cd565e9",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {