vike 0.4.167-commit-c08a6bb → 0.4.167-commit-aa83fde

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = exports.projectInfo = void 0;
4
- const PROJECT_VERSION = '0.4.167-commit-c08a6bb';
4
+ const PROJECT_VERSION = '0.4.167-commit-aa83fde';
5
5
  exports.PROJECT_VERSION = PROJECT_VERSION;
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
@@ -3,6 +3,7 @@ type HistoryState = {
3
3
  timestamp?: number;
4
4
  scrollPosition?: null | ScrollPosition;
5
5
  triggeredBy?: 'user' | 'vike' | 'browser';
6
+ _isVikeEnhanced: true;
6
7
  };
7
8
  type ScrollPosition = {
8
9
  x: number;
@@ -1,6 +1,5 @@
1
1
  export { initHistoryState, getHistoryState, pushHistory, saveScrollPosition, monkeyPatchHistoryPushState };
2
- import { assert, assertUsage, getGlobalObject, hasProp, isObject } from './utils.js';
3
- const globalObject = getGlobalObject('history.ts', {});
2
+ import { assert, assertUsage, hasProp, isObject } from './utils.js';
4
3
  // Fill missing state information:
5
4
  // - `history.state` can uninitialized (i.e. `null`):
6
5
  // - The very first render
@@ -8,9 +7,10 @@ const globalObject = getGlobalObject('history.ts', {});
8
7
  // - The user clicks on an anchor link `<a href="#section">Section</a>` (Vike's `onLinkClick()` handler skips hash links).
9
8
  // - State information may be incomplete if `history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
10
9
  function initHistoryState() {
10
+ // No way found to add TypeScript types to `window.history.state`: https://github.com/microsoft/TypeScript/issues/36178
11
11
  let state = window.history.state;
12
12
  if (!state) {
13
- state = {};
13
+ state = { _isVikeEnhanced: true };
14
14
  }
15
15
  let hasModifications = false;
16
16
  if (!('timestamp' in state)) {
@@ -49,7 +49,7 @@ function saveScrollPosition() {
49
49
  function pushHistory(url, overwriteLastHistoryEntry) {
50
50
  if (!overwriteLastHistoryEntry) {
51
51
  const timestamp = getTimestamp();
52
- pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike' }, url);
52
+ pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike', _isVikeEnhanced: true }, url);
53
53
  }
54
54
  else {
55
55
  replaceHistoryState(getHistoryState(), url);
@@ -69,25 +69,29 @@ function assertState(state) {
69
69
  }
70
70
  }
71
71
  function replaceHistoryState(state, url) {
72
- window.history.replaceState(state, '', url ?? /* Passing `undefined` chokes older Edge versions */ null);
72
+ const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
73
+ window.history.replaceState(state, '', url_);
73
74
  }
74
75
  function pushHistoryState(state, url) {
75
- pushStateOriginal(state, '', url);
76
+ // Vike should call window.history.pushState() (and not the orignal `pushStateOriginal()`) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls, see https://github.com/vikejs/vike/issues/1582.
77
+ window.history.pushState(state, '', url);
76
78
  }
77
79
  function monkeyPatchHistoryPushState() {
78
- globalObject.pushStateOriginal = globalObject.pushStateOriginal ?? window.history.pushState;
79
- window.history.pushState = (stateFromUser = {}, ...rest) => {
80
- assertUsage(null === stateFromUser || undefined === stateFromUser || isObject(stateFromUser), 'history.pushState(state) argument state must be an object');
81
- const state = {
82
- scrollPosition: getScrollPosition(),
83
- timestamp: getTimestamp(),
84
- ...stateFromUser,
85
- // Don't allow user to overwrite triggeredBy as it would break Vike's handling of the 'popstate' event
86
- triggeredBy: 'user'
87
- };
88
- return pushStateOriginal(state, ...rest);
80
+ const pushStateOriginal = window.history.pushState;
81
+ window.history.pushState = (stateOriginal = {}, ...rest) => {
82
+ assertUsage(stateOriginal === undefined || stateOriginal === null || isObject(stateOriginal), 'history.pushState(state) argument state must be an object');
83
+ const stateEnhanced = isVikeEnhanced(stateOriginal)
84
+ ? stateOriginal
85
+ : {
86
+ _isVikeEnhanced: true,
87
+ scrollPosition: getScrollPosition(),
88
+ timestamp: getTimestamp(),
89
+ triggeredBy: 'user',
90
+ ...stateOriginal
91
+ };
92
+ return pushStateOriginal(stateEnhanced, ...rest);
89
93
  };
90
94
  }
91
- function pushStateOriginal(...args) {
92
- globalObject.pushStateOriginal.apply(history, args);
95
+ function isVikeEnhanced(state) {
96
+ return isObject(state) && '_isVikeEnhanced' in state;
93
97
  }
@@ -1,7 +1,7 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- declare const PROJECT_VERSION: "0.4.167-commit-c08a6bb";
3
+ declare const PROJECT_VERSION: "0.4.167-commit-aa83fde";
4
4
  declare const projectInfo: {
5
5
  projectName: "Vike";
6
- projectVersion: "0.4.167-commit-c08a6bb";
6
+ projectVersion: "0.4.167-commit-aa83fde";
7
7
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  export { PROJECT_VERSION };
3
- const PROJECT_VERSION = '0.4.167-commit-c08a6bb';
3
+ const PROJECT_VERSION = '0.4.167-commit-aa83fde';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.167-commit-c08a6bb",
3
+ "version": "0.4.167-commit-aa83fde",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",