|
|
@@ -330,6 +330,70 @@ describe('SFC <script setup> helpers', () => {
|
|
|
expect(seenUid.two).toBeNull()
|
|
|
})
|
|
|
|
|
|
+ test('should not leak currentInstance to sibling slot render', async () => {
|
|
|
+ let done!: () => void
|
|
|
+ const ready = new Promise<void>(r => {
|
|
|
+ done = r
|
|
|
+ })
|
|
|
+ let innerUid: number | null = null
|
|
|
+ let innerRenderUid: number | null = null
|
|
|
+
|
|
|
+ const Inner = defineComponent({
|
|
|
+ setup(_, { slots }) {
|
|
|
+ innerUid = getCurrentInstance()!.uid
|
|
|
+ return () => {
|
|
|
+ innerRenderUid = getCurrentInstance()!.uid
|
|
|
+ done()
|
|
|
+ return h('div', slots.default?.())
|
|
|
+ }
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const Outer = defineComponent({
|
|
|
+ setup(_, { slots }) {
|
|
|
+ return () => h(Inner, null, () => [slots.default?.()])
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const AsyncA = defineComponent({
|
|
|
+ async setup() {
|
|
|
+ let __temp: any, __restore: any
|
|
|
+ ;[__temp, __restore] = withAsyncContext(() =>
|
|
|
+ Promise.resolve()
|
|
|
+ .then(() => {})
|
|
|
+ .then(() => {}),
|
|
|
+ )
|
|
|
+ __temp = await __temp
|
|
|
+ __restore()
|
|
|
+ return () => h('div', 'A')
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const AsyncB = defineComponent({
|
|
|
+ async setup() {
|
|
|
+ let __temp: any, __restore: any
|
|
|
+ ;[__temp, __restore] = withAsyncContext(() => Promise.resolve())
|
|
|
+ __temp = await __temp
|
|
|
+ __restore()
|
|
|
+ return () => h(Outer, null, () => 'B')
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const root = nodeOps.createElement('div')
|
|
|
+ render(
|
|
|
+ h(() => h(Suspense, () => h('div', [h(AsyncA), h(AsyncB)]))),
|
|
|
+ root,
|
|
|
+ )
|
|
|
+
|
|
|
+ await ready
|
|
|
+ expect(
|
|
|
+ 'Slot "default" invoked outside of the render function',
|
|
|
+ ).not.toHaveBeenWarned()
|
|
|
+ expect(innerRenderUid).toBe(innerUid)
|
|
|
+ await Promise.resolve()
|
|
|
+ expect(serializeInner(root)).toBe(`<div><div>A</div><div>B</div></div>`)
|
|
|
+ })
|
|
|
+
|
|
|
test('error handling', async () => {
|
|
|
const spy = vi.fn()
|
|
|
|