UNPKG

vike

Version:

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

47 lines (46 loc) 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.preparePageContextForUserConsumptionClientSide = preparePageContextForUserConsumptionClientSide; const utils_js_1 = require("../server-routing-runtime/utils.js"); const getPageContextProxyForUser_js_1 = require("./getPageContextProxyForUser.js"); const preparePageContextForUserConsumption_js_1 = require("../../shared/preparePageContextForUserConsumption.js"); function preparePageContextForUserConsumptionClientSide(pageContext, isClientRouting) { if (isClientRouting) { const pageContextTyped = pageContext; (0, utils_js_1.assert)([true, false].includes(pageContextTyped.isHydration)); (0, utils_js_1.assert)([true, false, null].includes(pageContextTyped.isBackwardNavigation)); } else { const pageContextTyped = pageContext; (0, utils_js_1.assert)(pageContextTyped.isHydration === true); (0, utils_js_1.assert)(pageContextTyped.isBackwardNavigation === null); } const Page = pageContext.config.Page || // TODO/next-major-release: remove pageContext.exports.Page; (0, utils_js_1.objectAssign)(pageContext, { Page }); // TODO/next-major-release: remove // - Requires https://github.com/vikejs/vike-vue/issues/198 // - 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. supportVueReactiviy(pageContext); (0, preparePageContextForUserConsumption_js_1.preparePageContextForUserConsumption)(pageContext); const pageContextProxy = (0, getPageContextProxyForUser_js_1.getPageContextProxyForUser)(pageContext); return pageContextProxy; } // With Vue + Cient Routing, the `pageContext` is made reactive: // ```js // import { reactive } from 'vue' // // See /examples/vue-full/renderer/createVueApp.ts // const pageContextReactive = reactive(pageContext) // ``` function supportVueReactiviy(pageContext) { resolveGetters(pageContext); } // Remove propery descriptor getters because they break Vue's reactivity. // E.g. resolve the `pageContext.urlPathname` getter. function resolveGetters(pageContext) { Object.entries(pageContext).forEach(([key, val]) => { delete pageContext[key]; pageContext[key] = val; }); }