UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

32 lines (31 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.execHookDataAndOnBeforeRender = execHookDataAndOnBeforeRender; const assertOnBeforeRenderHookReturn_js_1 = require("../../../shared/assertOnBeforeRenderHookReturn.js"); const execHookServer_js_1 = require("./execHookServer.js"); async function execHookDataAndOnBeforeRender(pageContext) { if (pageContext._pageContextAlreadyProvidedByOnPrerenderHook) { return; } const hooks = await (0, execHookServer_js_1.execHookServer)('data', pageContext); const dataHook = hooks[0]; // TO-DO/soon: support cumulative if (dataHook) { // Note: hookReturn can be anything (e.g. an object) and is to be assigned to pageContext.data const pageContextFromHook = { data: dataHook.hookReturn, }; Object.assign(pageContext, pageContextFromHook); // Execute +onData if (!pageContext.isClientSideNavigation) { await (0, execHookServer_js_1.execHookServer)('onData', pageContext); } } const res = await (0, execHookServer_js_1.execHookServer)('onBeforeRender', pageContext); const onBeforeRenderHook = res[0]; // TO-DO/soon: support cumulative if (onBeforeRenderHook) { const { hookReturn } = onBeforeRenderHook; (0, assertOnBeforeRenderHookReturn_js_1.assertOnBeforeRenderHookReturn)(hookReturn, onBeforeRenderHook.hookFilePath); const pageContextFromHook = hookReturn?.pageContext; Object.assign(pageContext, pageContextFromHook); } }