create-vike 0.0.341 → 0.0.342
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/boilerplate-react/package.json +1 -1
- package/boilerplate-react/renderer/+onRenderClient.jsx +3 -3
- package/boilerplate-react/renderer/+onRenderHtml.jsx +3 -3
- package/boilerplate-react/renderer/{PageLayout.jsx → Layout.jsx} +8 -8
- package/boilerplate-react-ts/package.json +1 -1
- package/boilerplate-react-ts/renderer/+onRenderClient.tsx +3 -3
- package/boilerplate-react-ts/renderer/+onRenderHtml.tsx +3 -3
- package/boilerplate-react-ts/renderer/{PageLayout.tsx → Layout.tsx} +6 -6
- package/boilerplate-vue/package.json +1 -1
- package/boilerplate-vue/pages/_error/+Page.vue +1 -1
- package/boilerplate-vue/renderer/+onRenderClient.js +2 -2
- package/boilerplate-vue/renderer/+onRenderHtml.js +2 -2
- package/boilerplate-vue/renderer/Link.vue +1 -1
- package/boilerplate-vue/renderer/createVueApp.js +28 -0
- package/boilerplate-vue-ts/package.json +1 -1
- package/boilerplate-vue-ts/pages/_error/+Page.vue +1 -1
- package/boilerplate-vue-ts/renderer/+onRenderClient.ts +3 -3
- package/boilerplate-vue-ts/renderer/+onRenderHtml.ts +2 -2
- package/boilerplate-vue-ts/renderer/Link.vue +1 -1
- package/boilerplate-vue-ts/renderer/createVueApp.ts +30 -0
- package/boilerplate-vue-ts/renderer/useData.ts +5 -5
- package/boilerplate-vue-ts/renderer/usePageContext.ts +4 -4
- package/boilerplate-vue-ts/renderer/utils.ts +0 -4
- package/package.json +1 -1
- package/boilerplate-vue/renderer/app.js +0 -45
- package/boilerplate-vue/renderer/utils.js +0 -3
- package/boilerplate-vue-ts/renderer/app.ts +0 -46
- /package/boilerplate-react/renderer/{PageLayout.css → Layout.css} +0 -0
- /package/boilerplate-react-ts/renderer/{PageLayout.css → Layout.css} +0 -0
- /package/boilerplate-vue/renderer/{PageLayout.vue → Layout.vue} +0 -0
- /package/boilerplate-vue-ts/renderer/{PageLayout.vue → Layout.vue} +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { onRenderClient }
|
|
3
3
|
|
|
4
4
|
import ReactDOM from 'react-dom/client'
|
|
5
|
-
import {
|
|
5
|
+
import { Layout } from './Layout'
|
|
6
6
|
import { getPageTitle } from './getPageTitle'
|
|
7
7
|
|
|
8
8
|
let root
|
|
@@ -17,9 +17,9 @@ function onRenderClient(pageContext) {
|
|
|
17
17
|
if (!container) throw new Error('DOM element #react-root not found')
|
|
18
18
|
|
|
19
19
|
const page = (
|
|
20
|
-
<
|
|
20
|
+
<Layout pageContext={pageContext}>
|
|
21
21
|
<Page />
|
|
22
|
-
</
|
|
22
|
+
</Layout>
|
|
23
23
|
)
|
|
24
24
|
if (pageContext.isHydration) {
|
|
25
25
|
root = ReactDOM.hydrateRoot(container, page)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { onRenderHtml }
|
|
3
3
|
|
|
4
4
|
import ReactDOMServer from 'react-dom/server'
|
|
5
|
-
import {
|
|
5
|
+
import { Layout } from './Layout'
|
|
6
6
|
import { escapeInject, dangerouslySkipEscape } from 'vike/server'
|
|
7
7
|
import logoUrl from './logo.svg'
|
|
8
8
|
import { getPageTitle } from './getPageTitle'
|
|
@@ -16,9 +16,9 @@ function onRenderHtml(pageContext) {
|
|
|
16
16
|
|
|
17
17
|
// Alternativly, we can use an HTML stream, see https://vike.dev/streaming
|
|
18
18
|
const pageHtml = ReactDOMServer.renderToString(
|
|
19
|
-
<
|
|
19
|
+
<Layout pageContext={pageContext}>
|
|
20
20
|
<Page />
|
|
21
|
-
</
|
|
21
|
+
</Layout>
|
|
22
22
|
)
|
|
23
23
|
|
|
24
24
|
// See https://vike.dev/head
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Layout }
|
|
2
2
|
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import PropTypes from 'prop-types'
|
|
@@ -7,17 +7,17 @@ import logoUrl from './logo.svg'
|
|
|
7
7
|
import { PageContextProvider } from './usePageContext'
|
|
8
8
|
import { Link } from './Link'
|
|
9
9
|
import './css/index.css'
|
|
10
|
-
import './
|
|
10
|
+
import './Layout.css'
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Layout.propTypes = {
|
|
13
13
|
pageContext: PropTypes.any,
|
|
14
14
|
children: childrenPropType
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function Layout({ pageContext, children }) {
|
|
17
17
|
return (
|
|
18
18
|
<React.StrictMode>
|
|
19
19
|
<PageContextProvider pageContext={pageContext}>
|
|
20
|
-
<
|
|
20
|
+
<Frame>
|
|
21
21
|
<Sidebar>
|
|
22
22
|
<Logo />
|
|
23
23
|
<Link href="/">Welcome</Link>
|
|
@@ -25,16 +25,16 @@ function PageLayout({ pageContext, children }) {
|
|
|
25
25
|
<Link href="/star-wars">Data Fetching</Link>
|
|
26
26
|
</Sidebar>
|
|
27
27
|
<Content>{children}</Content>
|
|
28
|
-
</
|
|
28
|
+
</Frame>
|
|
29
29
|
</PageContextProvider>
|
|
30
30
|
</React.StrictMode>
|
|
31
31
|
)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Frame.propTypes = {
|
|
35
35
|
children: childrenPropType
|
|
36
36
|
}
|
|
37
|
-
function
|
|
37
|
+
function Frame({ children }) {
|
|
38
38
|
return (
|
|
39
39
|
<div
|
|
40
40
|
style={{
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { onRenderClient }
|
|
3
3
|
|
|
4
4
|
import ReactDOM from 'react-dom/client'
|
|
5
|
-
import {
|
|
5
|
+
import { Layout } from './Layout'
|
|
6
6
|
import { getPageTitle } from './getPageTitle'
|
|
7
7
|
import type { OnRenderClientAsync } from 'vike/types'
|
|
8
8
|
|
|
@@ -18,9 +18,9 @@ const onRenderClient: OnRenderClientAsync = async (pageContext): ReturnType<OnRe
|
|
|
18
18
|
if (!container) throw new Error('DOM element #react-root not found')
|
|
19
19
|
|
|
20
20
|
const page = (
|
|
21
|
-
<
|
|
21
|
+
<Layout pageContext={pageContext}>
|
|
22
22
|
<Page />
|
|
23
|
-
</
|
|
23
|
+
</Layout>
|
|
24
24
|
)
|
|
25
25
|
if (pageContext.isHydration) {
|
|
26
26
|
root = ReactDOM.hydrateRoot(container, page)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { onRenderHtml }
|
|
3
3
|
|
|
4
4
|
import ReactDOMServer from 'react-dom/server'
|
|
5
|
-
import {
|
|
5
|
+
import { Layout } from './Layout'
|
|
6
6
|
import { escapeInject, dangerouslySkipEscape } from 'vike/server'
|
|
7
7
|
import logoUrl from './logo.svg'
|
|
8
8
|
import type { OnRenderHtmlAsync } from 'vike/types'
|
|
@@ -17,9 +17,9 @@ const onRenderHtml: OnRenderHtmlAsync = async (pageContext): ReturnType<OnRender
|
|
|
17
17
|
|
|
18
18
|
// Alternativly, we can use an HTML stream, see https://vike.dev/streaming
|
|
19
19
|
const pageHtml = ReactDOMServer.renderToString(
|
|
20
|
-
<
|
|
20
|
+
<Layout pageContext={pageContext}>
|
|
21
21
|
<Page />
|
|
22
|
-
</
|
|
22
|
+
</Layout>
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
// See https://vike.dev/head
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Layout }
|
|
2
2
|
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import logoUrl from './logo.svg'
|
|
@@ -6,13 +6,13 @@ import { PageContextProvider } from './usePageContext'
|
|
|
6
6
|
import { Link } from './Link'
|
|
7
7
|
import type { PageContext } from 'vike/types'
|
|
8
8
|
import './css/index.css'
|
|
9
|
-
import './
|
|
9
|
+
import './Layout.css'
|
|
10
10
|
|
|
11
|
-
function
|
|
11
|
+
function Layout({ children, pageContext }: { children: React.ReactNode; pageContext: PageContext }) {
|
|
12
12
|
return (
|
|
13
13
|
<React.StrictMode>
|
|
14
14
|
<PageContextProvider pageContext={pageContext}>
|
|
15
|
-
<
|
|
15
|
+
<Frame>
|
|
16
16
|
<Sidebar>
|
|
17
17
|
<Logo />
|
|
18
18
|
<Link href="/">Welcome</Link>
|
|
@@ -20,13 +20,13 @@ function PageLayout({ children, pageContext }: { children: React.ReactNode; page
|
|
|
20
20
|
<Link href="/star-wars">Data Fetching</Link>
|
|
21
21
|
</Sidebar>
|
|
22
22
|
<Content>{children}</Content>
|
|
23
|
-
</
|
|
23
|
+
</Frame>
|
|
24
24
|
</PageContextProvider>
|
|
25
25
|
</React.StrictMode>
|
|
26
26
|
)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
function
|
|
29
|
+
function Frame({ children }: { children: React.ReactNode }) {
|
|
30
30
|
return (
|
|
31
31
|
<div
|
|
32
32
|
style={{
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { usePageContext } from '../../renderer/usePageContext'
|
|
9
9
|
|
|
10
10
|
const pageContext = usePageContext()
|
|
11
|
-
let { is404, abortReason } = pageContext
|
|
11
|
+
let { is404, abortReason } = pageContext.value
|
|
12
12
|
if (!abortReason) {
|
|
13
13
|
abortReason = is404 ? 'Page not found.' : 'Something went wrong.'
|
|
14
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// https://vike.dev/onRenderClient
|
|
2
2
|
export { onRenderClient }
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { createVueApp } from './createVueApp'
|
|
5
5
|
import { getPageTitle } from './getPageTitle'
|
|
6
6
|
|
|
7
7
|
let app
|
|
@@ -11,7 +11,7 @@ async function onRenderClient(pageContext) {
|
|
|
11
11
|
if (!pageContext.Page) throw new Error('My onRenderClient() hook expects pageContext.Page to be defined')
|
|
12
12
|
|
|
13
13
|
if (!app) {
|
|
14
|
-
app =
|
|
14
|
+
app = createVueApp(pageContext)
|
|
15
15
|
app.mount('#app')
|
|
16
16
|
} else {
|
|
17
17
|
app.changePage(pageContext)
|
|
@@ -3,7 +3,7 @@ export { onRenderHtml }
|
|
|
3
3
|
|
|
4
4
|
import { renderToString as renderToString_ } from '@vue/server-renderer'
|
|
5
5
|
import { escapeInject, dangerouslySkipEscape } from 'vike/server'
|
|
6
|
-
import {
|
|
6
|
+
import { createVueApp } from './createVueApp'
|
|
7
7
|
import logoUrl from './logo.svg'
|
|
8
8
|
import { getPageTitle } from './getPageTitle'
|
|
9
9
|
|
|
@@ -12,7 +12,7 @@ async function onRenderHtml(pageContext) {
|
|
|
12
12
|
// onRenderHtml() to support SPA
|
|
13
13
|
if (!pageContext.Page) throw new Error('My render() hook expects pageContext.Page to be defined')
|
|
14
14
|
|
|
15
|
-
const app =
|
|
15
|
+
const app = createVueApp(pageContext)
|
|
16
16
|
|
|
17
17
|
const appHtml = await renderToString(app)
|
|
18
18
|
|
|
@@ -19,7 +19,7 @@ import { usePageContext } from './usePageContext'
|
|
|
19
19
|
const pageContext = usePageContext()
|
|
20
20
|
const { href } = useAttrs()
|
|
21
21
|
const isActive = computed(() => {
|
|
22
|
-
const { urlPathname } = pageContext
|
|
22
|
+
const { urlPathname } = pageContext.value
|
|
23
23
|
return href === '/' ? urlPathname === href : urlPathname.startsWith(href)
|
|
24
24
|
})
|
|
25
25
|
</script>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { createVueApp }
|
|
2
|
+
|
|
3
|
+
import { createSSRApp, h, shallowRef } from 'vue'
|
|
4
|
+
import { setPageContext } from './usePageContext'
|
|
5
|
+
import { setData } from './useData'
|
|
6
|
+
import Layout from './Layout.vue'
|
|
7
|
+
|
|
8
|
+
function createVueApp(pageContext) {
|
|
9
|
+
const pageContextRef = shallowRef(pageContext)
|
|
10
|
+
const dataRef = shallowRef(pageContext.data)
|
|
11
|
+
const pageRef = shallowRef(pageContext.Page)
|
|
12
|
+
|
|
13
|
+
const RootComponent = () => h(Layout, null, () => h(pageRef.value))
|
|
14
|
+
const app = createSSRApp(RootComponent)
|
|
15
|
+
setPageContext(app, pageContextRef)
|
|
16
|
+
setData(app, dataRef)
|
|
17
|
+
|
|
18
|
+
// app.changePage() is called upon navigation, see +onRenderClient.ts
|
|
19
|
+
Object.assign(app, {
|
|
20
|
+
changePage: (pageContext) => {
|
|
21
|
+
pageContextRef.value = pageContext
|
|
22
|
+
dataRef.value = pageContext.data
|
|
23
|
+
pageRef.value = pageContext.Page
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return app
|
|
28
|
+
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { usePageContext } from '../../renderer/usePageContext'
|
|
9
9
|
|
|
10
10
|
const pageContext = usePageContext()
|
|
11
|
-
let { is404, abortReason } = pageContext
|
|
11
|
+
let { is404, abortReason } = pageContext.value
|
|
12
12
|
if (!abortReason) {
|
|
13
13
|
abortReason = is404 ? 'Page not found.' : 'Something went wrong.'
|
|
14
14
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
// https://vike.dev/onRenderClient
|
|
2
2
|
export { onRenderClient }
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { createVueApp } from './createVueApp'
|
|
5
5
|
import { getPageTitle } from './getPageTitle'
|
|
6
6
|
import type { OnRenderClientAsync } from 'vike/types'
|
|
7
7
|
|
|
8
|
-
let app: ReturnType<typeof
|
|
8
|
+
let app: ReturnType<typeof createVueApp>
|
|
9
9
|
const onRenderClient: OnRenderClientAsync = async (pageContext): ReturnType<OnRenderClientAsync> => {
|
|
10
10
|
// This onRenderClient() hook only supports SSR, see https://vike.dev/render-modes for how to modify onRenderClient()
|
|
11
11
|
// to support SPA
|
|
12
12
|
if (!pageContext.Page) throw new Error('My onRenderClient() hook expects pageContext.Page to be defined')
|
|
13
13
|
|
|
14
14
|
if (!app) {
|
|
15
|
-
app =
|
|
15
|
+
app = createVueApp(pageContext)
|
|
16
16
|
app.mount('#app')
|
|
17
17
|
} else {
|
|
18
18
|
app.changePage(pageContext)
|
|
@@ -4,7 +4,7 @@ export { onRenderHtml }
|
|
|
4
4
|
import { renderToString as renderToString_ } from '@vue/server-renderer'
|
|
5
5
|
import type { App } from 'vue'
|
|
6
6
|
import { escapeInject, dangerouslySkipEscape } from 'vike/server'
|
|
7
|
-
import {
|
|
7
|
+
import { createVueApp } from './createVueApp'
|
|
8
8
|
import logoUrl from './logo.svg'
|
|
9
9
|
import type { OnRenderHtmlAsync } from 'vike/types'
|
|
10
10
|
import { getPageTitle } from './getPageTitle'
|
|
@@ -14,7 +14,7 @@ const onRenderHtml: OnRenderHtmlAsync = async (pageContext): ReturnType<OnRender
|
|
|
14
14
|
// onRenderHtml() to support SPA
|
|
15
15
|
if (!pageContext.Page) throw new Error('My render() hook expects pageContext.Page to be defined')
|
|
16
16
|
|
|
17
|
-
const app =
|
|
17
|
+
const app = createVueApp(pageContext)
|
|
18
18
|
|
|
19
19
|
const appHtml = await renderToString(app)
|
|
20
20
|
|
|
@@ -19,7 +19,7 @@ import { usePageContext } from './usePageContext'
|
|
|
19
19
|
const pageContext = usePageContext()
|
|
20
20
|
const { href } = useAttrs() as { href: string }
|
|
21
21
|
const isActive = computed(() => {
|
|
22
|
-
const { urlPathname } = pageContext
|
|
22
|
+
const { urlPathname } = pageContext.value
|
|
23
23
|
return href === '/' ? urlPathname === href : urlPathname.startsWith(href)
|
|
24
24
|
})
|
|
25
25
|
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export { createVueApp }
|
|
2
|
+
|
|
3
|
+
import { createSSRApp, h, shallowRef } from 'vue'
|
|
4
|
+
import { setPageContext } from './usePageContext'
|
|
5
|
+
import { setData } from './useData'
|
|
6
|
+
import Layout from './Layout.vue'
|
|
7
|
+
import type { PageContext } from 'vike/types'
|
|
8
|
+
import { objectAssign } from './utils'
|
|
9
|
+
|
|
10
|
+
function createVueApp(pageContext: PageContext) {
|
|
11
|
+
const pageContextRef = shallowRef(pageContext)
|
|
12
|
+
const dataRef = shallowRef(pageContext.data)
|
|
13
|
+
const pageRef = shallowRef(pageContext.Page)
|
|
14
|
+
|
|
15
|
+
const RootComponent = () => h(Layout, null, () => h(pageRef.value))
|
|
16
|
+
const app = createSSRApp(RootComponent)
|
|
17
|
+
setPageContext(app, pageContextRef)
|
|
18
|
+
setData(app, dataRef)
|
|
19
|
+
|
|
20
|
+
// app.changePage() is called upon navigation, see +onRenderClient.ts
|
|
21
|
+
objectAssign(app, {
|
|
22
|
+
changePage: (pageContext: PageContext) => {
|
|
23
|
+
pageContextRef.value = pageContext
|
|
24
|
+
dataRef.value = pageContext.data
|
|
25
|
+
pageRef.value = pageContext.Page
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
return app
|
|
30
|
+
}
|
|
@@ -3,17 +3,17 @@ export { useData }
|
|
|
3
3
|
export { setData }
|
|
4
4
|
|
|
5
5
|
import { inject } from 'vue'
|
|
6
|
-
import type { App } from 'vue'
|
|
6
|
+
import type { App, InjectionKey, Ref } from 'vue'
|
|
7
7
|
|
|
8
|
-
const key = Symbol()
|
|
8
|
+
const key: InjectionKey<Ref<unknown>> = Symbol()
|
|
9
9
|
|
|
10
10
|
/** https://vike.dev/useData */
|
|
11
|
-
function useData<Data>(): Data {
|
|
11
|
+
function useData<Data>(): Ref<Data> {
|
|
12
12
|
const data = inject(key)
|
|
13
13
|
if (!data) throw new Error('setData() not called')
|
|
14
|
-
return data as
|
|
14
|
+
return data as Ref<Data>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function setData(app: App, data: unknown): void {
|
|
17
|
+
function setData(app: App, data: Ref<unknown>): void {
|
|
18
18
|
app.provide(key, data)
|
|
19
19
|
}
|
|
@@ -3,18 +3,18 @@ export { usePageContext }
|
|
|
3
3
|
export { setPageContext }
|
|
4
4
|
|
|
5
5
|
import { inject } from 'vue'
|
|
6
|
-
import type { App, InjectionKey } from 'vue'
|
|
6
|
+
import type { App, InjectionKey, Ref } from 'vue'
|
|
7
7
|
import type { PageContext } from 'vike/types'
|
|
8
8
|
|
|
9
|
-
const key: InjectionKey<PageContext
|
|
9
|
+
const key: InjectionKey<Ref<PageContext>> = Symbol()
|
|
10
10
|
|
|
11
11
|
/** https://vike.dev/usePageContext */
|
|
12
|
-
function usePageContext(): PageContext {
|
|
12
|
+
function usePageContext(): Ref<PageContext> {
|
|
13
13
|
const pageContext = inject(key)
|
|
14
14
|
if (!pageContext) throw new Error('setPageContext() not called in parent')
|
|
15
15
|
return pageContext
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function setPageContext(app: App, pageContext: PageContext): void {
|
|
18
|
+
function setPageContext(app: App, pageContext: Ref<PageContext>): void {
|
|
19
19
|
app.provide(key, pageContext)
|
|
20
20
|
}
|
|
@@ -5,7 +5,3 @@ export function objectAssign<Obj extends object, ObjAddendum>(
|
|
|
5
5
|
): asserts obj is Obj & ObjAddendum {
|
|
6
6
|
Object.assign(obj, objAddendum)
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
10
|
-
return typeof value === 'object' && value !== null
|
|
11
|
-
}
|
package/package.json
CHANGED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export { createApp }
|
|
2
|
-
|
|
3
|
-
import { createSSRApp, h, markRaw, reactive, ref } from 'vue'
|
|
4
|
-
import PageLayout from './PageLayout.vue'
|
|
5
|
-
import { setPageContext } from './usePageContext'
|
|
6
|
-
import { setData } from './useData'
|
|
7
|
-
import { isObject } from './utils'
|
|
8
|
-
|
|
9
|
-
function createApp(pageContext) {
|
|
10
|
-
const { Page } = pageContext
|
|
11
|
-
|
|
12
|
-
const pageRef = ref(markRaw(Page))
|
|
13
|
-
|
|
14
|
-
const PageWithLayout = {
|
|
15
|
-
render() {
|
|
16
|
-
return h(PageLayout, {}, { default: () => h(pageRef.value) })
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const app = createSSRApp(PageWithLayout)
|
|
21
|
-
|
|
22
|
-
// app.changePage() is called upon navigation, see +onRenderClient.ts
|
|
23
|
-
Object.assign(app, {
|
|
24
|
-
changePage: (pageContext) => {
|
|
25
|
-
const data = pageContext.data ?? {}
|
|
26
|
-
assertDataIsObject(data)
|
|
27
|
-
Object.assign(dataReactive, data)
|
|
28
|
-
Object.assign(pageContextReactive, pageContext)
|
|
29
|
-
pageRef.value = markRaw(pageContext.Page)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const data = pageContext.data ?? {}
|
|
34
|
-
assertDataIsObject(data)
|
|
35
|
-
const dataReactive = reactive(data)
|
|
36
|
-
const pageContextReactive = reactive(pageContext)
|
|
37
|
-
setPageContext(app, pageContextReactive)
|
|
38
|
-
setData(app, dataReactive)
|
|
39
|
-
|
|
40
|
-
return app
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function assertDataIsObject(data) {
|
|
44
|
-
if (!isObject(data)) throw new Error('Return value of data() hook should be an object, undefined, or null')
|
|
45
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export { createApp }
|
|
2
|
-
|
|
3
|
-
import { createSSRApp, h, markRaw, reactive, ref } from 'vue'
|
|
4
|
-
import PageLayout from './PageLayout.vue'
|
|
5
|
-
import { setPageContext } from './usePageContext'
|
|
6
|
-
import type { PageContext } from 'vike/types'
|
|
7
|
-
import { setData } from './useData'
|
|
8
|
-
import { isObject, objectAssign } from './utils'
|
|
9
|
-
|
|
10
|
-
function createApp(pageContext: PageContext) {
|
|
11
|
-
const { Page } = pageContext
|
|
12
|
-
|
|
13
|
-
const pageRef = ref(markRaw(Page))
|
|
14
|
-
|
|
15
|
-
const PageWithLayout = {
|
|
16
|
-
render() {
|
|
17
|
-
return h(PageLayout, {}, { default: () => h(pageRef.value) })
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const app = createSSRApp(PageWithLayout)
|
|
22
|
-
|
|
23
|
-
// app.changePage() is called upon navigation, see +onRenderClient.ts
|
|
24
|
-
objectAssign(app, {
|
|
25
|
-
changePage: (pageContext: PageContext) => {
|
|
26
|
-
const data = pageContext.data ?? {}
|
|
27
|
-
assertDataIsObject(data)
|
|
28
|
-
Object.assign(dataReactive, data)
|
|
29
|
-
Object.assign(pageContextReactive, pageContext)
|
|
30
|
-
pageRef.value = markRaw(pageContext.Page)
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const data = pageContext.data ?? {}
|
|
35
|
-
assertDataIsObject(data)
|
|
36
|
-
const dataReactive = reactive(data)
|
|
37
|
-
const pageContextReactive = reactive(pageContext)
|
|
38
|
-
setPageContext(app, pageContextReactive)
|
|
39
|
-
setData(app, dataReactive)
|
|
40
|
-
|
|
41
|
-
return app
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function assertDataIsObject(data: unknown): asserts data is Record<string, unknown> {
|
|
45
|
-
if (!isObject(data)) throw new Error('Return value of data() hook should be an object, undefined, or null')
|
|
46
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|