vike 0.4.245-commit-4d0629e → 0.4.245-commit-6880dc7
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.
- package/dist/esm/client/runtime-client-routing/history.d.ts +5 -1
- package/dist/esm/client/runtime-client-routing/history.js +25 -3
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +0 -1
- package/dist/esm/client/runtime-client-routing/initOnLinkClick.js +0 -1
- package/dist/esm/client/runtime-client-routing/initOnPopState.js +6 -12
- package/dist/esm/client/runtime-client-routing/navigate.js +0 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +1 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +4 -17
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/package.json +2 -2
|
@@ -23,8 +23,12 @@ type HistoryInfo = {
|
|
|
23
23
|
state: StateEnhanced;
|
|
24
24
|
};
|
|
25
25
|
declare function onPopStateBegin(): {
|
|
26
|
-
|
|
26
|
+
skip: true;
|
|
27
|
+
previous?: undefined;
|
|
28
|
+
current?: undefined;
|
|
29
|
+
} | {
|
|
27
30
|
previous: HistoryInfo;
|
|
28
31
|
current: HistoryInfo;
|
|
32
|
+
skip?: undefined;
|
|
29
33
|
};
|
|
30
34
|
declare function initHistory(): void;
|
|
@@ -4,7 +4,7 @@ export { onPopStateBegin };
|
|
|
4
4
|
export { saveScrollPosition };
|
|
5
5
|
export { initHistory };
|
|
6
6
|
import { getCurrentUrl } from '../shared/getCurrentUrl.js';
|
|
7
|
-
import { assert, assertUsage, getGlobalObject, isObject, deepEqual, cast } from './utils.js';
|
|
7
|
+
import { assert, assertUsage, getGlobalObject, isObject, deepEqual, cast, redirectHard } from './utils.js';
|
|
8
8
|
const globalObject = getGlobalObject('history.ts', {
|
|
9
9
|
monkeyPatched: false,
|
|
10
10
|
previous: undefined,
|
|
@@ -66,6 +66,10 @@ function getTimestamp() {
|
|
|
66
66
|
}
|
|
67
67
|
function saveScrollPosition() {
|
|
68
68
|
const scrollPosition = getScrollPosition();
|
|
69
|
+
// Don't overwrite history.state if it was set by a non-Vike history.pushState() call.
|
|
70
|
+
// https://github.com/vikejs/vike/issues/2801#issuecomment-3490431479
|
|
71
|
+
if (!isVikeEnhanced(window.history.state))
|
|
72
|
+
return;
|
|
69
73
|
const state = getState();
|
|
70
74
|
replaceHistoryState({ ...state, scrollPosition });
|
|
71
75
|
}
|
|
@@ -160,13 +164,31 @@ function getHistoryInfo() {
|
|
|
160
164
|
}
|
|
161
165
|
function onPopStateBegin() {
|
|
162
166
|
const { previous } = globalObject;
|
|
163
|
-
const isHistoryStateEnhanced = window.history.state
|
|
167
|
+
const isHistoryStateEnhanced = isVikeEnhanced(window.history.state);
|
|
168
|
+
// Either:
|
|
169
|
+
// - `window.history.pushState(null, '', '/some-path')` , or
|
|
170
|
+
// - hash navigation
|
|
171
|
+
// - Click on `<a href="#some-hash">`
|
|
172
|
+
// - Using the `location` API (only hash navigation)
|
|
173
|
+
// See comments a the top of the ./initOnPopState.ts file.
|
|
174
|
+
const isHistoryStatePristine = window.history.state === null;
|
|
175
|
+
if (!isHistoryStateEnhanced && !isHistoryStatePristine) {
|
|
176
|
+
// Going to a history entry not created by Vike — entering another "SPA realm" => hard reload
|
|
177
|
+
// https://github.com/vikejs/vike/issues/2801#issuecomment-3490431479
|
|
178
|
+
redirectHard(getCurrentUrl());
|
|
179
|
+
return { skip: true };
|
|
180
|
+
}
|
|
164
181
|
if (!isHistoryStateEnhanced)
|
|
165
182
|
enhanceHistoryState();
|
|
166
183
|
assertIsVikeEnhanced(window.history.state);
|
|
167
184
|
const current = getHistoryInfo();
|
|
168
185
|
globalObject.previous = current;
|
|
169
|
-
|
|
186
|
+
// Let the browser handle hash navigations.
|
|
187
|
+
// - Upon hash navigation: `isHistoryStatePristine===true` (see comment above).
|
|
188
|
+
if (isHistoryStatePristine) {
|
|
189
|
+
return { skip: true };
|
|
190
|
+
}
|
|
191
|
+
return { previous, current };
|
|
170
192
|
}
|
|
171
193
|
function initHistory() {
|
|
172
194
|
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)
|
|
@@ -23,24 +23,18 @@ import { catchInfiniteLoop } from './utils.js';
|
|
|
23
23
|
// - It isn't possible to monkey patch the `location` APIs. (Chrome throws `TypeError: Cannot redefine property` when attempt to overwrite any `location` property.)
|
|
24
24
|
// - Text links aren't supported: https://github.com/vikejs/vike/issues/2114
|
|
25
25
|
// - docs/ is a good playground to test all this.
|
|
26
|
+
// - No 'popstate' event is fired upon Server Routing — when the user clicks on a link before the page's JavaScript loaded.
|
|
27
|
+
// - On a pristine page without JavaScript such as https://brillout.com we have `window.history.state === null`.
|
|
26
28
|
function initOnPopState() {
|
|
27
29
|
window.addEventListener('popstate', onPopState);
|
|
28
30
|
}
|
|
29
31
|
async function onPopState() {
|
|
30
32
|
catchInfiniteLoop('onPopState()');
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
// - Click on `<a href="#some-hash">`
|
|
34
|
-
// - Using the `location` API (only hash navigation, see comments above).
|
|
35
|
-
// - `isHistoryStateEnhanced===true` <=> back-/forward navigation (including back-/forward hash navigation).
|
|
36
|
-
// > Only back-/forward client-side navigation: no 'popstate' event is fired upon Server Routing (when the user clicks on a link before the page's JavaScript loaded), see comments above.
|
|
37
|
-
if (!isHistoryStateEnhanced) {
|
|
38
|
-
// Let the browser handle it
|
|
33
|
+
const res = onPopStateBegin();
|
|
34
|
+
if (res.skip)
|
|
39
35
|
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await handleHistoryNavigation(previous, current);
|
|
43
|
-
}
|
|
36
|
+
const { previous, current } = res;
|
|
37
|
+
await handleHistoryNavigation(previous, current);
|
|
44
38
|
}
|
|
45
39
|
async function handleHistoryNavigation(previous, current) {
|
|
46
40
|
const scrollTarget = current.state.scrollPosition || undefined;
|
|
@@ -19,7 +19,7 @@ type PageContextRouted = {
|
|
|
19
19
|
type PageContextBegin = Awaited<ReturnType<typeof getPageContextBegin>>;
|
|
20
20
|
type RenderArgs = {
|
|
21
21
|
scrollTarget: ScrollTarget;
|
|
22
|
-
isBackwardNavigation
|
|
22
|
+
isBackwardNavigation?: boolean | null;
|
|
23
23
|
isHistoryNavigation?: true;
|
|
24
24
|
urlOriginal?: string;
|
|
25
25
|
overwriteLastHistoryEntry?: boolean;
|
|
@@ -36,7 +36,7 @@ const globalObject = getGlobalObject('runtime-client-routing/renderPageClientSid
|
|
|
36
36
|
const { firstRenderStartPromise } = globalObject;
|
|
37
37
|
async function renderPageClientSide(renderArgs) {
|
|
38
38
|
catchInfiniteLoop('renderPageClientSide()');
|
|
39
|
-
const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, isHistoryNavigation = false, pageContextsFromRewrite = [], redirectCount = 0, doNotRenderIfSamePage, isClientSideNavigation = true, pageContextInitClient, } = renderArgs;
|
|
39
|
+
const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation = false, isHistoryNavigation = false, pageContextsFromRewrite = [], redirectCount = 0, doNotRenderIfSamePage, isClientSideNavigation = true, pageContextInitClient, } = renderArgs;
|
|
40
40
|
let { scrollTarget } = renderArgs;
|
|
41
41
|
const { previousPageContext } = globalObject;
|
|
42
42
|
addLinkPrefetchHandlers_unwatch();
|
|
@@ -370,7 +370,6 @@ async function renderPageClientSide(renderArgs) {
|
|
|
370
370
|
scrollTarget: undefined,
|
|
371
371
|
urlOriginal: urlRedirect,
|
|
372
372
|
overwriteLastHistoryEntry: false,
|
|
373
|
-
isBackwardNavigation: false,
|
|
374
373
|
redirectCount: redirectCount + 1,
|
|
375
374
|
});
|
|
376
375
|
}
|
|
@@ -664,7 +663,6 @@ if (import.meta.env.DEV && import.meta.hot)
|
|
|
664
663
|
scrollTarget: { preserveScroll: false },
|
|
665
664
|
urlOriginal: getCurrentUrl(),
|
|
666
665
|
overwriteLastHistoryEntry: true,
|
|
667
|
-
isBackwardNavigation: false,
|
|
668
666
|
});
|
|
669
667
|
}
|
|
670
668
|
});
|
|
@@ -263,8 +263,7 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
263
263
|
return;
|
|
264
264
|
pageConfigGlobal.configValueSources[configName] = sources;
|
|
265
265
|
});
|
|
266
|
-
|
|
267
|
-
applyEffectsConfVal(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal, plusFilesAll);
|
|
266
|
+
applyEffects(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal, plusFilesAll);
|
|
268
267
|
sortConfigValueSources(pageConfigGlobal.configValueSources, null);
|
|
269
268
|
assertPageConfigGlobal(pageConfigGlobal, plusFilesAll);
|
|
270
269
|
const pageConfigs = objectEntries(configDefinitionsResolved.configDefinitionsLocal)
|
|
@@ -281,8 +280,7 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
281
280
|
configValueSources[configName] = sources;
|
|
282
281
|
});
|
|
283
282
|
const pageConfigRoute = determineRouteFilesystem(locationId, configValueSources);
|
|
284
|
-
|
|
285
|
-
applyEffectsConfVal(configValueSources, configDefinitionsLocal, plusFilesAll);
|
|
283
|
+
applyEffects(configValueSources, configDefinitionsLocal, plusFilesAll);
|
|
286
284
|
sortConfigValueSources(configValueSources, locationId);
|
|
287
285
|
const pageConfig = {
|
|
288
286
|
pageId: locationId,
|
|
@@ -802,7 +800,7 @@ function assertMetaUsage(metaVal, metaConfigDefinedAt) {
|
|
|
802
800
|
});
|
|
803
801
|
}
|
|
804
802
|
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/vite.config.ts#L39
|
|
805
|
-
function
|
|
803
|
+
function applyEffects(configValueSources, configDefinitions, plusFilesAll) {
|
|
806
804
|
objectEntries(configDefinitions).forEach(([configNameEffect, configDefEffect]) => {
|
|
807
805
|
const sourceEffect = configValueSources[configNameEffect]?.[0];
|
|
808
806
|
if (!sourceEffect)
|
|
@@ -811,19 +809,8 @@ function applyEffectsConfVal(configValueSources, configDefinitions, plusFilesAll
|
|
|
811
809
|
if (!effect)
|
|
812
810
|
return;
|
|
813
811
|
const configModFromEffect = effect;
|
|
812
|
+
// Apply config value changes first to create sources, then meta.env changes to modify their env
|
|
814
813
|
applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions, plusFilesAll);
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/pages/config-meta/effect/e2e-test.ts#L16
|
|
818
|
-
function applyEffectsMetaEnv(configValueSources, configDefinitions) {
|
|
819
|
-
objectEntries(configDefinitions).forEach(([configNameEffect, configDefEffect]) => {
|
|
820
|
-
const sourceEffect = configValueSources[configNameEffect]?.[0];
|
|
821
|
-
if (!sourceEffect)
|
|
822
|
-
return;
|
|
823
|
-
const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
|
|
824
|
-
if (!effect)
|
|
825
|
-
return;
|
|
826
|
-
const configModFromEffect = effect;
|
|
827
814
|
applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEffect);
|
|
828
815
|
});
|
|
829
816
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.245-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.245-commit-6880dc7";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.245-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.245-commit-6880dc7';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.245-commit-
|
|
3
|
+
"version": "0.4.245-commit-6880dc7",
|
|
4
4
|
"repository": "https://github.com/vikejs/vike",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"dependencies": {
|
|
116
116
|
"@brillout/import": "^0.2.6",
|
|
117
117
|
"@brillout/json-serializer": "^0.5.21",
|
|
118
|
-
"@brillout/picocolors": "^1.0.
|
|
118
|
+
"@brillout/picocolors": "^1.0.29",
|
|
119
119
|
"@brillout/require-shim": "^0.1.2",
|
|
120
120
|
"@brillout/vite-plugin-server-entry": "^0.7.15",
|
|
121
121
|
"acorn": "^8.0.0",
|