Skip to content

fix(runtime-core): reactive children with teleport #2873

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions packages/runtime-core/__tests__/components/Teleport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,31 @@ describe('renderer: teleport', () => {
`"<div>teleported</div><span>false</span><!--v-if-->"`
)
})

test('should not throw error', async () => {
const targetA = nodeOps.createElement('div')
const targetB = nodeOps.createElement('div')
const target = ref(targetA)
const root = nodeOps.createElement('div')

const children = ref([h('div', 'teleported')])
render(
h(() => [
h(Teleport, { to: target.value }, children.value),
h('div', 'root')
]),
root
)

try {
target.value = targetB
await nextTick()
} catch (err) {
expect(err).toBeUndefined()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not remove the try catch altogether, I don't think it makes sense for this code to throw an undefined error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks a little weird. I'm just trying to show you that an error is thrown when you excute this test case before fixing it.
Actually, I wanted to refactor the test cases after you merged my PRs. Because this one can be tested together with the test case of "should update target" that I modified in my other PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leaon4 I'm not sure what other PR you are referring to, can you clarify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

expect(serializeInner(targetB)).toMatchInlineSnapshot(
`"<div>teleported</div>"`
)
})
})
2 changes: 2 additions & 0 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ function _createVNode(
type = Comment
}

children = toRaw(children)

if (isVNode(type)) {
// createVNode receiving an existing vnode. This happens in cases like
// <component :is="vnode"/>
Expand Down