vike 0.4.235-commit-7b1ab35 → 0.4.235-commit-8f42b16

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.
@@ -150,6 +150,8 @@ function getTagClosing(tag) {
150
150
  return tagClosing;
151
151
  }
152
152
  function injectAtPlaceholder(htmlFragment, htmlString, isFirst) {
153
+ // TO-DO/eventually: soft deprecate in favor of https://github.com/vikejs/vike/issues/695
154
+ // Used by BurdaForward https://github.com/vikejs/vike/discussions/2528#discussioncomment-13637156
153
155
  const placeholder = isFirst ? '__VITE_PLUGIN_SSR__ASSETS_FIRST__' : '__VITE_PLUGIN__SSR_ASSETS_LAST__';
154
156
  const parts = htmlString.split(placeholder);
155
157
  if (parts.length === 1)
@@ -108,7 +108,20 @@ function serializeObject(obj, objName, passToClient) {
108
108
  return serialized;
109
109
  }
110
110
  function serializeValue(value, varName) {
111
- return (0, stringify_1.stringify)(value, { forbidReactElements: true, valueName: varName });
111
+ return (0, stringify_1.stringify)(value, {
112
+ forbidReactElements: true,
113
+ valueName: varName,
114
+ // Prevent Google from crawling URLs in JSON:
115
+ // - https://github.com/vikejs/vike/discussions/2541#discussioncomment-13660198
116
+ // - https://github.com/vikejs/vike/discussions/2277
117
+ // - https://github.com/vikejs/vike/pull/2542
118
+ replacer(_key, value) {
119
+ if (typeof value === 'string' && value.startsWith('/')) {
120
+ // No need to use a reviver: https://github.com/brillout/json-serializer/blob/70fc8ed3741306391b51655b05df24e6963d1fdb/test/main.spec.ts#L74-L80
121
+ return { replacement: (value = '!' + value) };
122
+ }
123
+ },
124
+ });
112
125
  }
113
126
  function getPassToClientPageContext(pageContext) {
114
127
  let passToClient = [...pageContext._passToClient, ...passToClientBuiltInPageContext];
@@ -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-7b1ab35';
5
+ exports.PROJECT_VERSION = '0.4.235-commit-8f42b16';
@@ -2,7 +2,8 @@ export { pushHistoryState };
2
2
  export { replaceHistoryStateOriginal };
3
3
  export { onPopStateBegin };
4
4
  export { saveScrollPosition };
5
- export { initHistory };
5
+ export { initHistoryState };
6
+ export { monkeyPatchHistoryAPI };
6
7
  export type { HistoryInfo };
7
8
  export type { ScrollPosition };
8
9
  type StateEnhanced = {
@@ -18,6 +19,7 @@ type ScrollPosition = {
18
19
  declare function saveScrollPosition(): void;
19
20
  declare function pushHistoryState(url: string, overwriteLastHistoryEntry: boolean): void;
20
21
  declare function replaceHistoryStateOriginal(state: unknown, url: string): void;
22
+ declare function monkeyPatchHistoryAPI(): void;
21
23
  type HistoryInfo = {
22
24
  url: `/${string}`;
23
25
  state: StateEnhanced;
@@ -27,4 +29,4 @@ declare function onPopStateBegin(): {
27
29
  previous: HistoryInfo;
28
30
  current: HistoryInfo;
29
31
  };
30
- declare function initHistory(): void;
32
+ declare function initHistoryState(): void;
@@ -2,15 +2,12 @@ export { pushHistoryState };
2
2
  export { replaceHistoryStateOriginal };
3
3
  export { onPopStateBegin };
4
4
  export { saveScrollPosition };
5
- export { initHistory };
5
+ export { initHistoryState };
6
+ export { monkeyPatchHistoryAPI };
6
7
  import { getCurrentUrl } from '../shared/getCurrentUrl.js';
7
8
  import { assert, assertUsage, getGlobalObject, isObject } 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();
9
+ initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
10
+ const globalObject = getGlobalObject('runtime-client-routing/history.ts', { previous: getHistoryInfo() });
14
11
  // `window.history.state === null` when:
15
12
  // - The very first render
16
13
  // - Click on `<a href="#some-hash" />`
@@ -44,7 +41,7 @@ function enhance(stateNotEnhanced) {
44
41
  _isVikeEnhanced: true,
45
42
  };
46
43
  }
47
- assertIsVikeEnhanced(stateVikeEnhanced);
44
+ assert(isVikeEnhanced(stateVikeEnhanced));
48
45
  return stateVikeEnhanced;
49
46
  }
50
47
  function getState() {
@@ -54,7 +51,7 @@ function getState() {
54
51
  // - Therefore, we have to monkey patch history.pushState() and history.replaceState()
55
52
  // - Therefore, we need the assert() below to ensure history.state has been enhanced by Vike
56
53
  // - If users stumble upon this assert() then let's make it a assertUsage()
57
- assertIsVikeEnhanced(state);
54
+ assert(isVikeEnhanced(state), { state });
58
55
  return state;
59
56
  }
60
57
  function getStateNotEnhanced() {
@@ -93,7 +90,6 @@ function pushHistoryState(url, overwriteLastHistoryEntry) {
93
90
  function replaceHistoryState(state, url) {
94
91
  const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
95
92
  window.history.replaceState(state, '', url_);
96
- assertIsVikeEnhanced(getState());
97
93
  }
98
94
  function replaceHistoryStateOriginal(state, url) {
99
95
  // Bypass all monkey patches.
@@ -104,11 +100,7 @@ function replaceHistoryStateOriginal(state, url) {
104
100
  // - history.pushState()
105
101
  // - history.replaceState()
106
102
  function monkeyPatchHistoryAPI() {
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);
103
+ ;
112
104
  ['pushState', 'replaceState'].forEach((funcName) => {
113
105
  const funcOriginal = window.history[funcName].bind(window.history);
114
106
  window.history[funcName] = (stateOriginal = {}, ...rest) => {
@@ -122,14 +114,11 @@ function monkeyPatchHistoryAPI() {
122
114
  triggeredBy: 'user',
123
115
  ...stateOriginal,
124
116
  };
125
- assertIsVikeEnhanced(stateEnhanced);
126
- funcOriginal(stateEnhanced, ...rest);
127
- assertIsVikeEnhanced(getState());
117
+ assert(isVikeEnhanced(stateEnhanced));
118
+ const ret = funcOriginal(stateEnhanced, ...rest);
128
119
  globalObject.previous = getHistoryInfo();
120
+ return ret;
129
121
  };
130
- window.history[funcName]._isVikeMonkeyPatch = true;
131
- // Ensure assert() above isn't a false positive
132
- assert(window.history.pushState !== History.prototype.pushState);
133
122
  });
134
123
  }
135
124
  function isVikeEnhanced(state) {
@@ -147,16 +136,6 @@ function isVikeEnhanced(state) {
147
136
  }
148
137
  return false;
149
138
  }
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
- }
160
139
  function getHistoryInfo() {
161
140
  return {
162
141
  url: getCurrentUrl(),
@@ -168,12 +147,11 @@ function onPopStateBegin() {
168
147
  const isHistoryStateEnhanced = window.history.state !== null;
169
148
  if (!isHistoryStateEnhanced)
170
149
  enhanceHistoryState();
171
- assertIsVikeEnhanced(window.history.state);
150
+ assert(isVikeEnhanced(window.history.state));
172
151
  const current = getHistoryInfo();
173
152
  globalObject.previous = current;
174
153
  return { isHistoryStateEnhanced, previous, current };
175
154
  }
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`
155
+ function initHistoryState() {
156
+ enhanceHistoryState();
179
157
  }
@@ -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 { initHistory } from './history.js';
9
+ import { initHistoryState, monkeyPatchHistoryAPI } from './history.js';
10
10
  async function initClientRouter() {
11
11
  // Init navigation history and scroll restoration
12
12
  initHistoryAndScroll();
@@ -29,7 +29,8 @@ async function renderFirstPage() {
29
29
  }
30
30
  function initHistoryAndScroll() {
31
31
  scrollRestoration_init();
32
- initHistory(); // we redundantly call initHistory() to ensure it's called early
32
+ monkeyPatchHistoryAPI();
33
+ initHistoryState(); // we redundantly call initHistoryState() to ensure it's called early
33
34
  autoSaveScrollPosition();
34
35
  // Handle back-/forward navigation
35
36
  initOnPopState();
@@ -149,6 +149,8 @@ function getTagClosing(tag) {
149
149
  return tagClosing;
150
150
  }
151
151
  function injectAtPlaceholder(htmlFragment, htmlString, isFirst) {
152
+ // TO-DO/eventually: soft deprecate in favor of https://github.com/vikejs/vike/issues/695
153
+ // Used by BurdaForward https://github.com/vikejs/vike/discussions/2528#discussioncomment-13637156
152
154
  const placeholder = isFirst ? '__VITE_PLUGIN_SSR__ASSETS_FIRST__' : '__VITE_PLUGIN__SSR_ASSETS_LAST__';
153
155
  const parts = htmlString.split(placeholder);
154
156
  if (parts.length === 1)
@@ -103,7 +103,20 @@ function serializeObject(obj, objName, passToClient) {
103
103
  return serialized;
104
104
  }
105
105
  function serializeValue(value, varName) {
106
- return stringify(value, { forbidReactElements: true, valueName: varName });
106
+ return stringify(value, {
107
+ forbidReactElements: true,
108
+ valueName: varName,
109
+ // Prevent Google from crawling URLs in JSON:
110
+ // - https://github.com/vikejs/vike/discussions/2541#discussioncomment-13660198
111
+ // - https://github.com/vikejs/vike/discussions/2277
112
+ // - https://github.com/vikejs/vike/pull/2542
113
+ replacer(_key, value) {
114
+ if (typeof value === 'string' && value.startsWith('/')) {
115
+ // No need to use a reviver: https://github.com/brillout/json-serializer/blob/70fc8ed3741306391b51655b05df24e6963d1fdb/test/main.spec.ts#L74-L80
116
+ return { replacement: (value = '!' + value) };
117
+ }
118
+ },
119
+ });
107
120
  }
108
121
  function getPassToClientPageContext(pageContext) {
109
122
  let passToClient = [...pageContext._passToClient, ...passToClientBuiltInPageContext];
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.235-commit-7b1ab35";
1
+ export declare const PROJECT_VERSION: "0.4.235-commit-8f42b16";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.235-commit-7b1ab35';
2
+ export const PROJECT_VERSION = '0.4.235-commit-8f42b16';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.235-commit-7b1ab35",
3
+ "version": "0.4.235-commit-8f42b16",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -120,7 +120,7 @@
120
120
  },
121
121
  "dependencies": {
122
122
  "@brillout/import": "^0.2.6",
123
- "@brillout/json-serializer": "^0.5.15",
123
+ "@brillout/json-serializer": "^0.5.16",
124
124
  "@brillout/picocolors": "^1.0.26",
125
125
  "@brillout/require-shim": "^0.1.2",
126
126
  "@brillout/vite-plugin-server-entry": "^0.7.8",