import { createSSRApp , defineComponent , h , markRaw , reactive } from 'vue' ; import PageShell from './PageShell.vue' ; import type { Component , PageContext } from './types' ; import { setPageContext } from './usePageContext' ; export { createApp } ; function createApp ( pageContext ) { const { Page } = pageContext ; let rootComponent ; const PageWithWrapper = defineComponent ( { data : ( ) => ( { Page : markRaw ( Page ) , pageProps : markRaw ( pageContext . pageProps || { } ) , } ) , created ( ) { rootComponent = this ; } , render ( ) { return h ( PageShell , { } , { default : ( ) => { return h ( this . Page , this . pageProps ) ; } , } ) ; } , } ) ; const app = createSSRApp ( PageWithWrapper ) ; objectAssign ( app , { changePage : ( pageContext ) => { Object . assign ( pageContextReactive , pageContext ) ; rootComponent . Page = markRaw ( pageContext . Page ) ; rootComponent . pageProps = markRaw ( pageContext . pageProps || { } ) ; } , } ) ; const pageContextReactive = reactive ( pageContext ) ; setPageContext ( app , pageContextReactive ) ; return app ; } function objectAssign < Obj , ObjAddendum > ( obj , objAddendum ) { Object . assign ( obj , objAddendum ) ; }