Skip to content

Commit

Permalink
feat(preview): call customCode (importCode/useCode) on both server an…
Browse files Browse the repository at this point in the history
…d client on SSR

- define 2 flags in context: SSR_SERVER (true on server) and SSR_CLIENT (true on client if coming from SSR_SERVER)
  • Loading branch information
pdanpdan committed Dec 3, 2023
1 parent 4c27b9d commit 6a30326
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/output/Preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,17 @@ async function updatePreview() {
...ssrModules,
`import { renderToString as _renderToString } from 'vue/server-renderer'
import { createSSRApp as _createApp } from 'vue'
const SSR_SERVER = true
const SSR_CLIENT = false
${previewOptions?.customCode?.importCode || ''}
const AppComponent = __modules__["${mainFile}"].default
AppComponent.name = 'Repl'
const app = _createApp(AppComponent)
if (!app.config.hasOwnProperty('unwrapInjectedRef')) {
app.config.unwrapInjectedRef = true
}
app.config.warnHandler = () => {}
${previewOptions?.customCode?.useCode || ''}
window.__ssr_promise__ = _renderToString(app).then(html => {
document.body.innerHTML = '<div id="app">' + html + '</div>' + \`${
previewOptions?.bodyHTML || ''
Expand Down Expand Up @@ -240,6 +244,8 @@ async function updatePreview() {
`import { ${
isSSR ? `createSSRApp` : `createApp`
} as _createApp } from "vue"
const SSR_SERVER = false
const SSR_CLIENT = ${String(isSSR)}
${previewOptions?.customCode?.importCode || ''}
const _mount = () => {
const AppComponent = __modules__["${mainFile}"].default
Expand Down

0 comments on commit 6a30326

Please sign in to comment.