vike 0.4.245 → 0.4.246-commit-194db5c
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/__internal/index.js +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +6 -0
- 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 +8 -14
- package/dist/esm/client/runtime-client-routing/navigate.js +0 -1
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +8 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +4 -4
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -0
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -0
- package/dist/esm/node/runtime/globalContext.js +2 -1
- package/dist/esm/node/runtime/renderPage/html/serializeContext.js +8 -0
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +2 -0
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +5 -18
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -2
- package/dist/esm/types/PageContext.d.ts +18 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSetup.d.ts +2 -2
- package/dist/esm/utils/assertSetup.js +16 -6
- package/package.json +3 -3
|
@@ -4,14 +4,14 @@ export { setGlobalContext_prodBuildEntry } from '../node/runtime/globalContext.j
|
|
|
4
4
|
export { route, getPagesAndRoutes };
|
|
5
5
|
import { route as routeInternal } from '../shared/route/index.js';
|
|
6
6
|
import { getGlobalContextServerInternal, initGlobalContext_getPagesAndRoutes } from '../node/runtime/globalContext.js';
|
|
7
|
-
import {
|
|
7
|
+
import { setNodeEnvProductionIfUndefined } from '../utils/assertSetup.js';
|
|
8
8
|
/**
|
|
9
9
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
10
10
|
*
|
|
11
11
|
* TO-DO/eventually: remove
|
|
12
12
|
*/
|
|
13
13
|
async function getPagesAndRoutes() {
|
|
14
|
-
|
|
14
|
+
setNodeEnvProductionIfUndefined();
|
|
15
15
|
await initGlobalContext_getPagesAndRoutes();
|
|
16
16
|
const { globalContext } = await getGlobalContextServerInternal();
|
|
17
17
|
const {
|
|
@@ -89,6 +89,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
89
89
|
url: string;
|
|
90
90
|
} & import("../../shared/page-configs/resolveVikeConfigPublic.js").GlobalConfigPublic & {
|
|
91
91
|
isBackwardNavigation: boolean | null;
|
|
92
|
+
isHistoryNavigation: boolean;
|
|
92
93
|
isClientSideNavigation: boolean;
|
|
93
94
|
isHydration: boolean;
|
|
94
95
|
previousPageContext: ({
|
|
@@ -144,6 +145,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
144
145
|
} & {
|
|
145
146
|
isHydration: boolean;
|
|
146
147
|
isBackwardNavigation: boolean | null;
|
|
148
|
+
isHistoryNavigation: boolean;
|
|
147
149
|
previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
|
|
148
150
|
globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
|
|
149
151
|
} & {
|
|
@@ -209,6 +211,7 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
209
211
|
} & {
|
|
210
212
|
isHydration: boolean;
|
|
211
213
|
isBackwardNavigation: boolean | null;
|
|
214
|
+
isHistoryNavigation: boolean;
|
|
212
215
|
previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
|
|
213
216
|
globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
|
|
214
217
|
} & {
|
|
@@ -310,6 +313,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
310
313
|
url: string;
|
|
311
314
|
} & import("../../shared/page-configs/resolveVikeConfigPublic.js").GlobalConfigPublic & {
|
|
312
315
|
isBackwardNavigation: boolean | null;
|
|
316
|
+
isHistoryNavigation: boolean;
|
|
313
317
|
isClientSideNavigation: boolean;
|
|
314
318
|
isHydration: boolean;
|
|
315
319
|
previousPageContext: ({
|
|
@@ -365,6 +369,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
365
369
|
} & {
|
|
366
370
|
isHydration: boolean;
|
|
367
371
|
isBackwardNavigation: boolean | null;
|
|
372
|
+
isHistoryNavigation: boolean;
|
|
368
373
|
previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
|
|
369
374
|
globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
|
|
370
375
|
} & {
|
|
@@ -428,6 +433,7 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
428
433
|
} & {
|
|
429
434
|
isHydration: boolean;
|
|
430
435
|
isBackwardNavigation: boolean | null;
|
|
436
|
+
isHistoryNavigation: boolean;
|
|
431
437
|
previousPageContext: import("../../types/PageContext.js").PageContextClient<unknown> | null;
|
|
432
438
|
globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
|
|
433
439
|
} & {
|
|
@@ -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,26 +23,20 @@ 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 handleBackForwardNavigation(previous, current);
|
|
43
|
-
}
|
|
36
|
+
const { previous, current } = res;
|
|
37
|
+
await handleHistoryNavigation(previous, current);
|
|
44
38
|
}
|
|
45
|
-
async function
|
|
39
|
+
async function handleHistoryNavigation(previous, current) {
|
|
46
40
|
const scrollTarget = current.state.scrollPosition || undefined;
|
|
47
41
|
const isHashNavigation = removeHash(current.url) === removeHash(previous.url) && current.url !== previous.url;
|
|
48
42
|
if (isHashNavigation) {
|
|
@@ -53,7 +47,7 @@ async function handleBackForwardNavigation(previous, current) {
|
|
|
53
47
|
const isUserPushStateNavigation = current.state.triggeredBy === 'user' || previous.state.triggeredBy === 'user';
|
|
54
48
|
const doNotRenderIfSamePage = isUserPushStateNavigation;
|
|
55
49
|
const isBackwardNavigation = !current.state.timestamp || !previous.state.timestamp ? null : current.state.timestamp < previous.state.timestamp;
|
|
56
|
-
await renderPageClientSide({ scrollTarget, isBackwardNavigation, doNotRenderIfSamePage });
|
|
50
|
+
await renderPageClientSide({ scrollTarget, isBackwardNavigation, doNotRenderIfSamePage, isHistoryNavigation: true });
|
|
57
51
|
}
|
|
58
52
|
function removeHash(url) {
|
|
59
53
|
return url.split('#')[0];
|
|
@@ -19,7 +19,8 @@ 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
|
+
isHistoryNavigation?: true;
|
|
23
24
|
urlOriginal?: string;
|
|
24
25
|
overwriteLastHistoryEntry?: boolean;
|
|
25
26
|
pageContextsFromRewrite?: PageContextFromRewrite[];
|
|
@@ -103,6 +104,7 @@ declare function renderPageClientSide(renderArgs: RenderArgs): Promise<({
|
|
|
103
104
|
url: string;
|
|
104
105
|
} & import("../../shared/page-configs/resolveVikeConfigPublic.js").GlobalConfigPublic & {
|
|
105
106
|
isBackwardNavigation: boolean | null;
|
|
107
|
+
isHistoryNavigation: boolean;
|
|
106
108
|
isClientSideNavigation: boolean;
|
|
107
109
|
isHydration: boolean;
|
|
108
110
|
previousPageContext: ({
|
|
@@ -155,6 +157,7 @@ declare function renderPageClientSide(renderArgs: RenderArgs): Promise<({
|
|
|
155
157
|
} & {
|
|
156
158
|
isHydration: boolean;
|
|
157
159
|
isBackwardNavigation: boolean | null;
|
|
160
|
+
isHistoryNavigation: boolean;
|
|
158
161
|
previousPageContext: PageContextClient<unknown> | null;
|
|
159
162
|
globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
|
|
160
163
|
} & {
|
|
@@ -174,9 +177,10 @@ declare function renderPageClientSide(renderArgs: RenderArgs): Promise<({
|
|
|
174
177
|
urlPathname: string;
|
|
175
178
|
_hasPageContextFromServer: boolean;
|
|
176
179
|
} & PageContextRouted) | undefined>;
|
|
177
|
-
declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isBackwardNavigation, pageContextsFromRewrite, isClientSideNavigation, pageContextInitClient, isFirstRender, }: {
|
|
180
|
+
declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isBackwardNavigation, isHistoryNavigation, pageContextsFromRewrite, isClientSideNavigation, pageContextInitClient, isFirstRender, }: {
|
|
178
181
|
urlOriginal: string;
|
|
179
182
|
isBackwardNavigation: boolean | null;
|
|
183
|
+
isHistoryNavigation: boolean;
|
|
180
184
|
pageContextsFromRewrite: PageContextFromRewrite[];
|
|
181
185
|
isClientSideNavigation: boolean;
|
|
182
186
|
pageContextInitClient: Record<string, unknown> | undefined;
|
|
@@ -250,6 +254,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
250
254
|
url: string;
|
|
251
255
|
} & import("../../shared/page-configs/resolveVikeConfigPublic.js").GlobalConfigPublic & {
|
|
252
256
|
isBackwardNavigation: boolean | null;
|
|
257
|
+
isHistoryNavigation: boolean;
|
|
253
258
|
isClientSideNavigation: boolean;
|
|
254
259
|
isHydration: boolean;
|
|
255
260
|
previousPageContext: ({
|
|
@@ -302,6 +307,7 @@ declare function getPageContextBegin(isForErrorPage: boolean, { urlOriginal, isB
|
|
|
302
307
|
} & {
|
|
303
308
|
isHydration: boolean;
|
|
304
309
|
isBackwardNavigation: boolean | null;
|
|
310
|
+
isHistoryNavigation: boolean;
|
|
305
311
|
previousPageContext: PageContextClient<unknown> | null;
|
|
306
312
|
globalContext: import("../../types/GlobalContext.js").GlobalContextClient;
|
|
307
313
|
} & {
|
|
@@ -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, 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();
|
|
@@ -45,6 +45,7 @@ async function renderPageClientSide(renderArgs) {
|
|
|
45
45
|
const pageContextBeginArgs = {
|
|
46
46
|
urlOriginal,
|
|
47
47
|
isBackwardNavigation,
|
|
48
|
+
isHistoryNavigation,
|
|
48
49
|
pageContextsFromRewrite,
|
|
49
50
|
isClientSideNavigation,
|
|
50
51
|
pageContextInitClient,
|
|
@@ -369,7 +370,6 @@ async function renderPageClientSide(renderArgs) {
|
|
|
369
370
|
scrollTarget: undefined,
|
|
370
371
|
urlOriginal: urlRedirect,
|
|
371
372
|
overwriteLastHistoryEntry: false,
|
|
372
|
-
isBackwardNavigation: false,
|
|
373
373
|
redirectCount: redirectCount + 1,
|
|
374
374
|
});
|
|
375
375
|
}
|
|
@@ -476,11 +476,12 @@ async function renderPageClientSide(renderArgs) {
|
|
|
476
476
|
return pageContext;
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
|
-
async function getPageContextBegin(isForErrorPage, { urlOriginal, isBackwardNavigation, pageContextsFromRewrite, isClientSideNavigation, pageContextInitClient, isFirstRender, }) {
|
|
479
|
+
async function getPageContextBegin(isForErrorPage, { urlOriginal, isBackwardNavigation, isHistoryNavigation, pageContextsFromRewrite, isClientSideNavigation, pageContextInitClient, isFirstRender, }) {
|
|
480
480
|
const previousPageContext = globalObject.previousPageContext ?? null;
|
|
481
481
|
const pageContext = await createPageContextClientSide(urlOriginal);
|
|
482
482
|
objectAssign(pageContext, {
|
|
483
483
|
isBackwardNavigation,
|
|
484
|
+
isHistoryNavigation,
|
|
484
485
|
isClientSideNavigation,
|
|
485
486
|
isHydration: isFirstRender && !isForErrorPage,
|
|
486
487
|
previousPageContext,
|
|
@@ -662,7 +663,6 @@ if (import.meta.env.DEV && import.meta.hot)
|
|
|
662
663
|
scrollTarget: { preserveScroll: false },
|
|
663
664
|
urlOriginal: getCurrentUrl(),
|
|
664
665
|
overwriteLastHistoryEntry: true,
|
|
665
|
-
isBackwardNavigation: false,
|
|
666
666
|
});
|
|
667
667
|
}
|
|
668
668
|
});
|
|
@@ -18,6 +18,7 @@ async function createPageContextClientSide() {
|
|
|
18
18
|
_globalContext: globalContext,
|
|
19
19
|
_pageFilesAll: globalContext._pageFilesAll, // TO-DO/next-major-release: remove
|
|
20
20
|
isBackwardNavigation: null,
|
|
21
|
+
isHistoryNavigation: null,
|
|
21
22
|
_hasPageContextFromServer: true,
|
|
22
23
|
});
|
|
23
24
|
objectAssign(pageContextCreated, getPageContextSerializedInHtml());
|
|
@@ -29,7 +29,7 @@ export { vikeConfigErrorRecoverMsg };
|
|
|
29
29
|
// - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
|
|
30
30
|
// - In development: globalObject.viteDevServer which is Vite's development server
|
|
31
31
|
// - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExportsGlobalEntry
|
|
32
|
-
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, isNonRunnableDev, objectAssign, } from './utils.js';
|
|
32
|
+
import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, isNonRunnableDev, objectAssign, setNodeEnvProductionIfUndefined, } from './utils.js';
|
|
33
33
|
import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
|
|
34
34
|
import { virtualFileIdGlobalEntryServer } from '../shared/virtualFileId.js';
|
|
35
35
|
import pc from '@brillout/picocolors';
|
|
@@ -270,6 +270,7 @@ async function setGlobalContext_prodBuildEntry(prodBuildEntry) {
|
|
|
270
270
|
debug('setGlobalContext_prodBuildEntry()');
|
|
271
271
|
assert(!isNonRunnableDev());
|
|
272
272
|
assertProdBuildEntry(prodBuildEntry);
|
|
273
|
+
setNodeEnvProductionIfUndefined();
|
|
273
274
|
globalObject.prodBuildEntry = prodBuildEntry;
|
|
274
275
|
globalObject.prodBuildEntryPrevious = prodBuildEntry;
|
|
275
276
|
assert(globalObject.prodBuildEntry); // ensure no infinite loop
|
|
@@ -10,6 +10,7 @@ import { NOT_SERIALIZABLE } from '../../../../shared/NOT_SERIALIZABLE.js';
|
|
|
10
10
|
import { pageContextInitIsPassedToClient } from '../../../../shared/misc/pageContextInitIsPassedToClient.js';
|
|
11
11
|
import { isServerSideError } from '../../../../shared/misc/isServerSideError.js';
|
|
12
12
|
import { getPropKeys, getPropVal, setPropVal } from './propKeys.js';
|
|
13
|
+
import { assertRouteParams } from '../../../../shared/route/resolveRouteFunction.js';
|
|
13
14
|
const passToClientBuiltInPageContext = [
|
|
14
15
|
'abortReason',
|
|
15
16
|
'_urlRewrite',
|
|
@@ -123,6 +124,7 @@ function serializeValue(value, isHtmlJsonScript, varName) {
|
|
|
123
124
|
});
|
|
124
125
|
}
|
|
125
126
|
function getPassToClientPageContext(pageContext) {
|
|
127
|
+
assertPageContext(pageContext);
|
|
126
128
|
let passToClient = [...pageContext._passToClient, ...passToClientBuiltInPageContext];
|
|
127
129
|
if (isErrorPage(pageContext.pageId, pageContext._globalContext._pageConfigs)) {
|
|
128
130
|
assert(hasProp(pageContext, 'is404', 'boolean'));
|
|
@@ -182,3 +184,9 @@ function applyPassToClient(passToClient, obj) {
|
|
|
182
184
|
});
|
|
183
185
|
return { objClient, objClientProps };
|
|
184
186
|
}
|
|
187
|
+
// Ensure the following client-side assert() don't fail:
|
|
188
|
+
// https://github.com/vikejs/vike/blob/a33b6e6319a9a0e34ea78e23c5aa156022e3745c/packages/vike/client/shared/getJsonSerializedInHtml.ts#L15-L16
|
|
189
|
+
function assertPageContext(pageContext) {
|
|
190
|
+
assertUsage(hasProp(pageContext, 'pageId', 'string'), `${pc.bold('pageContext.pageId')} should be a ${pc.bold('string')}`);
|
|
191
|
+
assertRouteParams(pageContext, `${pc.bold('pageContext.routeParams')} should`);
|
|
192
|
+
}
|
|
@@ -17,6 +17,8 @@ async function determineOptimizeDeps(config) {
|
|
|
17
17
|
// - The issue was closed as completed with https://github.com/vitejs/vite/pull/20495 but it doesn't fix the issue and the workaround is still needed.
|
|
18
18
|
// - TO-DO/eventually: try removing the workaround and see if the CI fails (at test/@cloudflare_vite-plugin/) — maybe the issue will get fixed at some point.
|
|
19
19
|
includeServer.push('react/jsx-dev-runtime');
|
|
20
|
+
includeClient.push('@compiled/react/runtime');
|
|
21
|
+
includeServer.push('@compiled/react/runtime');
|
|
20
22
|
for (const envName in config.environments) {
|
|
21
23
|
const env = config.environments[envName];
|
|
22
24
|
if (env.consumer === 'server' && env.optimizeDeps.noDiscovery === false) {
|
|
@@ -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,
|
|
@@ -801,8 +799,8 @@ function assertMetaUsage(metaVal, metaConfigDefinedAt) {
|
|
|
801
799
|
}
|
|
802
800
|
});
|
|
803
801
|
}
|
|
804
|
-
// Test: https://github.com/vikejs/vike/blob/
|
|
805
|
-
function
|
|
802
|
+
// Test: https://github.com/vikejs/vike/blob/871a111a77d637bbd156b07be5ae728c3d595501/test/playground/pages/config-meta/effect/e2e-test.ts
|
|
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
|
}
|
|
@@ -9,6 +9,6 @@ declare function resolveRouteFunction(routeFunction: (arg: unknown) => unknown,
|
|
|
9
9
|
}>;
|
|
10
10
|
declare function assertSyncRouting(res: unknown, errPrefix: string): void;
|
|
11
11
|
declare function warnDeprecatedAllowKey(): void;
|
|
12
|
-
declare function assertRouteParams<T>(result: T, errPrefix: string): asserts result is T & {
|
|
12
|
+
declare function assertRouteParams<T>(result: T, errPrefix: `${string} should`): asserts result is T & {
|
|
13
13
|
routeParams?: Record<string, string>;
|
|
14
14
|
};
|
|
@@ -63,6 +63,5 @@ function assertRouteParams(result, errPrefix) {
|
|
|
63
63
|
if (!hasProp(result, 'routeParams')) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
67
|
-
assertUsage(hasProp(result, 'routeParams', 'string{}'), `${errPrefix} be an object holding string values.`);
|
|
66
|
+
assertUsage(hasProp(result, 'routeParams', 'string{}'), `${errPrefix} be ${pc.bold('Record<string, string>')}`);
|
|
68
67
|
}
|
|
@@ -170,19 +170,28 @@ type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageConte
|
|
|
170
170
|
cspNonce: string | null;
|
|
171
171
|
isHydration?: undefined;
|
|
172
172
|
isBackwardNavigation?: undefined;
|
|
173
|
+
isHistoryNavigation?: undefined;
|
|
173
174
|
previousPageContext?: undefined;
|
|
174
175
|
};
|
|
175
176
|
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'routeParams' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'pageId' | 'source' | 'sources' | 'from'> & PageContextClientCommon & {
|
|
176
177
|
/** Whether the current page is already rendered to HTML */
|
|
177
178
|
isHydration: boolean;
|
|
178
179
|
/**
|
|
179
|
-
* Whether the user is navigating
|
|
180
|
+
* Whether the user is navigating backward in history.
|
|
180
181
|
*
|
|
181
182
|
* The value is `true` when the user clicks on his browser's backward navigation button, or when invoking `history.back()`.
|
|
182
183
|
*
|
|
183
184
|
* https://vike.dev/pageContext#isBackwardNavigation
|
|
184
185
|
*/
|
|
185
186
|
isBackwardNavigation: boolean | null;
|
|
187
|
+
/**
|
|
188
|
+
* Whether the user is navigating back or forward in history.
|
|
189
|
+
*
|
|
190
|
+
* The value is `true` when the user clicks on his browser's backward/forward button, or when invoking `history.back()` or `history.forward()`.
|
|
191
|
+
*
|
|
192
|
+
* https://vike.dev/pageContext#isHistoryNavigation
|
|
193
|
+
*/
|
|
194
|
+
isHistoryNavigation: boolean;
|
|
186
195
|
/**
|
|
187
196
|
* Upon client-side page navigation, you can use `pageContext.previousPageContext` to access the `pageContext` of the previous page.
|
|
188
197
|
*
|
|
@@ -208,6 +217,14 @@ type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltI
|
|
|
208
217
|
* https://vike.dev/pageContext#isBackwardNavigation
|
|
209
218
|
*/
|
|
210
219
|
isBackwardNavigation: null;
|
|
220
|
+
/**
|
|
221
|
+
* Whether the user is navigating back or forward in history.
|
|
222
|
+
*
|
|
223
|
+
* The `isHistoryNavigation` property only works with Client Routing. (The value is always `null` when using Server Routing.)
|
|
224
|
+
*
|
|
225
|
+
* https://vike.dev/pageContext#isHistoryNavigation
|
|
226
|
+
*/
|
|
227
|
+
isHistoryNavigation: null;
|
|
211
228
|
globalContext: GlobalContextClientWithServerRouting;
|
|
212
229
|
};
|
|
213
230
|
type PageContextClientCommon = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.246-commit-194db5c";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.246-commit-194db5c';
|
|
@@ -3,7 +3,7 @@ export { onSetupRuntime };
|
|
|
3
3
|
export { onSetupBuild };
|
|
4
4
|
export { onSetupPrerender };
|
|
5
5
|
export { onSetupPreview };
|
|
6
|
-
export {
|
|
6
|
+
export { setNodeEnvProductionIfUndefined };
|
|
7
7
|
export { markSetup_viteDevServer };
|
|
8
8
|
export { markSetup_vitePreviewServer };
|
|
9
9
|
export { markSetup_vikeVitePlugin };
|
|
@@ -17,4 +17,4 @@ declare function markSetup_viteDevServer(): void | undefined;
|
|
|
17
17
|
declare function markSetup_vitePreviewServer(): void | undefined;
|
|
18
18
|
declare function markSetup_vikeVitePlugin(): void;
|
|
19
19
|
declare function markSetup_isViteDev(isViteDev: boolean): void;
|
|
20
|
-
declare function
|
|
20
|
+
declare function setNodeEnvProductionIfUndefined(): void | undefined;
|
|
@@ -3,7 +3,7 @@ export { onSetupRuntime };
|
|
|
3
3
|
export { onSetupBuild };
|
|
4
4
|
export { onSetupPrerender };
|
|
5
5
|
export { onSetupPreview };
|
|
6
|
-
export {
|
|
6
|
+
export { setNodeEnvProductionIfUndefined };
|
|
7
7
|
export { markSetup_viteDevServer };
|
|
8
8
|
export { markSetup_vitePreviewServer };
|
|
9
9
|
export { markSetup_vikeVitePlugin };
|
|
@@ -55,7 +55,7 @@ function onSetupRuntime() {
|
|
|
55
55
|
function onSetupBuild() {
|
|
56
56
|
assertUsageNodeEnvIsNotDev('building');
|
|
57
57
|
/* Not needed: Vite already sets `process.env.NODE_ENV = 'production'`
|
|
58
|
-
|
|
58
|
+
setNodeEnvProductionIfUndefined()
|
|
59
59
|
*/
|
|
60
60
|
}
|
|
61
61
|
// Called by ../node/prerender/runPrerender.ts
|
|
@@ -63,7 +63,7 @@ function onSetupPrerender() {
|
|
|
63
63
|
markSetup_isPrerendering();
|
|
64
64
|
if (getNodeEnv())
|
|
65
65
|
assertUsageNodeEnvIsNotDev('pre-rendering');
|
|
66
|
-
|
|
66
|
+
setNodeEnvProductionIfUndefined();
|
|
67
67
|
}
|
|
68
68
|
// Called by ../node/api/preview.ts
|
|
69
69
|
function onSetupPreview() {
|
|
@@ -157,10 +157,20 @@ function getNodeEnv() {
|
|
|
157
157
|
//*/
|
|
158
158
|
return val;
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function setNodeEnvProductionIfUndefined() {
|
|
161
161
|
// The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
|
|
162
|
-
|
|
162
|
+
let val;
|
|
163
|
+
let proc;
|
|
164
|
+
try {
|
|
165
|
+
proc = process;
|
|
166
|
+
val = process.env.NODE_ENV;
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (val !== undefined)
|
|
172
|
+
return;
|
|
163
173
|
const { env } = proc;
|
|
164
|
-
env.NODE_ENV = 'production';
|
|
174
|
+
env.NODE_ENV ?? (env.NODE_ENV = 'production');
|
|
165
175
|
assert(isNodeEnv('production'));
|
|
166
176
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.246-commit-194db5c",
|
|
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",
|
|
@@ -245,7 +245,7 @@
|
|
|
245
245
|
"@types/picomatch": "^3.0.2",
|
|
246
246
|
"@types/semver": "^7.5.8",
|
|
247
247
|
"@types/source-map-support": "^0.5.10",
|
|
248
|
-
"react-streaming": "^0.4.
|
|
248
|
+
"react-streaming": "^0.4.12",
|
|
249
249
|
"rimraf": "^5.0.5",
|
|
250
250
|
"typescript": "^5.9.2",
|
|
251
251
|
"vite": "^7.1.5"
|