|
1 | | -import { createApp, h, mergeProps, withCtx } from 'vue' |
| 1 | +import { createApp, createVNode, h, mergeProps, withCtx } from 'vue' |
2 | 2 | import { renderToString } from '../src/renderToString' |
3 | | -import { ssrRenderAttrs, ssrRenderComponent, ssrRenderSlot } from '../src' |
| 3 | +import { |
| 4 | + ssrRenderAttrs, |
| 5 | + ssrRenderComponent, |
| 6 | + ssrRenderSlot, |
| 7 | + ssrRenderVNode, |
| 8 | +} from '../src' |
4 | 9 |
|
5 | 10 | describe('ssr: scopedId runtime behavior', () => { |
6 | 11 | test('id on component root', async () => { |
@@ -269,4 +274,37 @@ describe('ssr: scopedId runtime behavior', () => { |
269 | 274 | `</div>`, |
270 | 275 | ) |
271 | 276 | }) |
| 277 | + |
| 278 | + // #12159 |
| 279 | + test('avoid duplicate scopeId through recursive ssr vnode roots', async () => { |
| 280 | + let count = 2 |
| 281 | + |
| 282 | + const Comp = { |
| 283 | + __scopeId: 'comp', |
| 284 | + ssrRender: (ctx: any, push: any, parent: any, attrs: any) => { |
| 285 | + if (--count) { |
| 286 | + push(ssrRenderComponent(Comp, attrs, null, parent)) |
| 287 | + } else { |
| 288 | + ssrRenderVNode(push, createVNode('div', attrs, 'vuejs'), parent) |
| 289 | + } |
| 290 | + }, |
| 291 | + } |
| 292 | + |
| 293 | + const result = await renderToString(createApp(Comp)) |
| 294 | + expect(result).toBe(`<div comp>vuejs</div>`) |
| 295 | + }) |
| 296 | + |
| 297 | + test('avoid duplicate scopeId through recursive render roots', async () => { |
| 298 | + let count = 2 |
| 299 | + |
| 300 | + const Comp = { |
| 301 | + __scopeId: 'comp', |
| 302 | + render(this: any) { |
| 303 | + return --count ? h(Comp, this.$attrs) : h('div', this.$attrs, 'vuejs') |
| 304 | + }, |
| 305 | + } |
| 306 | + |
| 307 | + const result = await renderToString(createApp(Comp)) |
| 308 | + expect(result).toBe(`<div comp>vuejs</div>`) |
| 309 | + }) |
272 | 310 | }) |
0 commit comments