Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/server-renderer/__tests__/ssrScopeId.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createApp, h, mergeProps, withCtx } from 'vue'
import { createApp, createVNode, h, mergeProps, withCtx } from 'vue'
import { renderToString } from '../src/renderToString'
import { ssrRenderAttrs, ssrRenderComponent, ssrRenderSlot } from '../src'
import { renderVNode } from '../src/render'

describe('ssr: scopedId runtime behavior', () => {
test('id on component root', async () => {
Expand Down Expand Up @@ -269,4 +270,23 @@ describe('ssr: scopedId runtime behavior', () => {
`</div>`,
)
})

// #12159
test('avoid scopeId inheritance when recursing components', async () => {
let count = 2

const Comp = {
__scopeId: 'comp',
ssrRender: (ctx: any, push: any, parent: any, attrs: any) => {
if (--count) {
push(ssrRenderComponent(h(Comp), attrs, null, parent))
} else {
renderVNode(push, createVNode('div', attrs, 'vuejs'), parent)
}
},
}

const result = await renderToString(createApp(Comp)) // output: `<div></div>`
expect(result).toBe(`<div comp>vuejs</div>`)
})
})
3 changes: 2 additions & 1 deletion packages/server-renderer/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ShapeFlags,
escapeHtml,
escapeHtmlComment,
hasOwn,
isArray,
isFunction,
isPromise,
Expand Down Expand Up @@ -303,7 +304,7 @@ function renderElementVNode(
openTag += ssrRenderAttrs(props, tag)
}

if (scopeId) {
if (scopeId && (!props || !hasOwn(props, scopeId))) {
openTag += ` ${scopeId}`
}
// inherit parent chain scope id if this is the root node
Expand Down