vike 0.4.196 → 0.4.197
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/server-routing-runtime/onLoad.js +7 -0
- package/dist/cjs/client/server-routing-runtime/utils.js +34 -0
- package/dist/cjs/client/shared/getPageContextProxyForUser.js +79 -0
- package/dist/cjs/client/shared/preparePageContextForUserConsumptionClientSide.js +46 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +5 -5
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +3 -3
- package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +1 -1
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +4 -4
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -7
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/cjs/node/runtime/renderPage.js +8 -8
- package/dist/cjs/shared/addIs404ToPageProps.js +1 -1
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/preparePageContextForUserConsumption.js +34 -0
- package/dist/cjs/shared/route/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +6 -6
- package/dist/cjs/shared/route/index.js +3 -3
- package/dist/cjs/shared/route/resolveRouteString.js +10 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +4 -4
- package/dist/esm/client/client-routing-runtime/prefetch.js +4 -4
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +59 -12
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +1 -1
- package/dist/esm/client/shared/getPageContextSerializedInHtml.d.ts +1 -1
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -1
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +1 -1
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.js +20 -29
- package/dist/esm/client/shared/removeFoucBuster.js +17 -11
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/prerender/runPrerender.js +5 -5
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +3 -3
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/debugPageFiles.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -4
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +3 -8
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +6 -6
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/esm/node/runtime/renderPage.js +8 -8
- package/dist/esm/shared/addIs404ToPageProps.d.ts +1 -1
- package/dist/esm/shared/addIs404ToPageProps.js +1 -1
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +11 -0
- package/dist/esm/shared/preparePageContextForUserConsumption.d.ts +5 -0
- package/dist/esm/shared/preparePageContextForUserConsumption.js +32 -0
- package/dist/esm/shared/route/executeGuardHook.d.ts +1 -1
- package/dist/esm/shared/route/executeGuardHook.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +6 -6
- package/dist/esm/shared/route/index.d.ts +1 -1
- package/dist/esm/shared/route/index.js +3 -3
- package/dist/esm/shared/route/resolveRouteString.d.ts +2 -15
- package/dist/esm/shared/route/resolveRouteString.js +10 -1
- package/dist/esm/shared/types.d.ts +6 -2
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/shared/sortPageContext.js +0 -12
- package/dist/esm/shared/sortPageContext.d.ts +0 -2
- package/dist/esm/shared/sortPageContext.js +0 -10
- /package/{readme.md → README.md} +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Utils needed by Server Routing.
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
// We assume all runtime entries will load this utils.ts file
|
|
19
|
+
const onLoad_js_1 = require("./onLoad.js");
|
|
20
|
+
(0, onLoad_js_1.onLoad)();
|
|
21
|
+
__exportStar(require("../../utils/assert.js"), exports);
|
|
22
|
+
__exportStar(require("../../utils/assertSingleInstance.js"), exports);
|
|
23
|
+
__exportStar(require("../../shared/hooks/executeHook.js"), exports);
|
|
24
|
+
__exportStar(require("../../utils/checkType.js"), exports); // Only used by Server Routing (not needed for Client Routing)
|
|
25
|
+
__exportStar(require("../../utils/getCurrentUrl.js"), exports);
|
|
26
|
+
__exportStar(require("../../utils/getGlobalObject.js"), exports);
|
|
27
|
+
__exportStar(require("../../utils/hasProp.js"), exports);
|
|
28
|
+
__exportStar(require("../../utils/isCallable.js"), exports);
|
|
29
|
+
__exportStar(require("../../utils/isObject.js"), exports);
|
|
30
|
+
__exportStar(require("../../utils/objectAssign.js"), exports);
|
|
31
|
+
__exportStar(require("../../utils/parseUrl.js"), exports);
|
|
32
|
+
__exportStar(require("../../utils/slice.js"), exports);
|
|
33
|
+
__exportStar(require("../../utils/unique.js"), exports); // Only used by Server Routing (not needed for Client Routing)
|
|
34
|
+
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPageContextProxyForUser = getPageContextProxyForUser;
|
|
4
|
+
const utils_js_1 = require("../server-routing-runtime/utils.js");
|
|
5
|
+
const notSerializable_js_1 = require("../../shared/notSerializable.js");
|
|
6
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('getPageContextProxyForUser.ts', {});
|
|
7
|
+
/**
|
|
8
|
+
* Throw error when pageContext value isn't:
|
|
9
|
+
* - serializable, or
|
|
10
|
+
* - defined.
|
|
11
|
+
*/
|
|
12
|
+
function getPageContextProxyForUser(pageContext) {
|
|
13
|
+
(0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromServer));
|
|
14
|
+
(0, utils_js_1.assert)([true, false].includes(pageContext._hasPageContextFromClient));
|
|
15
|
+
return new Proxy(pageContext, {
|
|
16
|
+
get(_, prop) {
|
|
17
|
+
const val = pageContext[prop];
|
|
18
|
+
const propName = (0, utils_js_1.getPropAccessNotation)(prop);
|
|
19
|
+
(0, utils_js_1.assertUsage)(val !== notSerializable_js_1.notSerializable, `Can't access pageContext${propName} on the client side. Because it can't be serialized, see server logs.`);
|
|
20
|
+
passToClientHint(pageContext, prop, propName);
|
|
21
|
+
return val;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function passToClientHint(pageContext, prop, propName) {
|
|
26
|
+
if (handleVueReactivity(prop))
|
|
27
|
+
return;
|
|
28
|
+
// `prop in pageContext` is the trick we use to know the passToClient value on the client-side, as we set a value to all passToClient props, even `undefined` ones:
|
|
29
|
+
// ```html
|
|
30
|
+
// <script id="vike_pageContext" type="application/json">{"pageProps":"!undefined"}</script>
|
|
31
|
+
// ```
|
|
32
|
+
if (prop in pageContext)
|
|
33
|
+
return;
|
|
34
|
+
if (isWhitelisted(prop))
|
|
35
|
+
return;
|
|
36
|
+
// The trick described above (`prop in pageContext`) doesn't work if Vike doesn't fetch any pageContext from the server.
|
|
37
|
+
// - There would still be some value to show a warning, but it isn't worth it because of the confusion that the first recommendation (adding `prop` to `passToClient`) wouldn't actually remove the warning, and only the second recommendation (using `prop in pageContext` instead of `pageContext[prop]`) would work.
|
|
38
|
+
if (!pageContext._hasPageContextFromServer)
|
|
39
|
+
return;
|
|
40
|
+
const errMsg = `pageContext${propName} isn't defined on the client-side, see https://vike.dev/passToClient#error`;
|
|
41
|
+
if (
|
|
42
|
+
// TODO/next-major-release always make it an error.
|
|
43
|
+
// - Remove pageContext._hasPageContextFromClient logic (IIRC this is its only use case).
|
|
44
|
+
pageContext._hasPageContextFromClient) {
|
|
45
|
+
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: false, showStackTrace: true });
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const WHITELIST = [
|
|
52
|
+
'then',
|
|
53
|
+
// Vue calls toJSON()
|
|
54
|
+
'toJSON'
|
|
55
|
+
];
|
|
56
|
+
function isWhitelisted(prop) {
|
|
57
|
+
if (WHITELIST.includes(prop))
|
|
58
|
+
return true;
|
|
59
|
+
if (typeof prop === 'symbol')
|
|
60
|
+
return true; // Vue tries to access some symbols
|
|
61
|
+
if (typeof prop !== 'string')
|
|
62
|
+
return true;
|
|
63
|
+
if (prop.startsWith('__v_'))
|
|
64
|
+
return true; // Vue internals upon `reactive(pageContext)`
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
// Handle Vue's reactivity.
|
|
68
|
+
// When changing a reactive object:
|
|
69
|
+
// - Vue tries to read its old value first. This triggers a `assertIsDefined()` failure if e.g. `pageContextReactive.routeParams = pageContextNew.routeParams` and `pageContextReactive` has no `routeParams`.
|
|
70
|
+
// - Vue seems to read __v_raw before reading the property.
|
|
71
|
+
function handleVueReactivity(prop) {
|
|
72
|
+
if (globalObject.prev === prop || globalObject.prev === '__v_raw')
|
|
73
|
+
return true;
|
|
74
|
+
globalObject.prev = prop;
|
|
75
|
+
window.setTimeout(() => {
|
|
76
|
+
globalObject.prev = undefined;
|
|
77
|
+
}, 0);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preparePageContextForUserConsumptionClientSide = preparePageContextForUserConsumptionClientSide;
|
|
4
|
+
const utils_js_1 = require("../server-routing-runtime/utils.js");
|
|
5
|
+
const getPageContextProxyForUser_js_1 = require("./getPageContextProxyForUser.js");
|
|
6
|
+
const preparePageContextForUserConsumption_js_1 = require("../../shared/preparePageContextForUserConsumption.js");
|
|
7
|
+
function preparePageContextForUserConsumptionClientSide(pageContext, isClientRouting) {
|
|
8
|
+
if (isClientRouting) {
|
|
9
|
+
const pageContextTyped = pageContext;
|
|
10
|
+
(0, utils_js_1.assert)([true, false].includes(pageContextTyped.isHydration));
|
|
11
|
+
(0, utils_js_1.assert)([true, false, null].includes(pageContextTyped.isBackwardNavigation));
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const pageContextTyped = pageContext;
|
|
15
|
+
(0, utils_js_1.assert)(pageContextTyped.isHydration === true);
|
|
16
|
+
(0, utils_js_1.assert)(pageContextTyped.isBackwardNavigation === null);
|
|
17
|
+
}
|
|
18
|
+
const Page = pageContext.config.Page ||
|
|
19
|
+
// TODO/next-major-release: remove
|
|
20
|
+
pageContext.exports.Page;
|
|
21
|
+
(0, utils_js_1.objectAssign)(pageContext, { Page });
|
|
22
|
+
// TODO/next-major-release: remove
|
|
23
|
+
// - Requires https://github.com/vikejs/vike-vue/issues/198
|
|
24
|
+
// - Last time I tried to remove it (https://github.com/vikejs/vike/commit/705fd23598d9d69bf46a52c8550216cd7117ce71) the tests were failing as expected: only the Vue integrations that used shallowReactive() failed.
|
|
25
|
+
supportVueReactiviy(pageContext);
|
|
26
|
+
(0, preparePageContextForUserConsumption_js_1.preparePageContextForUserConsumption)(pageContext);
|
|
27
|
+
const pageContextProxy = (0, getPageContextProxyForUser_js_1.getPageContextProxyForUser)(pageContext);
|
|
28
|
+
return pageContextProxy;
|
|
29
|
+
}
|
|
30
|
+
// With Vue + Cient Routing, the `pageContext` is made reactive:
|
|
31
|
+
// ```js
|
|
32
|
+
// import { reactive } from 'vue'
|
|
33
|
+
// // See /examples/vue-full/renderer/createVueApp.ts
|
|
34
|
+
// const pageContextReactive = reactive(pageContext)
|
|
35
|
+
// ```
|
|
36
|
+
function supportVueReactiviy(pageContext) {
|
|
37
|
+
resolveGetters(pageContext);
|
|
38
|
+
}
|
|
39
|
+
// Remove propery descriptor getters because they break Vue's reactivity.
|
|
40
|
+
// E.g. resolve the `pageContext.urlPathname` getter.
|
|
41
|
+
function resolveGetters(pageContext) {
|
|
42
|
+
Object.entries(pageContext).forEach(([key, val]) => {
|
|
43
|
+
delete pageContext[key];
|
|
44
|
+
pageContext[key] = val;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -243,7 +243,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
|
|
|
243
243
|
const importedFilesLoaded = {};
|
|
244
244
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
245
245
|
const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
246
|
-
.filter(([
|
|
246
|
+
.filter(([pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
247
247
|
.map(async ([locationId]) => {
|
|
248
248
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
249
249
|
const interfaceFilesRelevantList = Object.values(interfaceFilesRelevant).flat(1);
|
|
@@ -306,7 +306,7 @@ async function handlePagesWithStaticRoutes(prerenderContext, renderContext, doNo
|
|
|
306
306
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
307
307
|
_providedByHook: null,
|
|
308
308
|
routeParams,
|
|
309
|
-
|
|
309
|
+
pageId: pageId,
|
|
310
310
|
_debugRouteMatches: [
|
|
311
311
|
{
|
|
312
312
|
pageId,
|
|
@@ -469,8 +469,8 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
469
469
|
const { urlOriginal } = pageContext;
|
|
470
470
|
(0, utils_js_1.assert)(urlOriginal);
|
|
471
471
|
const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
|
|
472
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextFromRoute, '
|
|
473
|
-
if (pageContextFromRoute.
|
|
472
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextFromRoute, 'pageId', 'null') || (0, utils_js_1.hasProp)(pageContextFromRoute, 'pageId', 'string'));
|
|
473
|
+
if (pageContextFromRoute.pageId === null) {
|
|
474
474
|
let hookName;
|
|
475
475
|
let hookFilePath;
|
|
476
476
|
if (pageContext._providedByHook) {
|
|
@@ -492,9 +492,9 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
492
492
|
return;
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
(0, utils_js_1.assert)(pageContextFromRoute.
|
|
495
|
+
(0, utils_js_1.assert)(pageContextFromRoute.pageId);
|
|
496
496
|
(0, utils_js_1.objectAssign)(pageContext, pageContextFromRoute);
|
|
497
|
-
const {
|
|
497
|
+
const { pageId: pageId } = pageContext;
|
|
498
498
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
499
499
|
let usesClientRouter;
|
|
500
500
|
{
|
|
@@ -19,7 +19,7 @@ function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter,
|
|
|
19
19
|
(0, utils_js_1.assert)([true, false].includes(pageContext._isHtmlOnly));
|
|
20
20
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
21
21
|
const { isProduction } = (0, globalContext_js_1.getGlobalContext)();
|
|
22
|
-
const injectScriptsAt = getInjectScriptsAt(pageContext.
|
|
22
|
+
const injectScriptsAt = getInjectScriptsAt(pageContext.pageId, pageContext._pageConfigs);
|
|
23
23
|
const injectFilterEntries = pageAssets
|
|
24
24
|
.filter((asset) => {
|
|
25
25
|
if (asset.isEntry && asset.assetType === 'script') {
|
|
@@ -16,7 +16,7 @@ async function injectAssets__public(htmlString, pageContext) {
|
|
|
16
16
|
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, 'urlPathname', 'string'), errMsg('`pageContext.urlPathname` should be a string'), {
|
|
17
17
|
showStackTrace: true
|
|
18
18
|
});
|
|
19
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, '
|
|
19
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, 'pageId', 'string'), errMsg('`pageContext.pageId` should be a string'), {
|
|
20
20
|
showStackTrace: true
|
|
21
21
|
});
|
|
22
22
|
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(pageContext, '__getPageAssets'), errMsg('`pageContext.__getPageAssets` is missing'), {
|
|
@@ -23,7 +23,7 @@ const PASS_TO_CLIENT = [
|
|
|
23
23
|
'_abortCaller',
|
|
24
24
|
*/
|
|
25
25
|
pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient,
|
|
26
|
-
'
|
|
26
|
+
'pageId',
|
|
27
27
|
'routeParams',
|
|
28
28
|
'data' // for data() hook
|
|
29
29
|
];
|
|
@@ -100,7 +100,7 @@ function serialize(value, varName) {
|
|
|
100
100
|
}
|
|
101
101
|
function getPassToClient(pageContext) {
|
|
102
102
|
let passToClient = [...pageContext._passToClient, ...PASS_TO_CLIENT];
|
|
103
|
-
if ((0, error_page_js_1.isErrorPage)(pageContext.
|
|
103
|
+
if ((0, error_page_js_1.isErrorPage)(pageContext.pageId, pageContext._pageConfigs)) {
|
|
104
104
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'is404', 'boolean'));
|
|
105
105
|
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
106
106
|
passToClient.push(...PASS_TO_CLIENT_ERROR_PAGE);
|
|
@@ -14,7 +14,7 @@ const assertNoInfiniteHttpRedirect_js_1 = require("./createHttpResponse/assertNo
|
|
|
14
14
|
async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
15
15
|
let statusCode = pageContext.abortStatusCode;
|
|
16
16
|
if (!statusCode) {
|
|
17
|
-
const isError = !pageContext.
|
|
17
|
+
const isError = !pageContext.pageId || (0, error_page_js_1.isErrorPage)(pageContext.pageId, pageContext._pageConfigs);
|
|
18
18
|
if (pageContext.errorWhileRendering) {
|
|
19
19
|
(0, utils_js_1.assert)(isError);
|
|
20
20
|
}
|
|
@@ -29,8 +29,8 @@ async function createHttpResponsePage(htmlRender, renderHook, pageContext) {
|
|
|
29
29
|
}
|
|
30
30
|
const earlyHints = (0, getEarlyHints_js_1.getEarlyHints)(await pageContext.__getPageAssets());
|
|
31
31
|
const headers = [];
|
|
32
|
-
(0, utils_js_1.assert)(pageContext.
|
|
33
|
-
const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.
|
|
32
|
+
(0, utils_js_1.assert)(pageContext.pageId);
|
|
33
|
+
const cacheControl = (0, getCacheControl_js_1.getCacheControl)(pageContext.pageId, pageContext._pageConfigs);
|
|
34
34
|
if (cacheControl) {
|
|
35
35
|
headers.push(['Cache-Control', cacheControl]);
|
|
36
36
|
}
|
|
@@ -12,7 +12,7 @@ function debugPageFiles({ pageContext, isHtmlOnly, isClientRouting, pageFilesLoa
|
|
|
12
12
|
debug('All page files:', printPageFiles(pageContext._pageFilesAll, true)); // TODO
|
|
13
13
|
debug(`URL:`, pageContext.urlOriginal);
|
|
14
14
|
debug.options({ serialization: { emptyArray: 'No match' } })(`Routing:`, printRouteMatches(pageContext._debugRouteMatches));
|
|
15
|
-
debug(`pageId:`, pageContext.
|
|
15
|
+
debug(`pageId:`, pageContext.pageId);
|
|
16
16
|
debug('Page type:', isHtmlOnly ? 'HTML-only' : 'SSR/SPA');
|
|
17
17
|
debug(`Routing type:`, !isHtmlOnly && isClientRouting ? 'Client Routing' : 'Server Routing');
|
|
18
18
|
debug('Server-side page files:', printPageFiles(pageFilesLoaded));
|
|
@@ -11,7 +11,7 @@ const createHttpResponse_js_1 = require("./createHttpResponse.js");
|
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
12
|
// When the user hasn't defined _error.page.js
|
|
13
13
|
async function handleErrorWithoutErrorPage(pageContext) {
|
|
14
|
-
(0, utils_js_1.assert)(pageContext.
|
|
14
|
+
(0, utils_js_1.assert)(pageContext.pageId === null);
|
|
15
15
|
(0, utils_js_1.assert)(pageContext.errorWhileRendering || pageContext.is404);
|
|
16
16
|
{
|
|
17
17
|
const isV1 = pageContext._pageConfigs.length > 0;
|
|
@@ -11,12 +11,12 @@ const analyzePage_js_1 = require("./analyzePage.js");
|
|
|
11
11
|
const globalContext_js_1 = require("../globalContext.js");
|
|
12
12
|
const loadConfigValues_js_1 = require("../../../shared/page-configs/loadConfigValues.js");
|
|
13
13
|
async function loadUserFilesServerSide(pageContext) {
|
|
14
|
-
const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._pageConfigs, pageContext.
|
|
14
|
+
const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._pageConfigs, pageContext.pageId); // Make pageConfig globally available as pageContext._pageConfig?
|
|
15
15
|
const [{ pageFilesLoaded, pageContextExports }] = await Promise.all([
|
|
16
|
-
loadPageUserFiles(pageContext._pageFilesAll, pageConfig, pageContext.
|
|
17
|
-
(0, analyzePageClientSide_js_1.analyzePageClientSideInit)(pageContext._pageFilesAll, pageContext.
|
|
16
|
+
loadPageUserFiles(pageContext._pageFilesAll, pageConfig, pageContext.pageId, !(0, globalContext_js_1.getGlobalContext)().isProduction),
|
|
17
|
+
(0, analyzePageClientSide_js_1.analyzePageClientSideInit)(pageContext._pageFilesAll, pageContext.pageId, { sharedPageFilesAlreadyLoaded: true })
|
|
18
18
|
]);
|
|
19
|
-
const { isHtmlOnly, isClientRouting, clientEntries, clientDependencies, pageFilesClientSide, pageFilesServerSide } = (0, analyzePage_js_1.analyzePage)(pageContext._pageFilesAll, pageConfig, pageContext.
|
|
19
|
+
const { isHtmlOnly, isClientRouting, clientEntries, clientDependencies, pageFilesClientSide, pageFilesServerSide } = (0, analyzePage_js_1.analyzePage)(pageContext._pageFilesAll, pageConfig, pageContext.pageId);
|
|
20
20
|
const isV1Design = !!pageConfig;
|
|
21
21
|
const passToClient = [];
|
|
22
22
|
const errMsg = ' should be an array of strings.';
|
|
@@ -2,17 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.preparePageContextForUserConsumptionServerSide = preparePageContextForUserConsumptionServerSide;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
const sortPageContext_js_1 = require("../../../shared/sortPageContext.js");
|
|
6
5
|
const getPageContextUrlComputed_js_1 = require("../../../shared/getPageContextUrlComputed.js");
|
|
7
|
-
const
|
|
6
|
+
const preparePageContextForUserConsumption_js_1 = require("../../../shared/preparePageContextForUserConsumption.js");
|
|
8
7
|
function preparePageContextForUserConsumptionServerSide(pageContext) {
|
|
9
8
|
(0, getPageContextUrlComputed_js_1.assertPageContextUrl)(pageContext);
|
|
10
9
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(pageContext.routeParams));
|
|
11
10
|
(0, utils_js_1.assert)('Page' in pageContext);
|
|
12
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageContext.pageExports));
|
|
13
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageContext.exports));
|
|
14
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageContext.exportsAll));
|
|
15
11
|
(0, utils_js_1.assert)(typeof pageContext.isClientSideNavigation === 'boolean');
|
|
16
|
-
(0,
|
|
17
|
-
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
12
|
+
(0, preparePageContextForUserConsumption_js_1.preparePageContextForUserConsumption)(pageContext);
|
|
18
13
|
}
|
|
@@ -28,12 +28,12 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
28
28
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
29
29
|
const assertV1Design_js_1 = require("../../shared/assertV1Design.js");
|
|
30
30
|
async function renderPageAlreadyRouted(pageContext) {
|
|
31
|
-
// pageContext.
|
|
31
|
+
// pageContext.pageId can either be the:
|
|
32
32
|
// - ID of the page matching the routing, or the
|
|
33
33
|
// - ID of the error page `_error.page.js`.
|
|
34
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, '
|
|
34
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'pageId', 'string'));
|
|
35
35
|
const isError = pageContext.is404 || !!pageContext.errorWhileRendering;
|
|
36
|
-
(0, utils_js_1.assert)(isError === (pageContext.
|
|
36
|
+
(0, utils_js_1.assert)(isError === (pageContext.pageId === (0, error_page_js_1.getErrorPageId)(pageContext._pageFilesAll, pageContext._pageConfigs)));
|
|
37
37
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadUserFilesServerSide_js_1.loadUserFilesServerSide)(pageContext));
|
|
38
38
|
if (!isError) {
|
|
39
39
|
await (0, executeGuardHook_js_1.executeGuardHook)(pageContext, (pageContext) => (0, preparePageContextForUserConsumptionServerSide_js_1.preparePageContextForUserConsumptionServerSide)(pageContext));
|
|
@@ -95,7 +95,7 @@ async function prerender404Page(renderContext, pageContextInit_) {
|
|
|
95
95
|
return null;
|
|
96
96
|
}
|
|
97
97
|
const pageContext = {
|
|
98
|
-
|
|
98
|
+
pageId: errorPageId,
|
|
99
99
|
_httpRequestId: null,
|
|
100
100
|
_urlRewrite: null,
|
|
101
101
|
is404: true,
|
|
@@ -163,11 +163,11 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
163
163
|
{
|
|
164
164
|
const errorPageId = (0, error_page_js_1.getErrorPageId)(renderContext.pageFilesAll, renderContext.pageConfigs);
|
|
165
165
|
if (!errorPageId) {
|
|
166
|
-
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, {
|
|
166
|
+
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: null });
|
|
167
167
|
return (0, handleErrorWithoutErrorPage_js_1.handleErrorWithoutErrorPage)(pageContextErrorPageInit);
|
|
168
168
|
}
|
|
169
169
|
else {
|
|
170
|
-
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, {
|
|
170
|
+
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: errorPageId });
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
let pageContextErrorPage;
|
|
@@ -276,17 +276,17 @@ async function renderPageNominal(pageContext) {
|
|
|
276
276
|
{
|
|
277
277
|
const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
|
|
278
278
|
(0, utils_js_1.objectAssign)(pageContext, pageContextFromRoute);
|
|
279
|
-
(0, utils_js_1.objectAssign)(pageContext, { is404: pageContext.
|
|
280
|
-
if (pageContext.
|
|
279
|
+
(0, utils_js_1.objectAssign)(pageContext, { is404: pageContext.pageId ? null : true });
|
|
280
|
+
if (pageContext.pageId === null) {
|
|
281
281
|
const errorPageId = (0, error_page_js_1.getErrorPageId)(pageContext._pageFilesAll, pageContext._pageConfigs);
|
|
282
282
|
if (!errorPageId) {
|
|
283
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, '
|
|
283
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'pageId', 'null'));
|
|
284
284
|
return (0, handleErrorWithoutErrorPage_js_1.handleErrorWithoutErrorPage)(pageContext);
|
|
285
285
|
}
|
|
286
|
-
(0, utils_js_1.objectAssign)(pageContext, {
|
|
286
|
+
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, '
|
|
289
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'pageId', 'string'));
|
|
290
290
|
(0, utils_js_1.assert)(pageContext.errorWhileRendering === null);
|
|
291
291
|
// Render
|
|
292
292
|
const pageContextAfterRender = await (0, renderPageAlreadyRouted_js_1.renderPageAlreadyRouted)(pageContext);
|
|
@@ -406,7 +406,7 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
406
406
|
(0, utils_js_1.assert)(abortCall);
|
|
407
407
|
(0, utils_js_1.assertUsage)(errorPageId, `You called ${picocolors_1.default.cyan(abortCall)} but you didn't define an error page, make sure to define one https://vike.dev/error-page`);
|
|
408
408
|
const pageContext = createPageContext({});
|
|
409
|
-
(0, utils_js_1.objectAssign)(pageContext, {
|
|
409
|
+
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
410
410
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
411
411
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit);
|
|
412
412
|
(0, utils_js_1.objectAssign)(pageContext, renderContext);
|
|
@@ -8,7 +8,7 @@ function addIs404ToPageProps(pageContext) {
|
|
|
8
8
|
addIs404(pageContext);
|
|
9
9
|
}
|
|
10
10
|
function assertIs404(pageContext) {
|
|
11
|
-
if ((0, error_page_js_1.isErrorPage)(pageContext.
|
|
11
|
+
if ((0, error_page_js_1.isErrorPage)(pageContext.pageId, pageContext._pageConfigs)) {
|
|
12
12
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'is404', 'boolean'));
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -15,6 +15,6 @@ function assertPageContextProvidedByUser(pageContextProvidedByUser, { hookName,
|
|
|
15
15
|
(0, utils_js_1.assertUsage)(!('_objectCreatedByVike' in pageContextProvidedByUser), `${errPrefix} shouldn't be the whole ${picocolors_1.default.cyan('pageContext')} object, see https://vike.dev/pageContext-manipulation#do-not-return-entire-pagecontext`);
|
|
16
16
|
// In principle, it's possible to use onBeforeRoute()` to override and define the whole routing.
|
|
17
17
|
// Is that a good idea to allow users to do this? Beyond deep integration with Vue Router or React Router, is there a use case for this?
|
|
18
|
-
(0, utils_js_1.assertWarning)(!('
|
|
18
|
+
(0, utils_js_1.assertWarning)(!('pageId' in pageContextProvidedByUser), `${errPrefix} sets ${picocolors_1.default.cyan('pageContext.pageId')} which means that Vike's routing is overriden. This is an experimental feature: make sure to contact a vike maintainer before using this.`, { onlyOnce: true });
|
|
19
19
|
(0, utils_js_1.assertUsage)(!('is404' in pageContextProvidedByUser), `${errPrefix} sets ${picocolors_1.default.cyan('pageContext.is404')} which is forbidden, use ${picocolors_1.default.cyan('throw render()')} instead, see https://vike.dev/render`);
|
|
20
20
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preparePageContextForUserConsumption = preparePageContextForUserConsumption;
|
|
4
|
+
const utils_js_1 = require("./utils.js");
|
|
5
|
+
const addIs404ToPageProps_js_1 = require("./addIs404ToPageProps.js");
|
|
6
|
+
function preparePageContextForUserConsumption(pageContext) {
|
|
7
|
+
(0, utils_js_1.assert)(pageContext.pageId);
|
|
8
|
+
(0, utils_js_1.assert)('config' in pageContext);
|
|
9
|
+
(0, utils_js_1.assert)('configEntries' in pageContext);
|
|
10
|
+
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
11
|
+
// TODO/next-major-release: remove
|
|
12
|
+
if (!('_pageId' in pageContext)) {
|
|
13
|
+
Object.defineProperty(pageContext, '_pageId', {
|
|
14
|
+
get() {
|
|
15
|
+
(0, utils_js_1.assertWarning)(false, 'pageContext._pageId has been renamed to pageContext.pageId', {
|
|
16
|
+
showStackTrace: true,
|
|
17
|
+
onlyOnce: true
|
|
18
|
+
});
|
|
19
|
+
return pageContext.pageId;
|
|
20
|
+
},
|
|
21
|
+
enumerable: false
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
// For a more readable `console.log(pageContext)` output
|
|
25
|
+
sortPageContext(pageContext);
|
|
26
|
+
}
|
|
27
|
+
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
28
|
+
function sortPageContext(pageContext) {
|
|
29
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
30
|
+
for (const key of Object.keys(pageContext))
|
|
31
|
+
delete pageContext[key];
|
|
32
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => (0, utils_js_1.compareString)(key1, key2)));
|
|
33
|
+
Object.defineProperties(pageContext, descriptors);
|
|
34
|
+
}
|
|
@@ -10,7 +10,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
10
10
|
if (pageContext._pageFilesAll.length > 0) {
|
|
11
11
|
// V0.4 design
|
|
12
12
|
(0, utils_js_1.assert)(pageContext._pageConfigs.length === 0);
|
|
13
|
-
hook = findPageGuard(pageContext.
|
|
13
|
+
hook = findPageGuard(pageContext.pageId, pageContext._pageFilesAll);
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
16
16
|
// V1 design
|
|
@@ -16,8 +16,8 @@ async function executeOnBeforeRouteHook(pageContext) {
|
|
|
16
16
|
const pageContextFromHook = await getPageContextFromHook(pageContext._onBeforeRouteHook, pageContext);
|
|
17
17
|
if (pageContextFromHook) {
|
|
18
18
|
(0, utils_js_1.objectAssign)(pageContextFromOnBeforeRouteHook, pageContextFromHook);
|
|
19
|
-
if ((0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, '
|
|
20
|
-
(0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, '
|
|
19
|
+
if ((0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, 'pageId', 'string') ||
|
|
20
|
+
(0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, 'pageId', 'null')) {
|
|
21
21
|
// We bypass Vike's routing
|
|
22
22
|
if (!(0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, 'routeParams')) {
|
|
23
23
|
(0, utils_js_1.objectAssign)(pageContextFromOnBeforeRouteHook, { routeParams: {} });
|
|
@@ -50,10 +50,10 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
50
50
|
return null;
|
|
51
51
|
}
|
|
52
52
|
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(hookReturn, 'pageContext', 'object'), `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext }')} but pageContext should be a plain JavaScript object.`);
|
|
53
|
-
if ((0, utils_js_1.hasProp)(hookReturn.pageContext, '
|
|
54
|
-
const errPrefix2 = `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: {
|
|
55
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(hookReturn.pageContext, '
|
|
56
|
-
(0, utils_js_1.assertUsage)(pageContext._allPageIds.includes(hookReturn.pageContext.
|
|
53
|
+
if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'pageId') && !(0, utils_js_1.hasProp)(hookReturn.pageContext, 'pageId', 'null')) {
|
|
54
|
+
const errPrefix2 = `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { pageId } }')} but ${picocolors_1.default.cyan('pageId')} should be`;
|
|
55
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(hookReturn.pageContext, 'pageId', 'string'), `${errPrefix2} a string or null`);
|
|
56
|
+
(0, utils_js_1.assertUsage)(pageContext._allPageIds.includes(hookReturn.pageContext.pageId), `${errPrefix2} ${(0, utils_js_1.joinEnglish)(pageContext._allPageIds.map((s) => picocolors_1.default.cyan(s)), 'or')}`);
|
|
57
57
|
}
|
|
58
58
|
if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'routeParams')) {
|
|
59
59
|
(0, resolveRouteFunction_js_1.assertRouteParams)(hookReturn.pageContext, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { routeParams } }')} but routeParams should`);
|
|
@@ -26,7 +26,7 @@ async function route(pageContext) {
|
|
|
26
26
|
const pageContextFromOnBeforeRouteHook = await (0, executeOnBeforeRouteHook_js_1.executeOnBeforeRouteHook)(pageContext);
|
|
27
27
|
if (pageContextFromOnBeforeRouteHook) {
|
|
28
28
|
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
29
|
-
(0, utils_js_1.assert)(pageContextFromOnBeforeRouteHook.
|
|
29
|
+
(0, utils_js_1.assert)(pageContextFromOnBeforeRouteHook.pageId);
|
|
30
30
|
return pageContextFromOnBeforeRouteHook;
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
@@ -90,7 +90,7 @@ async function route(pageContext) {
|
|
|
90
90
|
(0, utils_js_1.objectAssign)(pageContextFromRoute, { _routeMatch: winner });
|
|
91
91
|
if (!winner) {
|
|
92
92
|
(0, utils_js_1.objectAssign)(pageContextFromRoute, {
|
|
93
|
-
|
|
93
|
+
pageId: null,
|
|
94
94
|
routeParams: {}
|
|
95
95
|
});
|
|
96
96
|
return pageContextFromRoute;
|
|
@@ -99,7 +99,7 @@ async function route(pageContext) {
|
|
|
99
99
|
const { routeParams } = winner;
|
|
100
100
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(routeParams));
|
|
101
101
|
(0, utils_js_1.objectAssign)(pageContextFromRoute, {
|
|
102
|
-
|
|
102
|
+
pageId: winner.pageId,
|
|
103
103
|
routeParams: winner.routeParams
|
|
104
104
|
});
|
|
105
105
|
}
|
|
@@ -8,7 +8,7 @@ exports.getUrlFromRouteString = getUrlFromRouteString;
|
|
|
8
8
|
exports.isStaticRouteString = isStaticRouteString;
|
|
9
9
|
exports.analyzeRouteString = analyzeRouteString;
|
|
10
10
|
exports.assertRouteString = assertRouteString;
|
|
11
|
-
exports.
|
|
11
|
+
exports.getRouteStringParameterList = getRouteStringParameterList;
|
|
12
12
|
const utils_js_1 = require("../utils.js");
|
|
13
13
|
const utils_js_2 = require("./utils.js");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
@@ -101,6 +101,15 @@ function parseRouteString(routeString) {
|
|
|
101
101
|
});
|
|
102
102
|
return segments;
|
|
103
103
|
}
|
|
104
|
+
function getRouteStringParameterList(routeString) {
|
|
105
|
+
const routeParameterList = [];
|
|
106
|
+
const segments = parseRouteString(routeString);
|
|
107
|
+
segments.forEach((segment) => {
|
|
108
|
+
if (segment.param)
|
|
109
|
+
routeParameterList.push(segment.param);
|
|
110
|
+
});
|
|
111
|
+
return routeParameterList;
|
|
112
|
+
}
|
|
104
113
|
function getUrlFromRouteString(routeString) {
|
|
105
114
|
if (isStaticRouteString(routeString)) {
|
|
106
115
|
const url = routeString;
|
|
@@ -10,7 +10,7 @@ type PageContext = {
|
|
|
10
10
|
_pageConfigs: PageConfigRuntime[];
|
|
11
11
|
};
|
|
12
12
|
type PageContextSerialized = {
|
|
13
|
-
|
|
13
|
+
pageId: string;
|
|
14
14
|
_hasPageContextFromServer: true;
|
|
15
15
|
};
|
|
16
16
|
declare function getPageContextFromHooks_serialized(): PageContextSerialized & {
|
|
@@ -22,13 +22,13 @@ declare function getPageContextFromHooks_isHydration(pageContext: PageContextSer
|
|
|
22
22
|
_hasPageContextFromServer: true;
|
|
23
23
|
}>;
|
|
24
24
|
declare function getPageContextFromHooks_isNotHydration(pageContext: {
|
|
25
|
-
|
|
25
|
+
pageId: string;
|
|
26
26
|
} & PageContext & PageContextExports, isErrorPage: boolean): Promise<{
|
|
27
27
|
is404ServerSideRouted: boolean;
|
|
28
28
|
pageContextAugmented?: undefined;
|
|
29
29
|
} | {
|
|
30
30
|
pageContextAugmented: {
|
|
31
|
-
|
|
31
|
+
pageId: string;
|
|
32
32
|
} & PageContext & PageContextExports & {
|
|
33
33
|
isHydration: false;
|
|
34
34
|
_hasPageContextFromClient: boolean;
|