vike 0.4.199-commit-3be497f → 0.4.199-commit-33e1230
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/cjs/node/client/router.js +3 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +3 -5
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +9 -7
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -8
- package/dist/esm/node/client/router.d.ts +2 -0
- package/dist/esm/node/client/router.js +2 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/getCurrentUrl.d.ts +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prefetch = exports.reload = exports.navigate = void 0;
|
|
3
|
+
exports.onPopState = exports.prefetch = exports.reload = exports.navigate = void 0;
|
|
4
4
|
const assert_js_1 = require("../../utils/assert.js");
|
|
5
5
|
// `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
|
|
6
6
|
const navigate = (() => warnNoEffect('navigate'));
|
|
@@ -9,6 +9,8 @@ const reload = (() => warnNoEffect('reload'));
|
|
|
9
9
|
exports.reload = reload;
|
|
10
10
|
const prefetch = (() => warnNoEffect('prefetch'));
|
|
11
11
|
exports.prefetch = prefetch;
|
|
12
|
+
const onPopState = (() => { });
|
|
13
|
+
exports.onPopState = onPopState;
|
|
12
14
|
function warnNoEffect(caller) {
|
|
13
15
|
(0, assert_js_1.assertWarning)(false, `Calling ${caller}() on the server-side has no effect`, {
|
|
14
16
|
showStackTrace: true,
|
|
@@ -3,17 +3,15 @@ export { updateState };
|
|
|
3
3
|
export { onPopState };
|
|
4
4
|
declare function initOnPopState(): void;
|
|
5
5
|
type Listener = (arg: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
}) => undefined | boolean;
|
|
6
|
+
previousState: ReturnType<typeof getState>;
|
|
7
|
+
}) => void | boolean;
|
|
10
8
|
/** Control client-side navigation.
|
|
11
9
|
*
|
|
12
10
|
* https://vike.dev/onPopState
|
|
13
11
|
*/
|
|
14
12
|
declare function onPopState(listener: Listener): void;
|
|
15
13
|
declare function getState(): {
|
|
16
|
-
|
|
14
|
+
url: `/${string}`;
|
|
17
15
|
historyState: {
|
|
18
16
|
timestamp: number;
|
|
19
17
|
scrollPosition: null | import("./history.js").ScrollPosition;
|
|
@@ -21,8 +21,7 @@ function initOnPopState() {
|
|
|
21
21
|
const currentState = getState();
|
|
22
22
|
globalObject.previousState = currentState;
|
|
23
23
|
const scrollTarget = currentState.historyState?.scrollPosition || undefined;
|
|
24
|
-
const
|
|
25
|
-
const isHashNavigation = currentState.urlWithoutHash === previousState.urlWithoutHash;
|
|
24
|
+
const isHashNavigation = removeHash(currentState.url) === removeHash(previousState.url);
|
|
26
25
|
const isBackwardNavigation = !currentState.historyState?.timestamp || !previousState.historyState?.timestamp
|
|
27
26
|
? null
|
|
28
27
|
: currentState.historyState.timestamp < previousState.historyState.timestamp;
|
|
@@ -46,19 +45,19 @@ function initOnPopState() {
|
|
|
46
45
|
// - Alternative: we completely take over hash navigation and reproduce the browser's native behavior upon hash navigation.
|
|
47
46
|
// - By using the `hashchange` event.
|
|
48
47
|
// - Problem: conflict if user wants to override the browser's default behavior? E.g. for smooth scrolling, or when using hashes for saving states of some fancy animations.
|
|
49
|
-
if (isHashNavigation
|
|
48
|
+
if (isHashNavigation) {
|
|
50
49
|
if (!isHashNavigationNew) {
|
|
51
50
|
setScrollPosition(scrollTarget);
|
|
52
51
|
}
|
|
53
52
|
return;
|
|
54
53
|
}
|
|
55
54
|
let abort;
|
|
56
|
-
globalObject.listeners.forEach(listener => {
|
|
57
|
-
abort || (abort = listener({
|
|
55
|
+
globalObject.listeners.forEach((listener) => {
|
|
56
|
+
abort || (abort = listener({ previousState }));
|
|
58
57
|
});
|
|
59
58
|
if (abort)
|
|
60
59
|
return;
|
|
61
|
-
await renderPageClientSide({ scrollTarget, isBackwardNavigation
|
|
60
|
+
await renderPageClientSide({ scrollTarget, isBackwardNavigation });
|
|
62
61
|
});
|
|
63
62
|
}
|
|
64
63
|
/** Control client-side navigation.
|
|
@@ -70,10 +69,13 @@ function onPopState(listener) {
|
|
|
70
69
|
}
|
|
71
70
|
function getState() {
|
|
72
71
|
return {
|
|
73
|
-
|
|
72
|
+
url: getCurrentUrl(),
|
|
74
73
|
historyState: getHistoryState()
|
|
75
74
|
};
|
|
76
75
|
}
|
|
76
|
+
function removeHash(url) {
|
|
77
|
+
return url.split('#')[0];
|
|
78
|
+
}
|
|
77
79
|
function updateState() {
|
|
78
80
|
globalObject.previousState = getState();
|
|
79
81
|
}
|
|
@@ -12,8 +12,6 @@ type RenderArgs = {
|
|
|
12
12
|
overwriteLastHistoryEntry?: boolean;
|
|
13
13
|
pageContextsFromRewrite?: PageContextFromRewrite[];
|
|
14
14
|
redirectCount?: number;
|
|
15
|
-
/** Whether the navigation was triggered by the user land calling `history.pushState()` */
|
|
16
|
-
isUserLandPushStateNavigation?: boolean;
|
|
17
15
|
isClientSideNavigation?: boolean;
|
|
18
16
|
};
|
|
19
17
|
declare function renderPageClientSide(renderArgs: RenderArgs): Promise<void>;
|
|
@@ -30,7 +30,7 @@ const globalObject = getGlobalObject('renderPageClientSide.ts', (() => {
|
|
|
30
30
|
})());
|
|
31
31
|
const { firstRenderStartPromise } = globalObject;
|
|
32
32
|
async function renderPageClientSide(renderArgs) {
|
|
33
|
-
const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0,
|
|
33
|
+
const { urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, isClientSideNavigation = true } = renderArgs;
|
|
34
34
|
let { scrollTarget } = renderArgs;
|
|
35
35
|
const { previousPageContext } = globalObject;
|
|
36
36
|
addLinkPrefetchHandlers_unwatch();
|
|
@@ -117,13 +117,6 @@ async function renderPageClientSide(renderArgs) {
|
|
|
117
117
|
redirectHard(urlOriginal);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
-
const isSamePage = pageContextFromRoute.pageId &&
|
|
121
|
-
previousPageContext?.pageId &&
|
|
122
|
-
pageContextFromRoute.pageId === previousPageContext.pageId;
|
|
123
|
-
if (isUserLandPushStateNavigation && isSamePage) {
|
|
124
|
-
// Skip's Vike's rendering; let the user handle the navigation
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
120
|
// TODO/eventually: create helper assertPageContextFromHook()
|
|
128
121
|
assert(!('urlOriginal' in pageContextFromRoute));
|
|
129
122
|
objectAssign(pageContext, pageContextFromRoute);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export { navigate };
|
|
2
2
|
export { reload };
|
|
3
3
|
export { prefetch };
|
|
4
|
+
export { onPopState };
|
|
4
5
|
import { assertWarning } from '../../utils/assert.js';
|
|
5
6
|
// `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
|
|
6
7
|
const navigate = (() => warnNoEffect('navigate'));
|
|
7
8
|
const reload = (() => warnNoEffect('reload'));
|
|
8
9
|
const prefetch = (() => warnNoEffect('prefetch'));
|
|
10
|
+
const onPopState = (() => { });
|
|
9
11
|
function warnNoEffect(caller) {
|
|
10
12
|
assertWarning(false, `Calling ${caller}() on the server-side has no effect`, {
|
|
11
13
|
showStackTrace: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.199-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.199-commit-33e1230";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.199-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.199-commit-33e1230';
|