-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
ScopeIds not working on router-view in SSR after upgrading from vue@3.0.7 #3513
Comments
A hint, this problem occurs when rendering components with manually written render function between ssr optimized components. E.g.
const _withId =_withScopeId("scope-id")
const CompA = {
ssrRender = _withId((_ctx, _push, _parent, _attrs) => {
const RouterView = _resolveComponent("RouterView")
// Render the <RouterView> component
_push(_ssrRenderComponent(RouterView, _attrs, null, _parent))
})
}
const RouterView = {
render() { return h(ViewComp) }
}
const ViewComp = {
ssrRender(_ctx, _push, _parent, _attrs) {
_push(`<p${_attrs}></p>`)
}
} This issue occurs in the renderComponentSubTree function, alternating rendering of SSR-optimized and non-SSR-optimized components will break the inheritance of Edit: The following test case can be used as a minimum reproduction: test('repro', async () => {
const Child = {
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
push(`<div${ssrRenderAttrs(attrs)}></div>`)
}
}
const Middle = {
render() {
return h(Child)
}
}
const Comp = {
__scopeId: 'parent',
ssrRender: (ctx: any, push: any, parent: any) => {
push(ssrRenderComponent(Middle, null, null, parent))
}
}
const result = await renderToString(createApp(Comp)) // output: `<div></div>`
expect(result).toBe(`<div parent></div>`)
}) |
The resolveScopeId function is also problematic. When a component is SSR-optimized, it will no longer have const Child = {
render() {
return h('div')
}
}
const Comp2 = {
__scopeId: 'parent2',
ssrRender: (ctx: any, push: any, parent: any) => {
push(ssrRenderComponent(Child, null, null, parent))
}
}
const Comp = {
__scopeId: 'parent',
ssrRender: (ctx: any, push: any, parent: any) => {
push(ssrRenderComponent(Comp2, null, null, parent))
}
}
async function run () {
// Should output: `<div parent parent2></div>`
// Actual behavior: `<div parent2></div>`
console.log(await renderToString(createApp(Comp)))
}
run() |
I have some ideas, and that requires changes to the compiler, but it has a relatively large impact..... |
@HcySunYang Maybe I could manually add the compiler hints to the render functions to vue router. |
@HcySunYang I suspect we found a similar issue on VTU-next This template
Is this the same root cause, or should I open a different issue? |
@cexbrayat that's a runtime error, definitely a different issue. |
@HcySunYang your case in #3513 (comment) won't happen because SSR-optimized HOC components pass const Comp = {
__scopeId: 'parent',
- ssrRender: (ctx: any, push: any, parent: any) => {
- push(ssrRenderComponent(Comp2, null, null, parent))
+ ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
+ push(ssrRenderComponent(Comp2, attrs, null, parent))
}
} playground link (see SSR output) |
@cexbrayat the bug you mentioned is fixed in 9cf7525 |
Version
3.0.9
Reproduction link
https://github.com/Olli1080/vue-3-ssr-reproduction
Steps to reproduce
Run
npm i
npm start
Open browser on localhost:3000
What is expected?
The scopeId should be applied to the router-view and the header causing the content background to be limegreen
What is actually happening?
The background is white and the scopeId is only missing on the router-view item in the dom.
The background changes to limegreen after navigation
with the scopeId applied
Ran into this after upgrading from vue@3.0.7 to vue@3.0.8 and vue@3.0.9
The text was updated successfully, but these errors were encountered: