From 7418c038f11643bd090398686a804ebf1994ef84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=9B=BE=E4=B8=89=E8=AF=AD?= <32354856+baiwusanyu-c@users.noreply.github.com> Date: Mon, 6 Mar 2023 23:23:56 +0800 Subject: [PATCH 1/2] feat(runtime-core): `to` changes during `teleport` disabled cause update error --- packages/runtime-core/src/components/Teleport.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index f9f845298dc..3d13d8bb58a 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -186,6 +186,13 @@ export const TeleportImpl = { internals, TeleportMoveTypes.TOGGLE ) + } else { + // #7835 + // When `teleport` is disabled, `to` may change, making it always old, + // to ensure the correct `to` when enabled + if (n2.props && n1.props && n2.props.to !== n1.props.to) { + n2.props.to = n1.props.to + } } } else { // target changed From a8cae166cfd1ab7ce8bdeeb214be67d6023f13cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E9=9B=BE=E4=B8=89=E8=AF=AD?= <32354856+baiwusanyu-c@users.noreply.github.com> Date: Mon, 6 Mar 2023 23:51:30 +0800 Subject: [PATCH 2/2] feat(runtime-core): added unit test --- .../__tests__/components/Teleport.spec.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/packages/runtime-core/__tests__/components/Teleport.spec.ts b/packages/runtime-core/__tests__/components/Teleport.spec.ts index 95fbf781671..d5d7cd5ebed 100644 --- a/packages/runtime-core/__tests__/components/Teleport.spec.ts +++ b/packages/runtime-core/__tests__/components/Teleport.spec.ts @@ -475,4 +475,57 @@ describe('renderer: teleport', () => { expect(dir.mounted).toHaveBeenCalledTimes(1) expect(dir.unmounted).toHaveBeenCalledTimes(1) }) + + // #7835 + test(`ensure that target changes when disabled are updated correctly when enabled`, async () => { + const root = nodeOps.createElement('div') + const target1 = nodeOps.createElement('div') + const target2 = nodeOps.createElement('div') + const target3 = nodeOps.createElement('div') + const target = ref(target1) + const disabled = ref(true) + + const App = { + setup() { + return () => + h(Fragment, [ + h( + Teleport, + { to: target.value, disabled: disabled.value }, + h('div', 'teleported') + ) + ]) + } + } + render(h(App), root) + disabled.value = false + await nextTick() + expect(serializeInner(target1)).toMatchInlineSnapshot( + `"
teleported
"` + ) + expect(serializeInner(target2)).toMatchInlineSnapshot(`""`) + expect(serializeInner(target3)).toMatchInlineSnapshot(`""`) + + disabled.value = true + await nextTick() + target.value = target2 + await nextTick() + expect(serializeInner(target1)).toMatchInlineSnapshot(`""`) + expect(serializeInner(target2)).toMatchInlineSnapshot(`""`) + expect(serializeInner(target3)).toMatchInlineSnapshot(`""`) + + target.value = target3 + await nextTick() + expect(serializeInner(target1)).toMatchInlineSnapshot(`""`) + expect(serializeInner(target2)).toMatchInlineSnapshot(`""`) + expect(serializeInner(target3)).toMatchInlineSnapshot(`""`) + + disabled.value = false + await nextTick() + expect(serializeInner(target1)).toMatchInlineSnapshot(`""`) + expect(serializeInner(target2)).toMatchInlineSnapshot(`""`) + expect(serializeInner(target3)).toMatchInlineSnapshot( + `"
teleported
"` + ) + }) })