From: daiwei Date: Wed, 29 Oct 2025 01:13:04 +0000 (+0800) Subject: wip: save X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cf9384588a5f8254d1588482187c05fb5d1c8031;p=thirdparty%2Fvuejs%2Fcore.git wip: save --- diff --git a/packages/runtime-vapor/__tests__/customElement.spec.ts b/packages/runtime-vapor/__tests__/customElement.spec.ts index f7ef9f8b82..d91d33c77b 100644 --- a/packages/runtime-vapor/__tests__/customElement.spec.ts +++ b/packages/runtime-vapor/__tests__/customElement.spec.ts @@ -1574,91 +1574,110 @@ describe('defineVaporCustomElement', () => { app.unmount() }) - // test('toggle nested custom element with shadowRoot: false', async () => { - // customElements.define( - // 'my-el-child-shadow-false', - // defineVaporCustomElement( - // { - // render(ctx: any) { - // return h('div', null, [renderSlot(ctx.$slots, 'default')]) - // }, - // }, - // { shadowRoot: false }, - // ), - // ) - // const ChildWrapper = { - // render() { - // return h('my-el-child-shadow-false', null, 'child') - // }, - // } - - // customElements.define( - // 'my-el-parent-shadow-false', - // defineVaporCustomElement( - // { - // props: { - // isShown: { type: Boolean, required: true }, - // }, - // render(ctx: any, _: any, $props: any) { - // return $props.isShown - // ? h('div', { key: 0 }, [renderSlot(ctx.$slots, 'default')]) - // : null - // }, - // }, - // { shadowRoot: false }, - // ), - // ) - // const ParentWrapper = { - // props: { - // isShown: { type: Boolean, required: true }, - // }, - // render(ctx: any, _: any, $props: any) { - // return h('my-el-parent-shadow-false', { isShown: $props.isShown }, [ - // renderSlot(ctx.$slots, 'default'), - // ]) - // }, - // } - - // const isShown = ref(true) - // const App = { - // render() { - // return h(ParentWrapper, { isShown: isShown.value } as any, { - // default: () => [h(ChildWrapper)], - // }) - // }, - // } - // const container = document.createElement('div') - // document.body.appendChild(container) - // const app = createVaporApp(App) - // app.mount(container) - // expect(container.innerHTML).toBe( - // `` + - // `
` + - // `` + - // `
child
` + - // `
` + - // `
` + - // `
`, - // ) + test('toggle nested custom element with shadowRoot: false', async () => { + customElements.define( + 'my-el-child-shadow-false', + defineVaporCustomElement( + { + setup() { + const n0 = template('
')() as any + setInsertionState(n0, null) + createSlot('default', null) + return n0 + }, + }, + { shadowRoot: false } as any, + ), + ) + const ChildWrapper = { + setup() { + return createComponentWithFallback('my-el-child-shadow-false', null, { + default: () => template('child')(), + }) + }, + } - // isShown.value = false - // await nextTick() - // expect(container.innerHTML).toBe( - // ``, - // ) + customElements.define( + 'my-el-parent-shadow-false', + defineVaporCustomElement( + { + props: { + isShown: { type: Boolean, required: true }, + }, + setup(props: any) { + return createIf( + () => props.isShown, + () => { + const n0 = template('
')() as any + setInsertionState(n0, null) + createSlot('default', null) + return n0 + }, + ) + }, + }, + { shadowRoot: false } as any, + ), + ) + const ParentWrapper = { + props: { + isShown: { type: Boolean, required: true }, + }, + setup(props: any) { + return createComponentWithFallback( + 'my-el-parent-shadow-false', + { isShown: () => props.isShown }, + { + default: () => createSlot('default'), + }, + ) + }, + } - // isShown.value = true - // await nextTick() - // expect(container.innerHTML).toBe( - // `` + - // `
` + - // `` + - // `
child
` + - // `
` + - // `
` + - // `
`, - // ) - // }) + const isShown = ref(true) + const App = { + setup() { + return createComponent( + ParentWrapper, + { isShown: () => isShown.value }, + { + default: () => createComponent(ChildWrapper), + }, + ) + }, + } + const container = document.createElement('div') + document.body.appendChild(container) + const app = createVaporApp(App) + app.mount(container) + expect(container.innerHTML).toBe( + `` + + `
` + + `` + + `
child
` + + `
` + + `
` + + `
`, + ) + + isShown.value = false + await nextTick() + expect(container.innerHTML).toBe( + ``, + ) + + isShown.value = true + await nextTick() + expect(container.innerHTML).toBe( + `` + + `
` + + `` + + `
child
` + + `
` + + `
` + + `
`, + ) + }) }) // describe('helpers', () => {