Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): to changes during teleport disabled cause update error #7837

Merged
merged 26 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7418c03
feat(runtime-core): `to` changes during `teleport` disabled cause upd…
baiwusanyu-c Mar 6, 2023
a8cae16
feat(runtime-core): added unit test
baiwusanyu-c Mar 6, 2023
5d3d7af
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Mar 17, 2023
c03c1cd
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Mar 20, 2023
e1d9293
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Mar 23, 2023
518c778
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Mar 24, 2023
efdff09
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Mar 26, 2023
d940c3e
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Mar 27, 2023
0f3efab
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 6, 2023
edfa57d
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 10, 2023
c53417a
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 10, 2023
30c5ceb
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 11, 2023
1ee69ae
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 14, 2023
83e84d9
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 17, 2023
372325a
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 19, 2023
ab062d5
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 20, 2023
8f79966
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 24, 2023
f5879ea
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Apr 25, 2023
4d02425
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c May 4, 2023
a1070e2
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c May 8, 2023
d255307
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c May 12, 2023
ddd0df3
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c May 12, 2023
9c5a936
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c May 16, 2023
9377ab5
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c May 17, 2023
bd89f55
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c May 22, 2023
5d0d8a4
Merge branch 'main' into bwsy/fix/teleportDisabled
baiwusanyu-c Jul 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/runtime-core/__tests__/components/Teleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`"<div>teleported</div>"`
)
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(
`"<div>teleported</div>"`
)
})
})
7 changes: 7 additions & 0 deletions packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down