Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fouc on dev ssr #1308

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/bridge/src/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { buildAssetsURL } from '#paths'
// @ts-expect-error virtual file
import htmlTemplate from '#build/views/document.template.mjs'
// @ts-ignore
import { renderToString } from '#vue-renderer'
import { renderToString as _renderToString } from '#vue-renderer'
// @ts-expect-error virtual file
import metaConfig from '#build/meta.config.mjs'

Expand Down Expand Up @@ -90,11 +90,25 @@ const getSSRRenderer = lazyCachedFunction(async () => {
const createSSRApp = await getServerEntry()
if (!createSSRApp) { throw new Error('Server bundle is not available') }

return createRenderer(createSSRApp, {
const options = {
manifest,
renderToString,
buildAssetsURL
})
}
// Create renderer
const renderer = createRenderer(createSSRApp, options)

type RenderToStringParams = Parameters<typeof _renderToString>
async function renderToString (input: RenderToStringParams[0], context: RenderToStringParams[1]) {
const html = await _renderToString(input, context)
// In development with vite-node, the manifest is on-demand and will be available after rendering
if (process.dev && process.env.NUXT_VITE_NODE_OPTIONS) {
renderer.rendererContext.updateManifest(await getClientManifest())
}
return html
}

return renderer
})

// -- SPA Renderer --
Expand Down