UNPKG

vike

Version:

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

40 lines (39 loc) 1.98 kB
export { preparePageContextForPublicUsageClientShared }; export { preparePageContextForPublicUsageClientMinimal }; import { objectAssign } from '../runtime-server-routing/utils.js'; import { assertPropertyGetters, preparePageContextForPublicUsage, } from '../../shared/preparePageContextForPublicUsage.js'; function preparePageContextForPublicUsageClientShared(pageContext) { // TODO/now-proxy use proxy const Page = pageContext.config?.Page || // TODO/next-major-release: remove pageContext.exports?.Page; objectAssign(pageContext, { Page }); // TODO/next-major-release: after we remove supportVueReactiviy() we can call this later inside the agnostic preparePageContextForPublicUsage() assertPropertyGetters(pageContext); // 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); return preparePageContextForPublicUsageClientMinimal(pageContext); } function preparePageContextForPublicUsageClientMinimal(pageContext) { const pageContextPublic = preparePageContextForPublicUsage(pageContext); return pageContextPublic; } // With Vue + Client 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 property 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; }); }