vike 0.4.232-commit-ec54a7e → 0.4.232-commit-1690f53
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 +3 -3
- 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/loadPageConfigsLazyServerSide.js +4 -4
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -11
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -2
- 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 +2 -2
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- 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/prefetch.js +2 -2
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +88 -65
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +4 -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 +5 -7
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +6 -6
- package/dist/esm/node/prerender/runPrerender.js +5 -5
- 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/getHttpResponseBody.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +6 -6
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +4 -4
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +12 -12
- package/dist/esm/node/runtime/renderPage.js +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -2
- package/dist/esm/shared/hooks/execHook.d.ts +14 -29
- 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 +2 -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/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
|
@@ -254,7 +254,7 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, globalContext,
|
|
|
254
254
|
if (doNotPrerenderList.find((p) => p.pageId === pageId))
|
|
255
255
|
return;
|
|
256
256
|
const { hookName, hookFilePath } = hook;
|
|
257
|
-
const prerenderResult = await (0, execHook_js_1.
|
|
257
|
+
const prerenderResult = await (0, execHook_js_1.execHookDirectWithoutPageContext)(() => hook.hookFn(), hook);
|
|
258
258
|
const result = normalizeOnPrerenderHookResult(prerenderResult, hookFilePath, hookName);
|
|
259
259
|
// Handle result
|
|
260
260
|
await Promise.all(result.map(async ({ url, pageContext }) => {
|
|
@@ -361,7 +361,7 @@ async function createPageContextPrerendering(urlOriginal, prerenderContext, glob
|
|
|
361
361
|
routeParams: {},
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
|
-
(0, utils_js_2.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.
|
|
364
|
+
(0, utils_js_2.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSideAndExecHook)(pageContext));
|
|
365
365
|
let usesClientRouter;
|
|
366
366
|
{
|
|
367
367
|
const { pageId } = pageContext;
|
|
@@ -482,7 +482,7 @@ async function callOnPrerenderStartHook(prerenderContext, globalContext, concurr
|
|
|
482
482
|
(0, utils_js_1.preservePropertyGetters)(pageContext);
|
|
483
483
|
});
|
|
484
484
|
const prerenderContextPublic = preparePrerenderContextForPublicUsage(prerenderContext);
|
|
485
|
-
let result = await (0, execHook_js_1.
|
|
485
|
+
let result = await (0, execHook_js_1.execHookDirectWithoutPageContext)(() => hookFn(prerenderContextPublic), onPrerenderStartHook);
|
|
486
486
|
// Before applying result
|
|
487
487
|
prerenderContext.pageContexts.forEach((pageContext) => {
|
|
488
488
|
;
|
|
@@ -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 });
|
|
@@ -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");
|
|
@@ -11,13 +11,13 @@ const findPageConfig_js_1 = require("../../../shared/page-configs/findPageConfig
|
|
|
11
11
|
const analyzePage_js_1 = require("./analyzePage.js");
|
|
12
12
|
const loadConfigValues_js_1 = require("../../../shared/page-configs/loadConfigValues.js");
|
|
13
13
|
const execHookServer_js_1 = require("./execHookServer.js");
|
|
14
|
-
async function
|
|
15
|
-
const pageContextAddendum = await
|
|
14
|
+
async function loadPageConfigsLazyServerSideAndExecHook(pageContext) {
|
|
15
|
+
const pageContextAddendum = await loadPageConfigsLazyServerSide(pageContext);
|
|
16
16
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAddendum);
|
|
17
17
|
await (0, execHookServer_js_1.execHookServer)('onCreatePageContext', pageContext);
|
|
18
18
|
return pageContext;
|
|
19
19
|
}
|
|
20
|
-
async function
|
|
20
|
+
async function loadPageConfigsLazyServerSide(pageContext) {
|
|
21
21
|
const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._globalContext._pageConfigs, pageContext.pageId); // Make pageConfig globally available as pageContext._pageConfig ?
|
|
22
22
|
const globalContext = pageContext._globalContext;
|
|
23
23
|
const [{ pageFilesLoaded, pageContextExports }] = await Promise.all([
|
|
@@ -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.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_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);
|
|
@@ -424,7 +424,7 @@ pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalCont
|
|
|
424
424
|
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
425
425
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
426
426
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit, true);
|
|
427
|
-
(0, utils_js_1.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.
|
|
427
|
+
(0, utils_js_1.augmentType)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSideAndExecHook)(pageContext));
|
|
428
428
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
429
429
|
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
430
430
|
}
|
|
@@ -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,7 +14,7 @@ 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
20
|
// TODO/next-major-release: make it sync
|
|
@@ -23,7 +23,7 @@ async function route(pageContext, skipOnBeforeRouteHook) {
|
|
|
23
23
|
const pageContextFromRoute = {};
|
|
24
24
|
// onBeforeRoute()
|
|
25
25
|
if (!skipOnBeforeRouteHook) {
|
|
26
|
-
const pageContextFromOnBeforeRouteHook = await (0,
|
|
26
|
+
const pageContextFromOnBeforeRouteHook = await (0, execHookOnBeforeRoute_js_1.execHookOnBeforeRoute)(pageContext);
|
|
27
27
|
if (pageContextFromOnBeforeRouteHook) {
|
|
28
28
|
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
29
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',
|
|
@@ -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
|
} & {
|
|
@@ -13,7 +13,7 @@ import { getPageContextRequestUrl } from '../../shared/getPageContextRequestUrl.
|
|
|
13
13
|
import { getPageConfig } from '../../shared/page-configs/helpers.js';
|
|
14
14
|
import { getConfigValueRuntime } from '../../shared/page-configs/getConfigValueRuntime.js';
|
|
15
15
|
import { assertOnBeforeRenderHookReturn } from '../../shared/assertOnBeforeRenderHookReturn.js';
|
|
16
|
-
import {
|
|
16
|
+
import { execHookGuard } from '../../shared/route/execHookGuard.js';
|
|
17
17
|
import { AbortRender, isAbortPageContext } from '../../shared/route/abort.js';
|
|
18
18
|
import { pageContextInitIsPassedToClient } from '../../shared/misc/pageContextInitIsPassedToClient.js';
|
|
19
19
|
import { isServerSideError } from '../../shared/misc/isServerSideError.js';
|
|
@@ -34,7 +34,7 @@ function getPageContextFromHooks_serialized() {
|
|
|
34
34
|
async function getPageContextFromHooks_isHydration(pageContext) {
|
|
35
35
|
for (const hookName of ['data', 'onBeforeRender']) {
|
|
36
36
|
if (hookClientOnlyExists(hookName, pageContext)) {
|
|
37
|
-
await
|
|
37
|
+
await execHookDataLike(hookName, pageContext);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return pageContext;
|
|
@@ -78,7 +78,7 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
|
78
78
|
!pageContext._hasPageContextFromServer) {
|
|
79
79
|
// Should we really call the guard() hook on the client-side? Shouldn't we make the guard() hook a server-side
|
|
80
80
|
// only hook? Or maybe make its env configurable like data() and onBeforeRender()?
|
|
81
|
-
await
|
|
81
|
+
await execHookGuard(pageContext, (pageContext) => preparePageContextForPublicUsageClient(pageContext));
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
else {
|
|
@@ -86,7 +86,7 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
|
86
86
|
if (hookName === 'data')
|
|
87
87
|
dataHookExec = true;
|
|
88
88
|
// This won't do anything if no hook has been defined or if the hook's env.client is false.
|
|
89
|
-
await
|
|
89
|
+
await execHookDataLike(hookName, pageContext);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -101,17 +101,17 @@ async function getPageContextFromClientHooks(pageContext, isErrorPage) {
|
|
|
101
101
|
async function execHookClient(hookName, pageContext) {
|
|
102
102
|
return await execHook(hookName, pageContext, (p) => preparePageContextForPublicUsageClient(p));
|
|
103
103
|
}
|
|
104
|
-
async function
|
|
104
|
+
async function execHookDataLike(hookName, pageContext) {
|
|
105
105
|
let pageContextFromHook;
|
|
106
106
|
if (hookName === 'data') {
|
|
107
|
-
pageContextFromHook = await
|
|
107
|
+
pageContextFromHook = await execHookData(pageContext);
|
|
108
108
|
}
|
|
109
109
|
else {
|
|
110
|
-
pageContextFromHook = await
|
|
110
|
+
pageContextFromHook = await execHookOnBeforeRender(pageContext);
|
|
111
111
|
}
|
|
112
112
|
Object.assign(pageContext, pageContextFromHook);
|
|
113
113
|
}
|
|
114
|
-
async function
|
|
114
|
+
async function execHookData(pageContext) {
|
|
115
115
|
const res = await execHookClient('data', pageContext);
|
|
116
116
|
const hook = res[0]; // TO-DO/soon: support cumulative
|
|
117
117
|
if (!hook)
|
|
@@ -120,7 +120,7 @@ async function executeDataHook(pageContext) {
|
|
|
120
120
|
const pageContextAddendum = { data: hookReturn };
|
|
121
121
|
return pageContextAddendum;
|
|
122
122
|
}
|
|
123
|
-
async function
|
|
123
|
+
async function execHookOnBeforeRender(pageContext) {
|
|
124
124
|
const res = await execHookClient('onBeforeRender', pageContext);
|
|
125
125
|
const hook = res[0]; // TO-DO/soon: support cumulative
|
|
126
126
|
if (!hook)
|
|
@@ -6,7 +6,7 @@ export { addLinkPrefetchHandlers };
|
|
|
6
6
|
export { addLinkPrefetchHandlers_watch };
|
|
7
7
|
export { addLinkPrefetchHandlers_unwatch };
|
|
8
8
|
import { assert, assertClientRouting, assertUsage, assertWarning, checkIfClientRouting, getGlobalObject, hasProp, objectAssign, } from './utils.js';
|
|
9
|
-
import { isErrorFetchingStaticAssets,
|
|
9
|
+
import { isErrorFetchingStaticAssets, loadPageConfigsLazyClientSide } from '../shared/loadPageConfigsLazyClientSide.js';
|
|
10
10
|
import { skipLink } from './skipLink.js';
|
|
11
11
|
import { disableClientRouting } from './renderPageClientSide.js';
|
|
12
12
|
import { isClientSideRoutable } from './isClientSideRoutable.js';
|
|
@@ -45,7 +45,7 @@ function getPageContextPrefetched(pageContext) {
|
|
|
45
45
|
}
|
|
46
46
|
async function prefetchAssets(pageContextLink) {
|
|
47
47
|
try {
|
|
48
|
-
await
|
|
48
|
+
await loadPageConfigsLazyClientSide(pageContextLink.pageId, pageContextLink._pageFilesAll, pageContextLink._globalContext._pageConfigs, pageContextLink._globalContext._pageConfigGlobal);
|
|
49
49
|
}
|
|
50
50
|
catch (err) {
|
|
51
51
|
if (isErrorFetchingStaticAssets(err)) {
|