Skip to content

Commit

Permalink
fix: missing register component in ssr (vuejs#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
mog422 committed Jul 19, 2024
1 parent 6986365 commit 3fc2599
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,18 @@ export default function loader(
.join(`\n`) + `\n`
}

if (isServer) {
code += `import { useSSRContext } from 'vue'\n`
code += `const _setup = script.setup\n`
;(code += `script.setup = (props, ctx) => {`),
(code += ` const ssrContext = _useSSRContext()`),
(code += ` ;(ssrContext._registeredComponents || (ssrContext._registeredComponents = new Set())).add(${JSON.stringify(
hash(loaderContext.request)
)});`)
code += ` return _setup ? _setup(props, ctx) : undefined`
code += `}\n`
}

// finalize
if (!propsToAttach.length) {
code += `\n\nconst __exports__ = script;`
Expand Down

0 comments on commit 3fc2599

Please sign in to comment.