fix(sfc): inherit parent scopeId on child rooot (#756)
This commit is contained in:
parent
1b9b235663
commit
9547c2b93d
@ -17,6 +17,27 @@ describe('scopeId runtime support', () => {
|
|||||||
expect(serializeInner(root)).toBe(`<div parent><div parent></div></div>`)
|
expect(serializeInner(root)).toBe(`<div parent><div parent></div></div>`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should attach scopeId to components in parent component', () => {
|
||||||
|
const Child = {
|
||||||
|
__scopeId: 'child',
|
||||||
|
render: withChildId(() => {
|
||||||
|
return h('div')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const App = {
|
||||||
|
__scopeId: 'parent',
|
||||||
|
render: withParentId(() => {
|
||||||
|
return h('div', [h(Child)])
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
render(h(App), root)
|
||||||
|
expect(serializeInner(root)).toBe(
|
||||||
|
`<div parent><div parent child></div></div>`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
test('should work on slots', () => {
|
test('should work on slots', () => {
|
||||||
const Child = {
|
const Child = {
|
||||||
__scopeId: 'child',
|
__scopeId: 'child',
|
||||||
@ -41,7 +62,7 @@ describe('scopeId runtime support', () => {
|
|||||||
// - scopeId from parent
|
// - scopeId from parent
|
||||||
// - slotted scopeId (with `-s` postfix) from child (the tree owner)
|
// - slotted scopeId (with `-s` postfix) from child (the tree owner)
|
||||||
expect(serializeInner(root)).toBe(
|
expect(serializeInner(root)).toBe(
|
||||||
`<div child><div parent child-s></div></div>`
|
`<div parent child><div parent child-s></div></div>`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -39,6 +39,7 @@ export function renderComponentRoot(
|
|||||||
): VNode {
|
): VNode {
|
||||||
const {
|
const {
|
||||||
type: Component,
|
type: Component,
|
||||||
|
parent,
|
||||||
vnode,
|
vnode,
|
||||||
proxy,
|
proxy,
|
||||||
withProxy,
|
withProxy,
|
||||||
@ -102,6 +103,11 @@ export function renderComponentRoot(
|
|||||||
if (vnodeHooks !== EMPTY_OBJ) {
|
if (vnodeHooks !== EMPTY_OBJ) {
|
||||||
result = cloneVNode(result, vnodeHooks)
|
result = cloneVNode(result, vnodeHooks)
|
||||||
}
|
}
|
||||||
|
// inherit scopeId
|
||||||
|
const parentScopeId = parent && parent.type.__scopeId
|
||||||
|
if (parentScopeId) {
|
||||||
|
result = cloneVNode(result, { [parentScopeId]: '' })
|
||||||
|
}
|
||||||
// inherit directives
|
// inherit directives
|
||||||
if (vnode.dirs != null) {
|
if (vnode.dirs != null) {
|
||||||
if (__DEV__ && !isElementRoot(result)) {
|
if (__DEV__ && !isElementRoot(result)) {
|
||||||
@ -127,6 +133,7 @@ export function renderComponentRoot(
|
|||||||
result = createVNode(Comment)
|
result = createVNode(Comment)
|
||||||
}
|
}
|
||||||
currentRenderingInstance = null
|
currentRenderingInstance = null
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,7 +562,7 @@ describe('ssr: renderToString', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
expect(await renderToString(h(Parent))).toBe(
|
expect(await renderToString(h(Parent))).toBe(
|
||||||
`<div data-v-child><span data-v-test data-v-child-s>slot</span></div>`
|
`<div data-v-test data-v-child><span data-v-test data-v-child-s>slot</span></div>`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -26,6 +26,14 @@ describe('ssr: renderAttrs', () => {
|
|||||||
).toBe(` id="foo" title="bar"`)
|
).toBe(` id="foo" title="bar"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('empty value attrs', () => {
|
||||||
|
expect(
|
||||||
|
ssrRenderAttrs({
|
||||||
|
'data-v-abc': ''
|
||||||
|
})
|
||||||
|
).toBe(` data-v-abc`)
|
||||||
|
})
|
||||||
|
|
||||||
test('escape attrs', () => {
|
test('escape attrs', () => {
|
||||||
expect(
|
expect(
|
||||||
ssrRenderAttrs({
|
ssrRenderAttrs({
|
||||||
|
@ -53,7 +53,9 @@ export function ssrRenderDynamicAttr(
|
|||||||
if (isBooleanAttr(attrKey)) {
|
if (isBooleanAttr(attrKey)) {
|
||||||
return value === false ? `` : ` ${attrKey}`
|
return value === false ? `` : ` ${attrKey}`
|
||||||
} else if (isSSRSafeAttrName(attrKey)) {
|
} else if (isSSRSafeAttrName(attrKey)) {
|
||||||
return ` ${attrKey}="${escapeHtml(value)}"`
|
return value === ''
|
||||||
|
? ` ${attrKey}`
|
||||||
|
: ` ${attrKey}="${escapeHtml(value)}"`
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
`[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
|
`[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user