parent
6cab91dfe8
commit
5e54081d5b
@ -1,4 +1,4 @@
|
|||||||
import { createApp, mergeProps, withCtx } from 'vue'
|
import { createApp, h, mergeProps, withCtx } from 'vue'
|
||||||
import { renderToString } from '../src/renderToString'
|
import { renderToString } from '../src/renderToString'
|
||||||
import { ssrRenderComponent, ssrRenderAttrs, ssrRenderSlot } from '../src'
|
import { ssrRenderComponent, ssrRenderAttrs, ssrRenderSlot } from '../src'
|
||||||
|
|
||||||
@ -154,4 +154,29 @@ describe('ssr: scopedId runtime behavior', () => {
|
|||||||
`</div>`
|
`</div>`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #3513
|
||||||
|
test('scopeId inheritance across ssr-compiled andn on-ssr compiled parent chain', 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>`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -129,13 +129,31 @@ function renderComponentSubTree(
|
|||||||
// resolve fallthrough attrs
|
// resolve fallthrough attrs
|
||||||
let attrs =
|
let attrs =
|
||||||
instance.type.inheritAttrs !== false ? instance.attrs : undefined
|
instance.type.inheritAttrs !== false ? instance.attrs : undefined
|
||||||
|
let hasCloned = false
|
||||||
|
|
||||||
// inherited scopeId
|
let cur = instance
|
||||||
const scopeId = instance.vnode.scopeId
|
while (true) {
|
||||||
if (scopeId || slotScopeId) {
|
const scopeId = cur.vnode.scopeId
|
||||||
attrs = { ...attrs }
|
if (scopeId) {
|
||||||
if (scopeId) attrs[scopeId] = ''
|
if (!hasCloned) {
|
||||||
if (slotScopeId) attrs[slotScopeId.trim()] = ''
|
attrs = { ...attrs }
|
||||||
|
hasCloned = true
|
||||||
|
}
|
||||||
|
attrs![scopeId] = ''
|
||||||
|
}
|
||||||
|
const parent = cur.parent
|
||||||
|
if (parent && parent.subTree && parent.subTree === cur.vnode) {
|
||||||
|
// parent is a non-SSR compiled component and is rendering this
|
||||||
|
// component as root. inherit its scopeId if present.
|
||||||
|
cur = parent
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slotScopeId) {
|
||||||
|
if (!hasCloned) attrs = { ...attrs }
|
||||||
|
attrs![slotScopeId.trim()] = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
// set current rendering instance for asset resolution
|
// set current rendering instance for asset resolution
|
||||||
|
Loading…
Reference in New Issue
Block a user