vike 0.4.236-commit-eab75f6 → 0.4.237
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/client/shared/createGetGlobalContextClient.js +2 -4
- package/dist/cjs/node/runtime/html/serializeContext.js +8 -47
- package/dist/cjs/node/runtime/html/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +19 -6
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/cjs/node/runtime/renderPage.js +7 -6
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +45 -43
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -2
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +2 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +7 -18
- package/dist/cjs/shared/createGlobalContextShared.js +13 -0
- package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +12 -13
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/cast.js +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
- package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
- package/dist/esm/client/runtime-client-routing/history.js +39 -22
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/utils.js +2 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.js +2 -4
- package/dist/esm/node/runtime/html/serializeContext.d.ts +8 -3
- package/dist/esm/node/runtime/html/serializeContext.js +8 -47
- package/dist/esm/node/runtime/html/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +20 -7
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +0 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +4 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/esm/node/runtime/renderPage.d.ts +1 -0
- package/dist/esm/node/runtime/renderPage.js +7 -6
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +46 -44
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +2 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +8 -19
- package/dist/esm/shared/createGlobalContextShared.js +14 -1
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
- package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +12 -13
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/Config.d.ts +33 -98
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/cast.d.ts +2 -2
- package/dist/esm/utils/cast.js +1 -1
- package/dist/esm/utils/objectFilter.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
|
@@ -3,9 +3,12 @@ export { getPageContextClientSerializedAbort };
|
|
|
3
3
|
export { getGlobalContextClientSerialized };
|
|
4
4
|
export type { PageContextSerialization };
|
|
5
5
|
export type { PassToClient };
|
|
6
|
+
export type { PassToClientPublic };
|
|
6
7
|
import type { UrlRedirect } from '../../../shared/route/abort.js';
|
|
7
8
|
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
8
|
-
type
|
|
9
|
+
import type { PageContextCreated } from '../renderPage/createPageContextServerSide.js';
|
|
10
|
+
import type { PageContextBegin } from '../renderPage.js';
|
|
11
|
+
type PageContextSerialization = PageContextCreated & {
|
|
9
12
|
pageId: string;
|
|
10
13
|
routeParams: Record<string, string>;
|
|
11
14
|
_passToClient: PassToClient;
|
|
@@ -13,12 +16,14 @@ type PageContextSerialization = {
|
|
|
13
16
|
pageProps?: Record<string, unknown>;
|
|
14
17
|
_pageContextInit: Record<string, unknown>;
|
|
15
18
|
_globalContext: GlobalContextServerInternal;
|
|
16
|
-
|
|
19
|
+
_isPageContextJsonRequest: null | PageContextBegin['_isPageContextJsonRequest'];
|
|
17
20
|
};
|
|
18
21
|
declare function getPageContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
19
22
|
declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
|
|
20
|
-
type PassToClient =
|
|
23
|
+
type PassToClient = string[];
|
|
24
|
+
type PassToClientPublic = (string | {
|
|
21
25
|
prop: string;
|
|
26
|
+
/** @deprecated The passToClient once setting is deprecated and no longer has any effect. Instead, see the upcoming .once.js suffix (see https://github.com/vikejs/vike/issues/2566 for more information). */
|
|
22
27
|
once?: boolean;
|
|
23
28
|
})[];
|
|
24
29
|
declare function getPageContextClientSerializedAbort(pageContext: Record<string, unknown> & ({
|
|
@@ -27,41 +27,24 @@ const passToClientBuiltInPageContext = [
|
|
|
27
27
|
const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError];
|
|
28
28
|
function getPageContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
29
29
|
const passToClientPageContext = getPassToClientPageContext(pageContext);
|
|
30
|
-
const
|
|
31
|
-
if (passToClientEntry.once)
|
|
32
|
-
return undefined; // pass it to client-side globalContext
|
|
33
|
-
return { obj: pageContext, objName: 'pageContext' };
|
|
34
|
-
};
|
|
35
|
-
const res = applyPassToClient(passToClientPageContext, getObj);
|
|
30
|
+
const res = applyPassToClient(passToClientPageContext, pageContext);
|
|
36
31
|
const pageContextClient = res.objClient;
|
|
37
32
|
const pageContextClientProps = res.objClientProps;
|
|
38
33
|
if (pageContextClientProps.some((prop) => getPropVal(pageContext._pageContextInit, prop))) {
|
|
39
34
|
pageContextClient[pageContextInitIsPassedToClient] = true;
|
|
40
35
|
}
|
|
41
|
-
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext,
|
|
36
|
+
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, 'pageContext', isHtmlJsonScript);
|
|
42
37
|
return pageContextClientSerialized;
|
|
43
38
|
}
|
|
44
39
|
function getGlobalContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
45
40
|
const passToClient = pageContext._passToClient;
|
|
46
41
|
const globalContext = pageContext._globalContext;
|
|
47
|
-
const
|
|
48
|
-
if (once && getPropVal(pageContext, prop)) {
|
|
49
|
-
assert(typeof pageContext.isClientSideNavigation === 'boolean');
|
|
50
|
-
if (!pageContext.isClientSideNavigation) {
|
|
51
|
-
return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
return undefined; // already passed to client-side
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return { obj: globalContext, objName: 'globalContext' };
|
|
58
|
-
};
|
|
59
|
-
const res = applyPassToClient(passToClient, getObj);
|
|
42
|
+
const res = applyPassToClient(passToClient, globalContext);
|
|
60
43
|
const globalContextClient = res.objClient;
|
|
61
|
-
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient,
|
|
44
|
+
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, 'globalContext', isHtmlJsonScript);
|
|
62
45
|
return globalContextClientSerialized;
|
|
63
46
|
}
|
|
64
|
-
function serializeObject(obj, passToClient,
|
|
47
|
+
function serializeObject(obj, passToClient, objName, isHtmlJsonScript) {
|
|
65
48
|
let serialized;
|
|
66
49
|
try {
|
|
67
50
|
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
@@ -70,15 +53,11 @@ function serializeObject(obj, passToClient, getObj, isHtmlJsonScript) {
|
|
|
70
53
|
const h = (s) => pc.cyan(s);
|
|
71
54
|
let hasWarned = false;
|
|
72
55
|
const propsNonSerializable = [];
|
|
73
|
-
passToClient.forEach((
|
|
74
|
-
const entryNormalized = normalizePassToClientEntry(entry);
|
|
75
|
-
const { prop } = entryNormalized;
|
|
56
|
+
passToClient.forEach((prop) => {
|
|
76
57
|
const res = getPropVal(obj, prop);
|
|
77
58
|
if (!res)
|
|
78
59
|
return;
|
|
79
60
|
const { value } = res;
|
|
80
|
-
const { objName } = getObj(entryNormalized) ?? {};
|
|
81
|
-
assert(objName);
|
|
82
61
|
const varName = `${objName}${getPropKeys(prop).map(getPropAccessNotation).join('')}`;
|
|
83
62
|
try {
|
|
84
63
|
serializeValue(value, isHtmlJsonScript, varName);
|
|
@@ -188,15 +167,10 @@ function getPageContextClientSerializedAbort(pageContext, isHtmlJsonScript) {
|
|
|
188
167
|
}
|
|
189
168
|
return serializeValue(pageContext, isHtmlJsonScript);
|
|
190
169
|
}
|
|
191
|
-
function applyPassToClient(passToClient,
|
|
170
|
+
function applyPassToClient(passToClient, obj) {
|
|
192
171
|
const objClient = {};
|
|
193
172
|
const objClientProps = [];
|
|
194
|
-
passToClient.forEach((
|
|
195
|
-
const entryNormalized = normalizePassToClientEntry(entry);
|
|
196
|
-
const { prop } = entryNormalized;
|
|
197
|
-
const { obj } = getObj(entryNormalized) ?? {};
|
|
198
|
-
if (!obj)
|
|
199
|
-
return;
|
|
173
|
+
passToClient.forEach((prop) => {
|
|
200
174
|
// Get value from pageContext
|
|
201
175
|
const res = getPropVal(obj, prop);
|
|
202
176
|
if (!res)
|
|
@@ -208,16 +182,3 @@ function applyPassToClient(passToClient, getObj) {
|
|
|
208
182
|
});
|
|
209
183
|
return { objClient, objClientProps };
|
|
210
184
|
}
|
|
211
|
-
function normalizePassToClientEntry(entry) {
|
|
212
|
-
let once;
|
|
213
|
-
let prop;
|
|
214
|
-
if (typeof entry === 'string') {
|
|
215
|
-
prop = entry;
|
|
216
|
-
once = false;
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
prop = entry.prop;
|
|
220
|
-
once = entry.once ?? false;
|
|
221
|
-
}
|
|
222
|
-
return { prop, once };
|
|
223
|
-
}
|
|
@@ -522,8 +522,8 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
522
522
|
const closeStream = async () => {
|
|
523
523
|
if (isClosed)
|
|
524
524
|
return;
|
|
525
|
-
isClosed = true;
|
|
526
525
|
await onEnd(isCancel);
|
|
526
|
+
isClosed = true;
|
|
527
527
|
controllerProxy.close();
|
|
528
528
|
};
|
|
529
529
|
let controllerProxy;
|
|
@@ -4,7 +4,7 @@ export type { PageContextCreated };
|
|
|
4
4
|
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
5
5
|
import type { PageContextInit } from '../renderPage.js';
|
|
6
6
|
type PageContextCreated = Awaited<ReturnType<typeof createPageContextServerSide>>;
|
|
7
|
-
declare function createPageContextServerSide(pageContextInit: PageContextInit, globalContext: GlobalContextServerInternal,
|
|
7
|
+
declare function createPageContextServerSide(pageContextInit: PageContextInit, globalContext: GlobalContextServerInternal, args: {
|
|
8
8
|
isPrerendering: false;
|
|
9
9
|
ssr: {
|
|
10
10
|
urlHandler: null | ((url: string) => string);
|
|
@@ -3,12 +3,9 @@ export { createPageContextServerSideWithoutGlobalContext };
|
|
|
3
3
|
import { assert, assertUsage, assertWarning, augmentType, normalizeHeaders, objectAssign } from '../utils.js';
|
|
4
4
|
import { getPageContextUrlComputed } from '../../../shared/getPageContextUrlComputed.js';
|
|
5
5
|
import { createPageContextObject, createPageContextShared } from '../../../shared/createPageContextShared.js';
|
|
6
|
-
function createPageContextServerSide(pageContextInit, globalContext,
|
|
7
|
-
urlHandler: null,
|
|
8
|
-
isClientSideNavigation: false,
|
|
9
|
-
}, }) {
|
|
6
|
+
function createPageContextServerSide(pageContextInit, globalContext, args) {
|
|
10
7
|
assert(pageContextInit.urlOriginal);
|
|
11
|
-
const pageContextCreated = createPageContext(pageContextInit, isPrerendering);
|
|
8
|
+
const pageContextCreated = createPageContext(pageContextInit, args.isPrerendering);
|
|
12
9
|
objectAssign(pageContextCreated, {
|
|
13
10
|
_globalContext: globalContext,
|
|
14
11
|
_pageFilesAll: globalContext._pageFilesAll, // TO-DO/next-major-release: remove
|
|
@@ -17,8 +14,8 @@ function createPageContextServerSide(pageContextInit, globalContext, { isPrerend
|
|
|
17
14
|
_baseAssets: globalContext.baseAssets,
|
|
18
15
|
_pageContextInit: pageContextInit,
|
|
19
16
|
_urlRewrite: null,
|
|
20
|
-
_urlHandler: urlHandler,
|
|
21
|
-
isClientSideNavigation,
|
|
17
|
+
_urlHandler: args.ssr?.urlHandler ?? null,
|
|
18
|
+
isClientSideNavigation: args.ssr?.isClientSideNavigation ?? false,
|
|
22
19
|
});
|
|
23
20
|
objectAssign(pageContextCreated, globalContext._vikeConfigPublicGlobal);
|
|
24
21
|
// pageContext.urlParsed
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { handleErrorWithoutErrorPage };
|
|
2
2
|
import type { GlobalContextServerInternal } from '../globalContext.js';
|
|
3
3
|
import type { PageContextAfterRender } from './renderPageAlreadyRouted.js';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import type { PageContextCreated } from './createPageContextServerSide.js';
|
|
5
|
+
declare function handleErrorWithoutErrorPage<PageContext extends PageContextCreated & {
|
|
6
6
|
errorWhileRendering: null | Error;
|
|
7
7
|
is404: null | boolean;
|
|
8
8
|
pageId: null;
|
|
@@ -1,30 +1,66 @@
|
|
|
1
1
|
export { handlePageContextRequestUrl };
|
|
2
2
|
import { pageContextJsonFileExtension, doNotCreateExtraDirectory } from '../../../shared/getPageContextRequestUrl.js';
|
|
3
|
-
import {
|
|
3
|
+
import { modifyUrl } from '../../../shared/modifyUrl.js';
|
|
4
|
+
import { baseServer, parseUrl, assert, slice, isObject, hasProp } from '../utils.js';
|
|
4
5
|
// See also shared/getPageContextRequestUrl.ts
|
|
5
6
|
function handlePageContextRequestUrl(url) {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
const urlParsed = parseUrl(url, baseServer);
|
|
8
|
+
if (!isMatch(urlParsed)) {
|
|
9
|
+
return {
|
|
10
|
+
isPageContextJsonRequest: false,
|
|
11
|
+
urlWithoutPageContextRequestSuffix: url,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const { urlWithoutPageContextRequestSuffix, searchVikeArgs } = processUrl(urlParsed, url);
|
|
16
|
+
const previousUrl = parseSearchVikeArgs(searchVikeArgs);
|
|
17
|
+
return {
|
|
18
|
+
/* TO-DO/soon/once: pass & use previousUrl
|
|
19
|
+
isPageContextJsonRequest: { previousUrl },
|
|
20
|
+
/*/
|
|
21
|
+
isPageContextJsonRequest: true,
|
|
22
|
+
//*/
|
|
23
|
+
urlWithoutPageContextRequestSuffix,
|
|
24
|
+
};
|
|
8
25
|
}
|
|
9
|
-
return { urlWithoutPageContextRequestSuffix: removePageContextUrlSuffix(url), isPageContextRequest: true };
|
|
10
26
|
}
|
|
11
|
-
function
|
|
12
|
-
const { pathnameOriginal, pathname } =
|
|
13
|
-
assert(
|
|
14
|
-
|
|
15
|
-
});
|
|
16
|
-
return pathnameOriginal.endsWith(pageContextJsonFileExtension);
|
|
27
|
+
function isMatch(urlParsed) {
|
|
28
|
+
const { pathnameOriginal, pathname } = urlParsed;
|
|
29
|
+
assert(pathname.endsWith(pageContextJsonFileExtension) === pathnameOriginal.endsWith(pageContextJsonFileExtension));
|
|
30
|
+
return pathname.endsWith(pageContextJsonFileExtension);
|
|
17
31
|
}
|
|
18
|
-
function
|
|
19
|
-
const urlParsed = parseUrl(url, baseServer);
|
|
32
|
+
function processUrl(urlParsed, url) {
|
|
20
33
|
// We cannot use `urlParsed.pathname` because it would break the `urlParsed.pathnameOriginal` value of subsequent `parseUrl()` calls.
|
|
21
|
-
const {
|
|
34
|
+
const { pathnameOriginal, search } = urlParsed;
|
|
22
35
|
assert(doNotCreateExtraDirectory === false);
|
|
23
36
|
const urlSuffix = `/index${pageContextJsonFileExtension}`;
|
|
24
37
|
assert(pathnameOriginal.endsWith(urlSuffix), { url });
|
|
25
38
|
let pathnameModified = slice(pathnameOriginal, 0, -1 * urlSuffix.length);
|
|
26
39
|
if (pathnameModified === '')
|
|
27
40
|
pathnameModified = '/';
|
|
28
|
-
|
|
29
|
-
|
|
41
|
+
const searchVikeArgs = search?._vike;
|
|
42
|
+
const urlWithoutPageContextRequestSuffix = modifyUrl(url, {
|
|
43
|
+
pathname: pathnameModified,
|
|
44
|
+
search: {
|
|
45
|
+
_vike: searchVikeArgs ? null : undefined,
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
searchVikeArgs,
|
|
50
|
+
urlWithoutPageContextRequestSuffix,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function parseSearchVikeArgs(searchVikeArgs) {
|
|
54
|
+
const args = {
|
|
55
|
+
previousUrl: null,
|
|
56
|
+
};
|
|
57
|
+
if (searchVikeArgs) {
|
|
58
|
+
const parsed = JSON.parse(searchVikeArgs);
|
|
59
|
+
assert(isObject(parsed));
|
|
60
|
+
if ('previousUrl' in parsed) {
|
|
61
|
+
assert(hasProp(parsed, 'previousUrl', 'string'));
|
|
62
|
+
args.previousUrl = parsed.previousUrl;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return args;
|
|
30
66
|
}
|
|
@@ -2,7 +2,7 @@ export { loadPageConfigsLazyServerSideAndExecHook };
|
|
|
2
2
|
import { getPageFilesServerSide } from '../../../shared/getPageFiles.js';
|
|
3
3
|
import { resolveVikeConfigPublicPageLazy } from '../../../shared/page-configs/resolveVikeConfigPublic.js';
|
|
4
4
|
import { analyzePageClientSideInit } from '../../../shared/getPageFiles/analyzePageClientSide.js';
|
|
5
|
-
import { assertUsage, assertWarning, hasProp, objectAssign } from '../utils.js';
|
|
5
|
+
import { assertUsage, assertWarning, hasProp, isArray, isObject, objectAssign } from '../utils.js';
|
|
6
6
|
import { getPageAssets } from './getPageAssets.js';
|
|
7
7
|
import { debugPageFiles } from './debugPageFiles.js';
|
|
8
8
|
import { findPageConfig } from '../../../shared/page-configs/findPageConfig.js';
|
|
@@ -29,19 +29,32 @@ async function loadPageConfigsLazyServerSide(pageContext) {
|
|
|
29
29
|
const { isHtmlOnly, isClientRouting, clientEntries, clientDependencies, pageFilesClientSide, pageFilesServerSide } = await analyzePage(pageContext._globalContext._pageFilesAll, pageConfig, pageContext.pageId, globalContext);
|
|
30
30
|
const isV1Design = !!pageConfig;
|
|
31
31
|
const passToClient = [];
|
|
32
|
-
const
|
|
32
|
+
const errMsgSuffix = ' should be an array of strings.';
|
|
33
33
|
if (!isV1Design) {
|
|
34
34
|
configPublicPageLazy.exportsAll.passToClient?.forEach((e) => {
|
|
35
|
-
assertUsage(hasProp(e, 'exportValue', 'string[]'), `${e.exportSource}${
|
|
35
|
+
assertUsage(hasProp(e, 'exportValue', 'string[]'), `${e.exportSource}${errMsgSuffix}`);
|
|
36
36
|
passToClient.push(...e.exportValue);
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
else {
|
|
40
40
|
configPublicPageLazy.from.configsCumulative.passToClient?.values.forEach((v) => {
|
|
41
|
-
const { value } = v;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const { value, definedAt } = v;
|
|
42
|
+
const errMsg = `+passToClient value defined at ${definedAt}${errMsgSuffix}`;
|
|
43
|
+
//*/ TO-DO/next-major-release: remove the passToClient once setting from the public API
|
|
44
|
+
assertUsage(isArray(value), `+passToClient value defined at ${definedAt} should be an array`);
|
|
45
|
+
const valS = value.map((el) => {
|
|
46
|
+
if (isObject(el)) {
|
|
47
|
+
assertWarning(!('once' in el), 'The passToClient once setting is deprecated and no longer has any effect. Instead, see the upcoming .once.js suffix (see https://github.com/vikejs/vike/issues/2566 for more information).', { onlyOnce: true });
|
|
48
|
+
assertUsage(hasProp(el, 'prop', 'string'), errMsg);
|
|
49
|
+
return el.prop;
|
|
50
|
+
}
|
|
51
|
+
assertUsage(typeof el === 'string', errMsg);
|
|
52
|
+
return el;
|
|
53
|
+
});
|
|
54
|
+
/*/
|
|
55
|
+
assertUsage(isArrayOfStrings(value), errMsg)
|
|
56
|
+
//*/
|
|
57
|
+
passToClient.push(...valS);
|
|
45
58
|
});
|
|
46
59
|
}
|
|
47
60
|
const pageContextAddendum = {};
|
|
@@ -2,10 +2,10 @@ export { log404 };
|
|
|
2
2
|
export { getRoutesInfo };
|
|
3
3
|
import type { PageRoutes } from '../../../../shared/route/index.js';
|
|
4
4
|
import type { GlobalContextServerInternal } from '../../globalContext.js';
|
|
5
|
-
|
|
5
|
+
import type { PageContextCreated } from '../createPageContextServerSide.js';
|
|
6
|
+
declare function log404(pageContext: PageContextCreated & {
|
|
6
7
|
urlPathname: string;
|
|
7
8
|
errorWhileRendering: null | Error;
|
|
8
|
-
isClientSideNavigation: boolean;
|
|
9
9
|
_globalContext: GlobalContextServerInternal;
|
|
10
10
|
}): Promise<void>;
|
|
11
11
|
declare function getRoutesInfo(pageRoutes: PageRoutes): string | null;
|
|
@@ -14,7 +14,6 @@ type PageContextForPublicUsageServer = PageContextInternalServer & VikeConfigPub
|
|
|
14
14
|
Page: unknown;
|
|
15
15
|
pageId: string;
|
|
16
16
|
is404: null | boolean;
|
|
17
|
-
isClientSideNavigation: boolean;
|
|
18
17
|
_globalContext: GlobalContextServerInternal;
|
|
19
18
|
};
|
|
20
19
|
declare function preparePageContextForPublicUsageServer<PageContext extends PageContextForPublicUsageServer>(pageContext: PageContext): PageContext;
|
|
@@ -5,6 +5,7 @@ import { type PageContextUrlInternal } from '../../../shared/getPageContextUrlCo
|
|
|
5
5
|
import { HttpResponse } from './createHttpResponse.js';
|
|
6
6
|
import { PageContext_loadPageConfigsLazyServerSide, type PageConfigsLazy } from './loadPageConfigsLazyServerSide.js';
|
|
7
7
|
import type { PageContextCreated } from './createPageContextServerSide.js';
|
|
8
|
+
import type { PageContextBegin } from '../renderPage.js';
|
|
8
9
|
type PageContextAfterRender = {
|
|
9
10
|
httpResponse: HttpResponse;
|
|
10
11
|
errorWhileRendering: null | Error;
|
|
@@ -16,7 +17,7 @@ declare function renderPageAlreadyRouted<PageContext extends {
|
|
|
16
17
|
routeParams: Record<string, string>;
|
|
17
18
|
errorWhileRendering: null | Error;
|
|
18
19
|
_httpRequestId: number;
|
|
19
|
-
} & PageContextCreated & PageContextUrlInternal & PageContext_loadPageConfigsLazyServerSide>(pageContext: PageContext): Promise<PageContext & PageContextAfterRender>;
|
|
20
|
+
} & PageContextCreated & PageContextBegin & PageContextUrlInternal & PageContext_loadPageConfigsLazyServerSide>(pageContext: PageContext): Promise<PageContext & PageContextAfterRender>;
|
|
20
21
|
declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy & {
|
|
21
22
|
routeParams: Record<string, string>;
|
|
22
23
|
pageId: string;
|
|
@@ -134,8 +135,7 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
134
135
|
_pageContextAlreadyProvidedByOnPrerenderHook?: true;
|
|
135
136
|
is404: boolean;
|
|
136
137
|
} & {
|
|
137
|
-
|
|
138
|
-
_urlHandler: null;
|
|
138
|
+
_isPageContextJsonRequest: null;
|
|
139
139
|
};
|
|
140
140
|
} | {
|
|
141
141
|
documentHtml: string;
|
|
@@ -246,7 +246,6 @@ declare function prerenderPage(pageContext: PageContextCreated & PageConfigsLazy
|
|
|
246
246
|
_pageContextAlreadyProvidedByOnPrerenderHook?: true;
|
|
247
247
|
is404: boolean;
|
|
248
248
|
} & {
|
|
249
|
-
|
|
250
|
-
_urlHandler: null;
|
|
249
|
+
_isPageContextJsonRequest: null;
|
|
251
250
|
};
|
|
252
251
|
}>;
|
|
@@ -58,8 +58,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
58
58
|
}
|
|
59
59
|
async function prerenderPage(pageContext) {
|
|
60
60
|
objectAssign(pageContext, {
|
|
61
|
-
|
|
62
|
-
_urlHandler: null,
|
|
61
|
+
_isPageContextJsonRequest: null,
|
|
63
62
|
});
|
|
64
63
|
/* Should we execute the guard() hook upon pre-rendering? Is there a use case for this?
|
|
65
64
|
* - It isn't trivial to implement, as it requires to duplicate / factor out the isAbortError() handling
|
|
@@ -68,7 +67,6 @@ async function prerenderPage(pageContext) {
|
|
|
68
67
|
await execHookDataAndOnBeforeRender(pageContext);
|
|
69
68
|
const { htmlRender, renderHook } = await execHookOnRenderHtml(pageContext);
|
|
70
69
|
assertUsage(htmlRender !== null, `Cannot pre-render ${pc.cyan(pageContext.urlOriginal)} because the ${renderHook.hookName}() hook defined by ${renderHook.hookFilePath} didn't return an HTML string.`);
|
|
71
|
-
assert(pageContext.isClientSideNavigation === false);
|
|
72
70
|
const documentHtml = await getHtmlString(htmlRender);
|
|
73
71
|
assert(typeof documentHtml === 'string');
|
|
74
72
|
if (!pageContext._usesClientRouter) {
|
|
@@ -307,7 +307,7 @@ async function getPageContextErrorPageInit(pageContextBegin, errNominalPage, pag
|
|
|
307
307
|
return pageContext;
|
|
308
308
|
}
|
|
309
309
|
function getPageContextBegin(pageContextInit, globalContext, httpRequestId) {
|
|
310
|
-
const { isClientSideNavigation, _urlHandler } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
310
|
+
const { isClientSideNavigation, _urlHandler, _isPageContextJsonRequest } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
311
311
|
const pageContextBegin = createPageContextServerSide(pageContextInit, globalContext, {
|
|
312
312
|
isPrerendering: false,
|
|
313
313
|
ssr: {
|
|
@@ -315,13 +315,14 @@ function getPageContextBegin(pageContextInit, globalContext, httpRequestId) {
|
|
|
315
315
|
isClientSideNavigation,
|
|
316
316
|
},
|
|
317
317
|
});
|
|
318
|
-
objectAssign(pageContextBegin, { _httpRequestId: httpRequestId });
|
|
318
|
+
objectAssign(pageContextBegin, { _httpRequestId: httpRequestId, _isPageContextJsonRequest });
|
|
319
319
|
return pageContextBegin;
|
|
320
320
|
}
|
|
321
321
|
function handlePageContextUrl(urlOriginal) {
|
|
322
|
-
const {
|
|
322
|
+
const { isPageContextJsonRequest } = handlePageContextRequestUrl(urlOriginal);
|
|
323
323
|
return {
|
|
324
|
-
isClientSideNavigation:
|
|
324
|
+
isClientSideNavigation: !!isPageContextJsonRequest,
|
|
325
|
+
_isPageContextJsonRequest: isPageContextJsonRequest,
|
|
325
326
|
_urlHandler: (url) => handlePageContextRequestUrl(url).urlWithoutPageContextRequestSuffix,
|
|
326
327
|
};
|
|
327
328
|
}
|
|
@@ -345,8 +346,8 @@ async function normalizeUrl(pageContextBegin, globalContext, httpRequestId) {
|
|
|
345
346
|
if (disableUrlNormalization)
|
|
346
347
|
return null;
|
|
347
348
|
const { urlOriginal } = pageContext;
|
|
348
|
-
const {
|
|
349
|
-
if (
|
|
349
|
+
const { isPageContextJsonRequest } = handlePageContextRequestUrl(urlOriginal);
|
|
350
|
+
if (isPageContextJsonRequest)
|
|
350
351
|
return null;
|
|
351
352
|
const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash ?? false, globalContext.baseServer);
|
|
352
353
|
if (!urlNormalized)
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export { determineOptimizeDeps };
|
|
2
2
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
3
3
|
import { assert, assertIsImportPathNpmPackage, createDebugger, getNpmPackageName, isArray, isFilePathAbsoluteFilesystem, isVirtualFileId, } from '../../utils.js';
|
|
4
|
-
import { getVikeConfigInternal
|
|
4
|
+
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
5
5
|
import { analyzeClientEntries } from '../pluginBuild/pluginBuildConfig.js';
|
|
6
6
|
import { virtualFileIdEntryClientCR, virtualFileIdEntryClientSR, } from '../../../shared/virtualFiles/virtualFileEntry.js';
|
|
7
7
|
import { getFilePathResolved } from '../../shared/getFilePath.js';
|
|
8
|
+
import { getConfigValueSourcesRelevant } from '../pluginVirtualFiles/getConfigValueSourcesRelevant.js';
|
|
8
9
|
const debug = createDebugger('vike:optimizeDeps');
|
|
9
10
|
async function determineOptimizeDeps(config) {
|
|
10
11
|
const vikeConfig = await getVikeConfigInternal();
|
|
@@ -38,43 +39,36 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
38
39
|
let entriesServer = [];
|
|
39
40
|
let includeClient = [];
|
|
40
41
|
let includeServer = [];
|
|
41
|
-
const addEntry = (e,
|
|
42
|
+
const addEntry = (e, isForClientSide, definedAt) => {
|
|
42
43
|
assert(e);
|
|
43
44
|
// optimizeDeps.entries expects filesystem absolute paths
|
|
44
45
|
assert(isVirtualFileId(e) || isFilePathAbsoluteFilesystem(e));
|
|
45
|
-
if (
|
|
46
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
47
|
+
return;
|
|
48
|
+
if (isForClientSide) {
|
|
46
49
|
entriesClient.push(e);
|
|
47
50
|
}
|
|
48
|
-
|
|
51
|
+
else {
|
|
49
52
|
entriesServer.push(e);
|
|
50
53
|
}
|
|
51
54
|
};
|
|
52
|
-
const addInclude = (e,
|
|
55
|
+
const addInclude = (e, isForClientSide, definedAt) => {
|
|
53
56
|
assert(e);
|
|
54
57
|
// optimizeDeps.include expects npm packages
|
|
55
58
|
assert(!e.startsWith('/'));
|
|
56
59
|
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
57
60
|
assertIsImportPathNpmPackage(e);
|
|
58
|
-
if (
|
|
61
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
62
|
+
return;
|
|
63
|
+
if (isForClientSide) {
|
|
59
64
|
includeClient.push(e);
|
|
60
65
|
}
|
|
61
|
-
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
62
|
-
includeServer.push(e);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
const isRelevant = (e, server, configEnv, definedAt) => {
|
|
66
|
-
if (server) {
|
|
67
|
-
if (!configEnv || !configEnv.server)
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
66
|
else {
|
|
71
|
-
|
|
72
|
-
return false;
|
|
67
|
+
includeServer.push(e);
|
|
73
68
|
}
|
|
74
|
-
return !isExcluded(e, server, definedAt);
|
|
75
69
|
};
|
|
76
|
-
const isExcluded = (e,
|
|
77
|
-
const exclude =
|
|
70
|
+
const isExcluded = (e, isForClientSide, definedAt) => {
|
|
71
|
+
const exclude = isForClientSide ? config.optimizeDeps.exclude : config.ssr.optimizeDeps.exclude;
|
|
78
72
|
if (!exclude)
|
|
79
73
|
return false;
|
|
80
74
|
if (definedAt?.importPathAbsolute) {
|
|
@@ -86,26 +80,34 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
86
80
|
};
|
|
87
81
|
// V1 design
|
|
88
82
|
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
83
|
+
;
|
|
84
|
+
[true, false].forEach((isForClientSide) => {
|
|
85
|
+
pageConfigs.forEach((pageConfig) => {
|
|
86
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
87
|
+
const runtimeEnv = {
|
|
88
|
+
isForClientSide,
|
|
89
|
+
isDev: true,
|
|
90
|
+
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
91
|
+
isClientRouting: true,
|
|
92
|
+
};
|
|
93
|
+
const sourcesRelevant = getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig);
|
|
94
|
+
sourcesRelevant.forEach((configValueSource) => {
|
|
95
|
+
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
96
|
+
return;
|
|
97
|
+
const { definedAt } = configValueSource;
|
|
98
|
+
if (definedAt.definedBy)
|
|
99
|
+
return;
|
|
100
|
+
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
101
|
+
addEntry(
|
|
102
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
103
|
+
definedAt.filePathAbsoluteFilesystem, isForClientSide, definedAt);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
addInclude(
|
|
107
|
+
// optimizeDeps.include expects npm packages
|
|
108
|
+
definedAt.importPathAbsolute, isForClientSide, definedAt);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
109
111
|
});
|
|
110
112
|
});
|
|
111
113
|
});
|
|
@@ -117,7 +119,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
117
119
|
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
118
120
|
const entry = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
119
121
|
const { filePathAbsoluteFilesystem } = entry;
|
|
120
|
-
addEntry(filePathAbsoluteFilesystem);
|
|
122
|
+
addEntry(filePathAbsoluteFilesystem, true);
|
|
121
123
|
});
|
|
122
124
|
}
|
|
123
125
|
// Add virtual files.
|
|
@@ -127,11 +129,11 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
127
129
|
// - If we do, then we need to adjust include/entries (maybe by making include === entries -> will Vite complain?)
|
|
128
130
|
{
|
|
129
131
|
const { hasClientRouting, hasServerRouting, clientEntries } = analyzeClientEntries(pageConfigs, config);
|
|
130
|
-
Object.values(clientEntries).forEach((e) => addEntry(e));
|
|
132
|
+
Object.values(clientEntries).forEach((e) => addEntry(e, true));
|
|
131
133
|
if (hasClientRouting)
|
|
132
|
-
addEntry(virtualFileIdEntryClientCR);
|
|
134
|
+
addEntry(virtualFileIdEntryClientCR, true);
|
|
133
135
|
if (hasServerRouting)
|
|
134
|
-
addEntry(virtualFileIdEntryClientSR);
|
|
136
|
+
addEntry(virtualFileIdEntryClientSR, true);
|
|
135
137
|
}
|
|
136
138
|
entriesClient = entriesClient;
|
|
137
139
|
entriesServer = entriesServer;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { getConfigValueSourcesRelevant };
|
|
2
|
+
export { isRuntimeEnvMatch };
|
|
3
|
+
export type { RuntimeEnv };
|
|
4
|
+
import type { ConfigEnvInternal, ConfigValueSource, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../../../../types/PageConfig.js';
|
|
5
|
+
type RuntimeEnv = {
|
|
6
|
+
isForClientSide: boolean;
|
|
7
|
+
isClientRouting: boolean;
|
|
8
|
+
isDev?: boolean;
|
|
9
|
+
} | {
|
|
10
|
+
isForConfig: true;
|
|
11
|
+
};
|
|
12
|
+
declare function getConfigValueSourcesRelevant(configName: string, runtimeEnv: RuntimeEnv, pageConfig: PageConfigPartial): ConfigValueSource[];
|
|
13
|
+
declare function isRuntimeEnvMatch(configEnv: ConfigEnvInternal, runtimeEnv: RuntimeEnv): boolean;
|
|
14
|
+
type PageConfigPartial = Pick<PageConfigBuildTime | PageConfigGlobalBuildTime, 'configValueSources' | 'configDefinitions'>;
|