|
|
@@ -13,7 +13,9 @@ import {
|
|
|
toDisplayString,
|
|
|
} from '@vue/runtime-dom'
|
|
|
import {
|
|
|
+ VaporTransition,
|
|
|
createComponent,
|
|
|
+ createIf,
|
|
|
createSlot,
|
|
|
createTextNode,
|
|
|
createVaporApp,
|
|
|
@@ -401,6 +403,60 @@ describe('api: provide/inject', () => {
|
|
|
expect(host.innerHTML).toBe('hello<!--slot-->')
|
|
|
})
|
|
|
|
|
|
+ it('transition out-in deferred branch should keep parent inject context', async () => {
|
|
|
+ const toggle = ref(true)
|
|
|
+
|
|
|
+ const ChildA = defineVaporComponent({
|
|
|
+ setup() {
|
|
|
+ const foo = inject('foo', 'missing')
|
|
|
+ const n0 = template('<div></div>')()
|
|
|
+ setElementText(n0, `A:${foo}`)
|
|
|
+ return n0
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const ChildB = defineVaporComponent({
|
|
|
+ setup() {
|
|
|
+ const foo = inject('foo', 'missing')
|
|
|
+ const n0 = template('<div></div>')()
|
|
|
+ setElementText(n0, `B:${foo}`)
|
|
|
+ return n0
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const Parent = defineVaporComponent({
|
|
|
+ setup() {
|
|
|
+ provide('foo', 'from-parent')
|
|
|
+ const onLeave = (_: any, done: Function) => setTimeout(done, 0)
|
|
|
+ return createComponent(
|
|
|
+ VaporTransition,
|
|
|
+ {
|
|
|
+ mode: () => 'out-in',
|
|
|
+ onLeave: () => onLeave,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ default: withVaporCtx(() =>
|
|
|
+ createIf(
|
|
|
+ () => toggle.value,
|
|
|
+ () => createComponent(ChildA),
|
|
|
+ () => createComponent(ChildB),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ )
|
|
|
+ },
|
|
|
+ })
|
|
|
+
|
|
|
+ const { host } = define(Parent).render()
|
|
|
+ expect(host.textContent).toContain('A:from-parent')
|
|
|
+
|
|
|
+ toggle.value = false
|
|
|
+ await nextTick()
|
|
|
+ await new Promise(r => setTimeout(r, 0))
|
|
|
+
|
|
|
+ expect(host.textContent).toContain('B:from-parent')
|
|
|
+ })
|
|
|
+
|
|
|
describe('hasInjectionContext', () => {
|
|
|
it('should be false outside of setup', () => {
|
|
|
expect(hasInjectionContext()).toBe(false)
|