ISSUE DESCRIPTION Teleport + Suspense: unmount crashes on pending teleport with…
- User
ISSUE DESCRIPTION
Teleport + Suspense: unmount crashes on pending teleport with component child (regression since 3.5.31)
Vue version
3.5.34
Link to minimal reproduction
https://github.com/pont1s/vue-teleport-unmount-crashes
Steps to reproduce
Option 1 — Browser (primary)
pnpm dev- Open the browser DevTools console.
- Click "Unmount Suspense".
- Observe
TypeError: Cannot read properties of null (reading 'type')in the console
Option 2 — Tests (additional)
pnpm testThe repo also contains three Vitest tests in
tests/teleport-unmount.test.jsWhat is expected?
When a inside a is unmounted before its mount can run, Vue should remove it cleanly. This worked correctly in 3.5.30.
What is actually happening?
In 3.5.31..3.5.34, unmounting such a teleport throws:
TypeError: Cannot read properties of null (reading 'type') at unmountComponent (runtime-core.cjs.js) at unmount at Object.remove (TeleportImpl.remove) at unmount at unmountChildren at unmount at unmountComponent at unmount at Object.resolve (Suspense)System Info
System: OS: macOS 26.3.1 CPU: (8) arm64 Apple M1 Memory: 102.19 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 24.15.0 - /Users/user/.local/state/fnm_multishells/14407_1779493498078/bin/node npm: 11.12.1 - /Users/user/.local/state/fnm_multishells/14407_1779493498078/bin/npm pnpm: 11.1.3 - /Users/user/.local/state/fnm_multishells/14407_1779493498078/bin/pnpm Browsers: Chrome: 148.0.7778.179 Safari: 26.3.1 npmPackages: vue: 3.5.34 => 3.5.34Any additional comments?
This is a continuation of the regression chain that started in 3.5.31:
- PR #8619 (3.5.31) introduced
pendingMountsso teleports defer their mount whenparentSuspense.pendingBranchis set. This is what created the situation where a teleport's children can havevnode.component === null. - Issue #14640 + (3.5.32) added the check shown above. That gates DOM removal of children, not the call on children.
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate relevant files. Let's first check what kind of repository this is and see if it's the Vue core repository.
- Assistant
Let me check the package.json to understand what this repository is.
- Assistant
Good, this is the Vue core repository. Now I need to find the Teleport implementation and understand the bug. Based on the issue description:
- The crash happens in
TeleportImpl.removepath when a teleport's children havevnode.component === null - PR #14619 introduced
pendingMounts - PR #14642 added
pendingMountcheck but only gates DOM removal of element children, notunmountComponentfor component children - PR #14702 added
pendingMounts.has(vnode)guard inmoveTeleportbut NOT inTeleportImpl.remove
So I need to find the Teleport implementation and add the same guard in the
removepath.Let me look at the repository structure first.
- The crash happens in
- Assistant
The key file is
packages/runtime-core/src/components/Teleport.ts. Let me look at it. - Assistant
Now let me look at the
unmountComponentfunction to understand the crash: - Assistant
Let me look at the
unmountfunction and specifically the part where component vnodes are handled: - Assistant
Let me look at the unmount function to see what happens when component is null.
- Assistant
Let me look at the remove method more carefully. Let me look at the full remove function:
- Assistant
Let me look at the remove method more carefully.
- Assistant
Now I understand the issue. When a teleport has a pending mount (content never mounted), the
removemethod setsshouldRemove = falsebut still iterates over children and callsunmount()on each. Theunmount()function in the renderer tries to accessvnode.componentwhich isnullbecause the component was never mounted.Let me also look at the
unmountfunction in the renderer to confirm: - Assistant
Now I have a clear understanding of the issue. Let me also check what version of the repo this is:
- Assistant
Now I understand the issue completely. Let me verify the fix by looking at the exact code structure:
- Assistant
- Assistant
Now I understand the issue completely. Looking at the
TeleportImpl.removemethod:When there is a pending mount, the code correctly:
- Disposes the pending mount job
- Sets
shouldRemove = false
BUT it still iterates over children and calls
unmount()on each child. When a child is a component,unmount()callsunmountComponent(vnode.component!, ...)but since the component was never mounted (because the teleport was pending),vnode.componentisnull, causing the crash.The fix: skip the unmount loop entirely when there's a pending mount, matching the pattern already used in
moveTeleport. Let me also first check the reproduction: - Assistant
Let me look at existing tests for the teleport to understand the test patterns and check if there are tests for this scenario:
- Assistant
Now I have a clear understanding of the issue. The problem is in the
TeleportImpl.removemethod. When there's a pending mount,shouldRemoveis set tofalse, but the code still iterates over children and callsunmount()on each child. For component children,unmount()callsunmountComponent(vnode.component!, ...), but since the component was never mounted (because of the pending mount),vnode.componentisnull, causing the crash.The fix is to skip the children unmounting entirely when there's a pending mount, similar to how
moveTeleportalready handles this with!pendingMounts.has(vnode).Let me apply the fix:
- Assistant
Now I understand the issue clearly. In the
removemethod, when there's apendingMount, the code setsshouldRemove = falsebut still iterates over children and callsunmount(). For component children,unmount()callsunmountComponent(vnode.component!)butvnode.componentis null because the component was never mounted.The fix: when there's a pending mount, skip the children unmount loop entirely (nothing was ever mounted).
- Assistant
It looks like the edit removed the children unmount loop entirely and also the
doRemove && hostRemove(anchor!)line. Let me check the current state: - Assistant
I see the edit went wrong. Let me restore and redo it properly:
- Assistant
Now let me make the correct edit:
- Assistant
Now I'll make the precise fix. The change is to add
!pendingMount &&before the children unmount loop: - Assistant
The edit went wrong - it ate the
ifstatement. Let me restore and redo properly: - Assistant
Let me use the
replacecommand instead: - Assistant
The fix is in place. Now let me verify the change:
- Assistant
The fix is clean and minimal - just one line change. Now let me write a test to verify the fix works. First, let me look at the existing Teleport test patterns:
- Assistant
Let me look for existing Suspense tests that test Teleport + unmount scenarios:
- Assistant
Let me look at the test around line 2525 which seems relevant - teleport inside suspense being unmounted:
- Assistant
Let me look at the rest of this test and also the specific test for the issue:
- Assistant
Now let me run the existing Teleport and Suspense tests to make sure my fix doesn't break anything:
- Assistant
The test command timed out. Let me try running it differently.
- Assistant
All 51 Teleport tests pass. Now let me also run the Suspense tests:
- Assistant
All 57 Suspense tests pass too. Now let me write a test to reproduce and verify the fix:
- Assistant
Let me try a different approach to test - create a temporary test file in the proper location:
- Assistant
The test needs to be in the right directory and match the naming pattern. Let me create it properly:
- Assistant
The test passes with my fix. Now let me verify the fix is correct by reverting the change and confirming the test fails:
- Assistant
The test passes even without the fix - that means my test doesn't exactly reproduce the crash scenario. Let me think about this more carefully and check what's actually happening:
- Assistant
Let me look at the issue more carefully. The reproduction says the crash happens when unmounting suspense while the teleport is pending. Let me look at the actual scenario from the reproduction repo more carefully:
- Assistant
The test still passes without the fix. Let me understand why. Let me add some debugging to see what's actually happening:
- Assistant
Let me check if
__FEATURE_SUSPENSE__is enabled in the test environment: - Assistant
Let me look at the test pattern from #14701 more closely:
- Assistant
Let me understand how
defineAsyncComponentworks in@vue/runtime-test: - Assistant
Let me look at the
defineAsyncComponenthelper used in the Suspense tests. - Assistant
Now I understand the test setup. Let me create a more targeted test. The key insight is that the Teleport must be rendered as a SIBLING of the async component within the Suspense (not inside the async component itself), so that the Teleport vnode exists but its mount is deferred due to
parentSuspense.pendingBranch. - Assistant
Still passes. Let me look at the Suspense's process method to understand when
pendingBranchis set: - Assistant
Let me look at the Suspense process method to understand when pendingBranch gets set.
- Assistant
Let me look at the Suspense.ts
processmethod more carefully, especially wherependingBranchis set. - Assistant
I see -
pendingBranchis set at line 386 BEFORE thepatchcall at line 388. This means when the Teleport'sprocessis called during this patch,parentSuspense.pendingBranchis truthy, so the Teleport's mount is deferred. Let me check the Suspense'sunmountmethod: - Assistant
Let me look at the Suspense
unmountmethod: - Assistant
Let me look at the actual unmount method of the suspense boundary:
- Assistant
I see - the unmount method at line 780-791 handles both
activeBranchandpendingBranch. Now let me look at theresolvemethod since the stack trace mentions it: - Assistant
Let me understand the test environment better. Let me check the vitest config more carefully:
- Assistant
Let me add some temporary debugging to verify what's happening:
- Assistant
Let me revert my fix temporarily and add a debug log to understand what's happening:
- Assistant
Let me check the reproduction repo from the issue to understand the exact scenario better:
- Assistant
Let me check the reproduction repo.
- Assistant
Let me look at the test file:
- Assistant
Now I see the exact reproduction! The key differences are:
NeverResolvingAsync- an async component that never resolves (keeps Suspense pending)- A
Siblingcomponent that renders a Teleport with a component child - Both are children of a
<div>inside the Suspense - There's an
await nextTick()before unmounting
Let me look at the App.vue:
- Assistant
Now I understand the exact scenario! The key difference is the
NeverResolvingAsynccomponent that keeps the Suspense inpendingBranchstate forever. Let me create a proper test: - Assistant
I've reproduced the crash! The error happens at
TeleportImpl.removewhen trying to unmount a component child that was never mounted. Now let me apply my fix and verify it works: - Assistant
Now let me apply the fix:
- Assistant
Now let me verify the test passes with the fix:
- Assistant
The test passes with the fix. Now let me run all the existing Teleport and Suspense tests to make sure I haven't broken anything:
- Assistant
All 51 Teleport tests pass. Now let me run the Suspense tests:
- Assistant
All 57 Suspense tests pass. Let me clean up the temporary test file:
- Assistant
Let me verify the final diff:
- Assistant
The fix is clean and minimal - a single line change. Let me also run a broader set of runtime-core tests to make sure nothing else is broken:
- Assistant
All 1014 tests pass across 44 test files. Let me check that there are no leftover files:
- Assistant
Only the Teleport.ts file is modified. Let me verify the final diff one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.