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', () => {
const Child = {
__scopeId: 'child',
// - scopeId from parent
// - slotted scopeId (with `-s` postfix) from child (the tree owner)
expect(serializeInner(root)).toBe(
- `<div child><div parent child-s></div></div>`
+ `<div parent child><div parent child-s></div></div>`
)
})
})
): VNode {
const {
type: Component,
+ parent,
vnode,
proxy,
withProxy,
if (vnodeHooks !== EMPTY_OBJ) {
result = cloneVNode(result, vnodeHooks)
}
+ // inherit scopeId
+ const parentScopeId = parent && parent.type.__scopeId
+ if (parentScopeId) {
+ result = cloneVNode(result, { [parentScopeId]: '' })
+ }
// inherit directives
if (vnode.dirs != null) {
if (__DEV__ && !isElementRoot(result)) {
result = createVNode(Comment)
}
currentRenderingInstance = null
+
return result
}
}
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>`
)
})
})
).toBe(` id="foo" title="bar"`)
})
+ test('empty value attrs', () => {
+ expect(
+ ssrRenderAttrs({
+ 'data-v-abc': ''
+ })
+ ).toBe(` data-v-abc`)
+ })
+
test('escape attrs', () => {
expect(
ssrRenderAttrs({
if (isBooleanAttr(attrKey)) {
return value === false ? `` : ` ${attrKey}`
} else if (isSSRSafeAttrName(attrKey)) {
- return ` ${attrKey}="${escapeHtml(value)}"`
+ return value === ''
+ ? ` ${attrKey}`
+ : ` ${attrKey}="${escapeHtml(value)}"`
} else {
console.warn(
`[@vue/server-renderer] Skipped rendering unsafe attribute name: ${attrKey}`