vike 0.4.232 → 0.4.233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/prerender/runPrerender.js +9 -4
- package/dist/cjs/node/runtime/renderPage/{executeOnBeforeRenderAndDataHooks.js → execHookDataAndOnBeforeRender.js} +2 -2
- package/dist/cjs/node/runtime/renderPage/{executeOnRenderHtmlHook.js → execHookOnRenderHtml.js} +3 -3
- package/dist/cjs/node/runtime/renderPage/execHookServer.js +1 -4
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +18 -13
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -11
- package/dist/cjs/node/runtime/renderPage.js +55 -48
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -2
- package/dist/cjs/shared/createPageContextShared.js +1 -3
- package/dist/cjs/shared/hooks/execHook.js +31 -54
- package/dist/cjs/shared/route/{executeGuardHook.js → execHookGuard.js} +3 -3
- package/dist/cjs/shared/route/{executeOnBeforeRouteHook.js → execHookOnBeforeRoute.js} +4 -4
- package/dist/cjs/shared/route/index.js +3 -2
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/styleFileRE.js +1 -0
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +9 -9
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +97 -62
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +11 -4
- package/dist/esm/client/runtime-server-routing/entry.js +2 -2
- package/dist/esm/client/shared/{executeOnRenderClientHook.d.ts → execHookOnRenderClient.d.ts} +2 -2
- package/dist/esm/client/shared/{executeOnRenderClientHook.js → execHookOnRenderClient.js} +4 -4
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +12 -4
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +4 -4
- package/dist/esm/node/prerender/runPrerender.d.ts +250 -4
- package/dist/esm/node/prerender/runPrerender.js +11 -6
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/execHookDataAndOnBeforeRender.d.ts +6 -0
- package/dist/esm/node/runtime/renderPage/{executeOnBeforeRenderAndDataHooks.js → execHookDataAndOnBeforeRender.js} +2 -2
- package/dist/esm/node/runtime/renderPage/{executeOnRenderHtmlHook.d.ts → execHookOnRenderHtml.d.ts} +2 -2
- package/dist/esm/node/runtime/renderPage/{executeOnRenderHtmlHook.js → execHookOnRenderHtml.js} +4 -4
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/execHookServer.js +1 -4
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +15 -6
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +18 -13
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +13 -13
- package/dist/esm/node/runtime/renderPage.js +57 -50
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -2
- package/dist/esm/shared/createPageContextShared.js +1 -3
- package/dist/esm/shared/hooks/execHook.d.ts +14 -28
- package/dist/esm/shared/hooks/execHook.js +31 -54
- package/dist/esm/shared/route/execHookGuard.d.ts +8 -0
- package/dist/esm/shared/route/{executeGuardHook.js → execHookGuard.js} +4 -4
- package/dist/esm/shared/route/{executeOnBeforeRouteHook.d.ts → execHookOnBeforeRoute.d.ts} +2 -2
- package/dist/esm/shared/route/{executeOnBeforeRouteHook.js → execHookOnBeforeRoute.js} +5 -5
- package/dist/esm/shared/route/index.js +3 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/styleFileRE.js +1 -0
- package/package.json +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +0 -6
- package/dist/esm/shared/route/executeGuardHook.d.ts +0 -8
|
@@ -67,6 +67,7 @@ const getOutDirs_js_1 = require("../vite/shared/getOutDirs.js");
|
|
|
67
67
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
68
68
|
const getProxyForPublicUsage_js_1 = require("../../shared/getProxyForPublicUsage.js");
|
|
69
69
|
const resolveRedirects_js_1 = require("../runtime/renderPage/resolveRedirects.js");
|
|
70
|
+
const utils_js_2 = require("../runtime/utils.js");
|
|
70
71
|
const docLink = 'https://vike.dev/i18n#pre-rendering';
|
|
71
72
|
async function runPrerender(options = {}, trigger) {
|
|
72
73
|
(0, context_js_1.setWasPrerenderRun)(trigger);
|
|
@@ -253,7 +254,7 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, globalContext,
|
|
|
253
254
|
if (doNotPrerenderList.find((p) => p.pageId === pageId))
|
|
254
255
|
return;
|
|
255
256
|
const { hookName, hookFilePath } = hook;
|
|
256
|
-
const prerenderResult = await (0, execHook_js_1.
|
|
257
|
+
const prerenderResult = await (0, execHook_js_1.execHookDirectWithoutPageContext)(() => hook.hookFn(), hook);
|
|
257
258
|
const result = normalizeOnPrerenderHookResult(prerenderResult, hookFilePath, hookName);
|
|
258
259
|
// Handle result
|
|
259
260
|
await Promise.all(result.map(async ({ url, pageContext }) => {
|
|
@@ -360,7 +361,7 @@ async function createPageContextPrerendering(urlOriginal, prerenderContext, glob
|
|
|
360
361
|
routeParams: {},
|
|
361
362
|
});
|
|
362
363
|
}
|
|
363
|
-
(0,
|
|
364
|
+
(0, utils_js_2.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSideAndExecHook)(pageContext));
|
|
364
365
|
let usesClientRouter;
|
|
365
366
|
{
|
|
366
367
|
const { pageId } = pageContext;
|
|
@@ -481,7 +482,7 @@ async function callOnPrerenderStartHook(prerenderContext, globalContext, concurr
|
|
|
481
482
|
(0, utils_js_1.preservePropertyGetters)(pageContext);
|
|
482
483
|
});
|
|
483
484
|
const prerenderContextPublic = preparePrerenderContextForPublicUsage(prerenderContext);
|
|
484
|
-
let result = await (0, execHook_js_1.
|
|
485
|
+
let result = await (0, execHook_js_1.execHookDirectWithoutPageContext)(() => hookFn(prerenderContextPublic), onPrerenderStartHook);
|
|
485
486
|
// Before applying result
|
|
486
487
|
prerenderContext.pageContexts.forEach((pageContext) => {
|
|
487
488
|
;
|
|
@@ -763,9 +764,13 @@ function getRedirectHtml(urlTarget) {
|
|
|
763
764
|
<meta charset="UTF-8">
|
|
764
765
|
<meta http-equiv="refresh" content="0;url=${urlTargetSafe}">
|
|
765
766
|
<title>Redirect ${urlTargetSafe}</title>
|
|
767
|
+
<style>body{opacity:0}</style>
|
|
768
|
+
<noscript>
|
|
769
|
+
<style>body{opacity:1}</style>
|
|
770
|
+
</noscript>
|
|
766
771
|
</head>
|
|
767
772
|
<body style="min-height: 100vh; margin: 0; font-family: sans-serif; display: flex; justify-content: center; align-items: center; transition: opacity 0.3s;">
|
|
768
|
-
<script>
|
|
773
|
+
<script>setTimeout(()=>{document.body.style.opacity=1},2000)</script>
|
|
769
774
|
<div>
|
|
770
775
|
<h1>Redirect <a href="${urlTargetSafe}"><code style="background-color: #eaeaea; padding: 3px 5px; border-radius: 4px;">${urlTargetSafe}</code></a></h1>
|
|
771
776
|
<p>If you aren't redirected, click the link above.</p>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.execHookDataAndOnBeforeRender = execHookDataAndOnBeforeRender;
|
|
4
4
|
const assertOnBeforeRenderHookReturn_js_1 = require("../../../shared/assertOnBeforeRenderHookReturn.js");
|
|
5
5
|
const execHookServer_js_1 = require("./execHookServer.js");
|
|
6
|
-
async function
|
|
6
|
+
async function execHookDataAndOnBeforeRender(pageContext) {
|
|
7
7
|
if (pageContext._pageContextAlreadyProvidedByOnPrerenderHook) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
package/dist/cjs/node/runtime/renderPage/{executeOnRenderHtmlHook.js → execHookOnRenderHtml.js}
RENAMED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.execHookOnRenderHtml = execHookOnRenderHtml;
|
|
7
7
|
const renderHtml_js_1 = require("../html/renderHtml.js");
|
|
8
8
|
const getHook_js_1 = require("../../../shared/hooks/getHook.js");
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
@@ -14,10 +14,10 @@ const assertHookReturnedObject_js_1 = require("../../../shared/assertHookReturne
|
|
|
14
14
|
const loggerRuntime_js_1 = require("../loggerRuntime.js");
|
|
15
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
16
|
const execHook_js_1 = require("../../../shared/hooks/execHook.js");
|
|
17
|
-
async function
|
|
17
|
+
async function execHookOnRenderHtml(pageContext) {
|
|
18
18
|
const hook = getRenderHook(pageContext);
|
|
19
19
|
(0, utils_js_1.objectAssign)(pageContext, { _renderHook: hook });
|
|
20
|
-
const { hookReturn } = await (0, execHook_js_1.
|
|
20
|
+
const { hookReturn } = await (0, execHook_js_1.execHookDirectSingleWithReturn)(hook, pageContext, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer);
|
|
21
21
|
const { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter } = processHookReturnValue(hookReturn, hook);
|
|
22
22
|
Object.assign(pageContext, pageContextProvidedByRenderHook);
|
|
23
23
|
(0, utils_js_1.objectAssign)(pageContext, { _pageContextPromise: pageContextPromise });
|
|
@@ -4,8 +4,5 @@ exports.execHookServer = execHookServer;
|
|
|
4
4
|
const execHook_js_1 = require("../../../shared/hooks/execHook.js");
|
|
5
5
|
const preparePageContextForPublicUsageServer_js_1 = require("./preparePageContextForPublicUsageServer.js");
|
|
6
6
|
async function execHookServer(hookName, pageContext) {
|
|
7
|
-
return await (0, execHook_js_1.execHook)(hookName, pageContext,
|
|
8
|
-
(0, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer)(p);
|
|
9
|
-
return p;
|
|
10
|
-
});
|
|
7
|
+
return await (0, execHook_js_1.execHook)(hookName, pageContext, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer);
|
|
11
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.loadPageConfigsLazyServerSideAndExecHook = loadPageConfigsLazyServerSideAndExecHook;
|
|
4
4
|
const getPageFiles_js_1 = require("../../../shared/getPageFiles.js");
|
|
5
5
|
const resolveVikeConfigPublic_js_1 = require("../../../shared/page-configs/resolveVikeConfigPublic.js");
|
|
6
6
|
const analyzePageClientSide_js_1 = require("../../../shared/getPageFiles/analyzePageClientSide.js");
|
|
@@ -10,6 +10,13 @@ const debugPageFiles_js_1 = require("./debugPageFiles.js");
|
|
|
10
10
|
const findPageConfig_js_1 = require("../../../shared/page-configs/findPageConfig.js");
|
|
11
11
|
const analyzePage_js_1 = require("./analyzePage.js");
|
|
12
12
|
const loadConfigValues_js_1 = require("../../../shared/page-configs/loadConfigValues.js");
|
|
13
|
+
const execHookServer_js_1 = require("./execHookServer.js");
|
|
14
|
+
async function loadPageConfigsLazyServerSideAndExecHook(pageContext) {
|
|
15
|
+
const pageContextAddendum = await loadPageConfigsLazyServerSide(pageContext);
|
|
16
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextAddendum);
|
|
17
|
+
await (0, execHookServer_js_1.execHookServer)('onCreatePageContext', pageContext);
|
|
18
|
+
return pageContext;
|
|
19
|
+
}
|
|
13
20
|
async function loadPageConfigsLazyServerSide(pageContext) {
|
|
14
21
|
const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._globalContext._pageConfigs, pageContext.pageId); // Make pageConfig globally available as pageContext._pageConfig ?
|
|
15
22
|
const globalContext = pageContext._globalContext;
|
|
@@ -86,18 +93,16 @@ async function loadPageConfigsLazyServerSide(pageContext) {
|
|
|
86
93
|
return pageAssetsOldFormat;
|
|
87
94
|
},
|
|
88
95
|
});
|
|
89
|
-
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
}
|
|
96
|
+
(0, debugPageFiles_js_1.debugPageFiles)({
|
|
97
|
+
pageContext,
|
|
98
|
+
isHtmlOnly,
|
|
99
|
+
isClientRouting,
|
|
100
|
+
pageFilesLoaded,
|
|
101
|
+
pageFilesClientSide,
|
|
102
|
+
pageFilesServerSide,
|
|
103
|
+
clientEntries,
|
|
104
|
+
clientDependencies,
|
|
105
|
+
});
|
|
101
106
|
return pageContextAddendum;
|
|
102
107
|
}
|
|
103
108
|
async function loadPageUserFiles(pageFilesAll, pageConfig, pageConfigGlobal, pageId, isDev) {
|
|
@@ -11,12 +11,12 @@ const utils_js_1 = require("../utils.js");
|
|
|
11
11
|
const serializeContext_js_1 = require("../html/serializeContext.js");
|
|
12
12
|
const createHttpResponse_js_1 = require("./createHttpResponse.js");
|
|
13
13
|
const loadPageConfigsLazyServerSide_js_1 = require("./loadPageConfigsLazyServerSide.js");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const execHookOnRenderHtml_js_1 = require("./execHookOnRenderHtml.js");
|
|
15
|
+
const execHookDataAndOnBeforeRender_js_1 = require("./execHookDataAndOnBeforeRender.js");
|
|
16
16
|
const loggerRuntime_js_1 = require("../loggerRuntime.js");
|
|
17
17
|
const isNewError_js_1 = require("./isNewError.js");
|
|
18
18
|
const preparePageContextForPublicUsageServer_js_1 = require("./preparePageContextForPublicUsageServer.js");
|
|
19
|
-
const
|
|
19
|
+
const execHookGuard_js_1 = require("../../../shared/route/execHookGuard.js");
|
|
20
20
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
21
21
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
22
22
|
async function renderPageAlreadyRouted(pageContext) {
|
|
@@ -28,16 +28,16 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
28
28
|
(0, utils_js_1.assert)(isError ===
|
|
29
29
|
(pageContext.pageId ===
|
|
30
30
|
(0, error_page_js_1.getErrorPageId)(pageContext._globalContext._pageFilesAll, pageContext._globalContext._pageConfigs)));
|
|
31
|
-
(0, utils_js_1.
|
|
31
|
+
(0, utils_js_1.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSideAndExecHook)(pageContext));
|
|
32
32
|
if (!isError) {
|
|
33
|
-
await (0,
|
|
33
|
+
await (0, execHookGuard_js_1.execHookGuard)(pageContext, (pageContext) => (0, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer)(pageContext));
|
|
34
34
|
}
|
|
35
35
|
if (!isError) {
|
|
36
|
-
await (0,
|
|
36
|
+
await (0, execHookDataAndOnBeforeRender_js_1.execHookDataAndOnBeforeRender)(pageContext);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
try {
|
|
40
|
-
await (0,
|
|
40
|
+
await (0, execHookDataAndOnBeforeRender_js_1.execHookDataAndOnBeforeRender)(pageContext);
|
|
41
41
|
}
|
|
42
42
|
catch (err) {
|
|
43
43
|
if ((0, isNewError_js_1.isNewError)(err, pageContext.errorWhileRendering)) {
|
|
@@ -54,7 +54,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
54
54
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
55
55
|
return pageContext;
|
|
56
56
|
}
|
|
57
|
-
const renderHookResult = await (0,
|
|
57
|
+
const renderHookResult = await (0, execHookOnRenderHtml_js_1.execHookOnRenderHtml)(pageContext);
|
|
58
58
|
const { htmlRender, renderHook } = renderHookResult;
|
|
59
59
|
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePage)(htmlRender, renderHook, pageContext);
|
|
60
60
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
@@ -67,10 +67,10 @@ async function prerenderPage(pageContext) {
|
|
|
67
67
|
});
|
|
68
68
|
/* Should we execute the guard() hook upon pre-rendering? Is there a use case for this?
|
|
69
69
|
* - It isn't trivial to implement, as it requires to duplicate / factor out the isAbortError() handling
|
|
70
|
-
await
|
|
70
|
+
await execHookGuard(pageContext, (pageContext) => preparePageContextForPublicUsageServer(pageContext))
|
|
71
71
|
*/
|
|
72
|
-
await (0,
|
|
73
|
-
const { htmlRender, renderHook } = await (0,
|
|
72
|
+
await (0, execHookDataAndOnBeforeRender_js_1.execHookDataAndOnBeforeRender)(pageContext);
|
|
73
|
+
const { htmlRender, renderHook } = await (0, execHookOnRenderHtml_js_1.execHookOnRenderHtml)(pageContext);
|
|
74
74
|
(0, utils_js_1.assertUsage)(htmlRender !== null, `Cannot pre-render ${picocolors_1.default.cyan(pageContext.urlOriginal)} because the ${renderHook.hookName}() hook defined by ${renderHook.hookFilePath} didn't return an HTML string.`);
|
|
75
75
|
(0, utils_js_1.assert)(pageContext.isClientSideNavigation === false);
|
|
76
76
|
const documentHtml = await (0, renderHtml_js_1.getHtmlString)(htmlRender);
|
|
@@ -143,59 +143,66 @@ async function renderPageAlreadyPrepared(pageContextBegin, globalContext, httpRe
|
|
|
143
143
|
else {
|
|
144
144
|
(0, utils_js_1.assert)(errNominalPage);
|
|
145
145
|
(0, utils_js_1.assert)(pageContextNominalPageSuccess === undefined);
|
|
146
|
-
(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
return await renderPageOnError(errNominalPage, pageContextBegin, pageContextNominalPageBegin, globalContext, httpRequestId, pageContextsFromRewrite);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// When the normal page threw an error
|
|
150
|
+
// - Can be a URL rewrite upon `throw render('/some-url')`
|
|
151
|
+
// - Can be rendering the error page
|
|
152
|
+
// - Can be rendering Vike's generic error page (if no error page is defined, or if the error page throws an error)
|
|
153
|
+
async function renderPageOnError(errNominalPage, pageContextBegin, pageContextNominalPageBegin, globalContext, httpRequestId, pageContextsFromRewrite) {
|
|
154
|
+
(0, utils_js_1.assert)(pageContextNominalPageBegin);
|
|
155
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextNominalPageBegin, 'urlOriginal', 'string'));
|
|
156
|
+
const pageContextErrorPageInit = await getPageContextErrorPageInit(pageContextBegin, errNominalPage, pageContextNominalPageBegin);
|
|
157
|
+
// Handle `throw redirect()` and `throw render()` while rendering nominal page
|
|
158
|
+
if ((0, abort_js_1.isAbortError)(errNominalPage)) {
|
|
159
|
+
const handled = await handleAbortError(errNominalPage, pageContextsFromRewrite, pageContextBegin, pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalContext);
|
|
160
|
+
if (handled.pageContextReturn) {
|
|
161
|
+
// - throw redirect()
|
|
162
|
+
// - throw render(url)
|
|
163
|
+
// - throw render(abortStatusCode) if .pageContext.json request
|
|
164
|
+
return handled.pageContextReturn;
|
|
162
165
|
}
|
|
163
|
-
{
|
|
164
|
-
|
|
165
|
-
if (!errorPageId) {
|
|
166
|
-
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: null });
|
|
167
|
-
return (0, handleErrorWithoutErrorPage_js_1.handleErrorWithoutErrorPage)(pageContextErrorPageInit);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: errorPageId });
|
|
171
|
-
}
|
|
166
|
+
else {
|
|
167
|
+
// - throw render(abortStatusCode) if not .pageContext.json request
|
|
172
168
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
169
|
+
Object.assign(pageContextErrorPageInit, handled.pageContextAbort);
|
|
170
|
+
}
|
|
171
|
+
{
|
|
172
|
+
const errorPageId = (0, error_page_js_1.getErrorPageId)(globalContext._pageFilesAll, globalContext._pageConfigs);
|
|
173
|
+
if (!errorPageId) {
|
|
174
|
+
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: null });
|
|
175
|
+
return (0, handleErrorWithoutErrorPage_js_1.handleErrorWithoutErrorPage)(pageContextErrorPageInit);
|
|
176
176
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
(0,
|
|
177
|
+
else {
|
|
178
|
+
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: errorPageId });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
let pageContextErrorPage;
|
|
182
|
+
try {
|
|
183
|
+
pageContextErrorPage = await (0, renderPageAlreadyRouted_js_1.renderPageAlreadyRouted)(pageContextErrorPageInit);
|
|
184
|
+
}
|
|
185
|
+
catch (errErrorPage) {
|
|
186
|
+
// Handle `throw redirect()` and `throw render()` while rendering error page
|
|
187
|
+
if ((0, abort_js_1.isAbortError)(errErrorPage)) {
|
|
188
|
+
const handled = await handleAbortError(errErrorPage, pageContextsFromRewrite, pageContextBegin, pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalContext);
|
|
189
|
+
// throw render(abortStatusCode)
|
|
190
|
+
if (!handled.pageContextReturn) {
|
|
191
|
+
const pageContextAbort = errErrorPage._pageContextAbort;
|
|
192
|
+
(0, utils_js_1.assertWarning)(false, `Failed to render error page because ${picocolors_1.default.cyan(pageContextAbort._abortCall)} was called: make sure ${picocolors_1.default.cyan(pageContextAbort._abortCaller)} doesn't occur while the error page is being rendered.`, { onlyOnce: false });
|
|
193
|
+
const pageContextHttpWithError = getPageContextHttpResponseError(errNominalPage, pageContextBegin);
|
|
194
|
+
return pageContextHttpWithError;
|
|
193
195
|
}
|
|
194
|
-
|
|
195
|
-
return
|
|
196
|
+
// `throw redirect()` / `throw render(url)`
|
|
197
|
+
return handled.pageContextReturn;
|
|
196
198
|
}
|
|
197
|
-
|
|
199
|
+
if ((0, isNewError_js_1.isNewError)(errErrorPage, errNominalPage)) {
|
|
200
|
+
(0, loggerRuntime_js_1.logRuntimeError)(errErrorPage, httpRequestId);
|
|
201
|
+
}
|
|
202
|
+
const pageContextWithError = getPageContextHttpResponseError(errNominalPage, pageContextBegin);
|
|
203
|
+
return pageContextWithError;
|
|
198
204
|
}
|
|
205
|
+
return pageContextErrorPage;
|
|
199
206
|
}
|
|
200
207
|
function logHttpRequest(urlOriginal, httpRequestId) {
|
|
201
208
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info');
|
|
@@ -417,7 +424,7 @@ pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalCont
|
|
|
417
424
|
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
418
425
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
419
426
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit, true);
|
|
420
|
-
(0, utils_js_1.
|
|
427
|
+
(0, utils_js_1.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSideAndExecHook)(pageContext));
|
|
421
428
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
422
429
|
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
423
430
|
}
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPageContextShared = createPageContextShared;
|
|
4
4
|
exports.createPageContextObject = createPageContextObject;
|
|
5
|
-
const execHook_js_1 = require("./hooks/execHook.js");
|
|
6
|
-
const preparePageContextForPublicUsage_js_1 = require("./preparePageContextForPublicUsage.js");
|
|
7
5
|
const utils_js_1 = require("./utils.js");
|
|
6
|
+
// TODO/now: make this and parents sync
|
|
8
7
|
async function createPageContextShared(pageContextCreated, pageConfigGlobal, vikeConfigPublicGlobal) {
|
|
9
8
|
(0, utils_js_1.objectAssign)(pageContextCreated, vikeConfigPublicGlobal);
|
|
10
|
-
await (0, execHook_js_1.execHookGlobal)('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
11
9
|
return pageContextCreated;
|
|
12
10
|
}
|
|
13
11
|
function createPageContextObject() {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.execHook = execHook;
|
|
4
|
-
exports.execHookSingle = execHookSingle;
|
|
5
|
-
exports.execHookSingleWithReturn = execHookSingleWithReturn;
|
|
6
|
-
exports.execHookErrorHandling = execHookErrorHandling;
|
|
7
|
-
exports.execHooksErrorHandling = execHooksErrorHandling;
|
|
8
|
-
exports.execHookWithoutPageContext = execHookWithoutPageContext;
|
|
9
4
|
exports.execHookGlobal = execHookGlobal;
|
|
10
|
-
exports.
|
|
5
|
+
exports.execHookDirect = execHookDirect;
|
|
6
|
+
exports.execHookDirectSingle = execHookDirectSingle;
|
|
7
|
+
exports.execHookDirectSingleWithReturn = execHookDirectSingleWithReturn;
|
|
8
|
+
exports.execHookDirectWithoutPageContext = execHookDirectWithoutPageContext;
|
|
9
|
+
exports.execHookDirectSync = execHookDirectSync;
|
|
11
10
|
exports.getPageContext = getPageContext;
|
|
12
11
|
exports.providePageContext = providePageContext;
|
|
13
12
|
exports.isUserHookError = isUserHookError;
|
|
@@ -21,70 +20,48 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/execHook.t
|
|
|
21
20
|
userHookErrors: new WeakMap(),
|
|
22
21
|
pageContext: null,
|
|
23
22
|
});
|
|
24
|
-
async function execHookSingle(hook, pageContext, preparePageContextForPublicUsage) {
|
|
25
|
-
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
26
|
-
if ('err' in res)
|
|
27
|
-
throw res.err;
|
|
28
|
-
const { hookReturn } = res.hooks[0];
|
|
29
|
-
(0, assert_js_1.assertUsage)(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
30
|
-
}
|
|
31
|
-
async function execHookSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
|
|
32
|
-
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
33
|
-
if ('err' in res)
|
|
34
|
-
throw res.err;
|
|
35
|
-
const { hookReturn } = res.hooks[0];
|
|
36
|
-
return { hookReturn };
|
|
37
|
-
}
|
|
38
23
|
async function execHook(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
39
|
-
const res = await execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage);
|
|
40
|
-
if ('err' in res)
|
|
41
|
-
throw res.err;
|
|
42
|
-
return res.hooks;
|
|
43
|
-
}
|
|
44
|
-
async function execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
45
24
|
const hooks = (0, getHook_js_1.getHookFromPageContextNew)(hookName, pageContext);
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
async function execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage) {
|
|
49
|
-
if (!hooks.length)
|
|
50
|
-
return { hooks: [] };
|
|
51
|
-
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
52
|
-
let hooksWithResult;
|
|
53
|
-
let err;
|
|
54
|
-
try {
|
|
55
|
-
hooksWithResult = await Promise.all(hooks.map(async (hook) => {
|
|
56
|
-
const hookReturn = await execHookAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
|
|
57
|
-
return { ...hook, hookReturn };
|
|
58
|
-
}));
|
|
59
|
-
}
|
|
60
|
-
catch (err_) {
|
|
61
|
-
err = err_;
|
|
62
|
-
}
|
|
63
|
-
if (hooksWithResult) {
|
|
64
|
-
return { hooks: hooksWithResult };
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
return { hooks, err };
|
|
68
|
-
}
|
|
25
|
+
return await execHookDirect(hooks, pageContext, preparePageContextForPublicUsage);
|
|
69
26
|
}
|
|
70
27
|
async function execHookGlobal(hookName, pageConfigGlobal, pageContext, hookArg, prepareForPublicUsage) {
|
|
71
28
|
const hooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(pageConfigGlobal, hookName);
|
|
72
29
|
const hookArgForPublicUsage = prepareForPublicUsage(hookArg);
|
|
73
30
|
await Promise.all(hooks.map(async (hook) => {
|
|
74
|
-
await
|
|
31
|
+
await execHookDirectAsync(() => hook.hookFn(hookArgForPublicUsage), hook, pageContext);
|
|
75
32
|
}));
|
|
76
33
|
}
|
|
34
|
+
async function execHookDirect(hooks, pageContext, preparePageContextForPublicUsage) {
|
|
35
|
+
if (!hooks.length)
|
|
36
|
+
return [];
|
|
37
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
38
|
+
const hooksWithResult = await Promise.all(hooks.map(async (hook) => {
|
|
39
|
+
const hookReturn = await execHookDirectAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
|
|
40
|
+
return { ...hook, hookReturn };
|
|
41
|
+
}));
|
|
42
|
+
return hooksWithResult;
|
|
43
|
+
}
|
|
44
|
+
async function execHookDirectSingle(hook, pageContext, preparePageContextForPublicUsage) {
|
|
45
|
+
const hooksWithResult = await execHookDirect([hook], pageContext, preparePageContextForPublicUsage);
|
|
46
|
+
const { hookReturn } = hooksWithResult[0];
|
|
47
|
+
(0, assert_js_1.assertUsage)(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
48
|
+
}
|
|
49
|
+
async function execHookDirectSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
|
|
50
|
+
const hooksWithResult = await execHookDirect([hook], pageContext, preparePageContextForPublicUsage);
|
|
51
|
+
const { hookReturn } = hooksWithResult[0];
|
|
52
|
+
return { hookReturn };
|
|
53
|
+
}
|
|
77
54
|
function isUserHookError(err) {
|
|
78
55
|
if (!(0, isObject_js_1.isObject)(err))
|
|
79
56
|
return false;
|
|
80
57
|
return globalObject.userHookErrors.get(err) ?? false;
|
|
81
58
|
}
|
|
82
|
-
async function
|
|
59
|
+
async function execHookDirectWithoutPageContext(hookFnCaller, hook) {
|
|
83
60
|
const { hookName, hookFilePath, hookTimeout } = hook;
|
|
84
|
-
const hookReturn = await
|
|
61
|
+
const hookReturn = await execHookDirectAsync(hookFnCaller, { hookName, hookFilePath, hookTimeout }, null);
|
|
85
62
|
return hookReturn;
|
|
86
63
|
}
|
|
87
|
-
function
|
|
64
|
+
function execHookDirectAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
88
65
|
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn }, } = hook;
|
|
89
66
|
let resolve;
|
|
90
67
|
let reject;
|
|
@@ -128,7 +105,7 @@ function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
|
128
105
|
})();
|
|
129
106
|
return promise;
|
|
130
107
|
}
|
|
131
|
-
function
|
|
108
|
+
function execHookDirectSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
132
109
|
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
133
110
|
providePageContextInternal(pageContextForPublicUsage);
|
|
134
111
|
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.execHookGuard = execHookGuard;
|
|
4
4
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const execHook_js_1 = require("../hooks/execHook.js");
|
|
7
7
|
const errIntro = 'The guard() hook defined by';
|
|
8
|
-
async function
|
|
8
|
+
async function execHookGuard(pageContext, prepareForPublicUsage) {
|
|
9
9
|
let hook;
|
|
10
10
|
if (pageContext._globalContext._pageFilesAll.length > 0) {
|
|
11
11
|
// TODO/v1-release: remove
|
|
@@ -19,7 +19,7 @@ async function executeGuardHook(pageContext, prepareForPublicUsage) {
|
|
|
19
19
|
}
|
|
20
20
|
if (!hook)
|
|
21
21
|
return;
|
|
22
|
-
await (0, execHook_js_1.
|
|
22
|
+
await (0, execHook_js_1.execHookDirectSingle)(hook, pageContext, prepareForPublicUsage);
|
|
23
23
|
}
|
|
24
24
|
function findPageGuard(pageId, pageFilesAll) {
|
|
25
25
|
const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
|
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.execHookOnBeforeRoute = execHookOnBeforeRoute;
|
|
7
7
|
const assertPageContextProvidedByUser_js_1 = require("../assertPageContextProvidedByUser.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
11
|
const execHook_js_1 = require("../hooks/execHook.js");
|
|
12
12
|
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
13
|
-
async function
|
|
13
|
+
async function execHookOnBeforeRoute(pageContext) {
|
|
14
14
|
const pageContextFromOnBeforeRouteHook = {};
|
|
15
15
|
if (!pageContext._globalContext._onBeforeRouteHook)
|
|
16
16
|
return null;
|
|
@@ -39,9 +39,9 @@ async function executeOnBeforeRouteHook(pageContext) {
|
|
|
39
39
|
return pageContextFromOnBeforeRouteHook;
|
|
40
40
|
}
|
|
41
41
|
async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
42
|
-
let { hookReturn } = (0, execHook_js_1.
|
|
42
|
+
let { hookReturn } = (0, execHook_js_1.execHookDirectSync)(onBeforeRouteHook, pageContext, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
43
43
|
(0, resolveRouteFunction_js_1.assertSyncRouting)(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
44
|
-
// TODO/v1-release: make
|
|
44
|
+
// TODO/v1-release: make execHookOnBeforeRoute() and route() sync
|
|
45
45
|
hookReturn = await hookReturn;
|
|
46
46
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
47
47
|
(0, utils_js_1.assertUsage)(hookReturn === null ||
|
|
@@ -14,15 +14,16 @@ const utils_js_1 = require("./utils.js");
|
|
|
14
14
|
const resolvePrecedence_js_1 = require("./resolvePrecedence.js");
|
|
15
15
|
const resolveRouteString_js_1 = require("./resolveRouteString.js");
|
|
16
16
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
17
|
-
const
|
|
17
|
+
const execHookOnBeforeRoute_js_1 = require("./execHookOnBeforeRoute.js");
|
|
18
18
|
const debug_js_1 = require("./debug.js");
|
|
19
19
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
20
|
+
// TODO/next-major-release: make it sync
|
|
20
21
|
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
21
22
|
(0, debug_js_1.debug)('Pages routes:', pageContext._globalContext._pageRoutes);
|
|
22
23
|
const pageContextFromRoute = {};
|
|
23
24
|
// onBeforeRoute()
|
|
24
25
|
if (!skipOnBeforeRouteHook) {
|
|
25
|
-
const pageContextFromOnBeforeRouteHook = await (0,
|
|
26
|
+
const pageContextFromOnBeforeRouteHook = await (0, execHookOnBeforeRoute_js_1.execHookOnBeforeRoute)(pageContext);
|
|
26
27
|
if (pageContextFromOnBeforeRouteHook) {
|
|
27
28
|
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
28
29
|
(0, utils_js_1.assert)(pageContextFromOnBeforeRouteHook.pageId);
|
|
@@ -12,7 +12,7 @@ const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForP
|
|
|
12
12
|
const utils_js_1 = require("./utils.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
async function resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath) {
|
|
15
|
-
let { hookReturn: result } = (0, execHook_js_1.
|
|
15
|
+
let { hookReturn: result } = (0, execHook_js_1.execHookDirectSync)({
|
|
16
16
|
hookFn: routeFunction,
|
|
17
17
|
hookFilePath: routeFunctionFilePath,
|
|
18
18
|
hookName: 'route',
|
|
@@ -2,4 +2,5 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.styleFileRE = void 0;
|
|
4
4
|
// Copied from https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/css.ts#L90-L91
|
|
5
|
+
// spellcheck-ignore
|
|
5
6
|
exports.styleFileRE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\?)/;
|
|
@@ -421,8 +421,8 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
421
421
|
} & {
|
|
422
422
|
urlOriginal: string;
|
|
423
423
|
}>;
|
|
424
|
-
type
|
|
425
|
-
declare function execHookClient(hookName: HookName, pageContext:
|
|
424
|
+
type PageContextExecHookClient = VikeConfigPublicPageLazy & PageContextForPublicUsageClient;
|
|
425
|
+
declare function execHookClient(hookName: HookName, pageContext: PageContextExecHookClient): Promise<(import("../../shared/hooks/getHook.js").HookLoc & {
|
|
426
426
|
hookFn: (arg: import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum | import("../../shared/prepareGlobalContextForPublicUsage.js").GlobalContextPrepareMinimum) => unknown;
|
|
427
427
|
hookTimeout: import("../../shared/hooks/getHook.js").HookTimeout;
|
|
428
428
|
} & {
|