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 + PR #14642 (3.5.32) added the
pendingMountcheck shown above. That gates DOM removal of element children, not theunmountComponent(null, …)call on component children. - Issue #14699 (3.5.32) reported the same crash with the same stack as this issue. Closed by the author with a note about re-filing with a more accurate reproduction.
- Issue #14701 + PR #14702 (3.5.33) added
pendingMounts.has(vnode)guard, but only inmoveTeleport. TheTeleportImpl.removepath was not touched, so 3.5.33 and 3.5.34 still crash.
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /core, current file: none) bash-$
- Assistant
I'll start by exploring the repository to understand its structure and locate the relevant files. Let's first check what's in the root directory.
- Assistant
This is the Vue.js core repository. Let me explore the packages directory to find the runtime-core package where the Teleport implementation likely is.
- Assistant
Let me look at the Teleport implementation and find the
removemethod that's mentioned in the error stack trace. - Assistant
Let me look at the
removemethod of TeleportImpl to understand the issue. - Assistant
Let me open the file around line 317 to see the remove method.
- Assistant
Now let me look at the renderer to understand the
unmountfunction and how it handles component vnodes. - Assistant
Let me search for the unmount function in the renderer.
- Assistant
Let me look at the
unmountfunction and theunmountComponentfunction in the renderer. - Assistant
Now let me look at the
unmountComponentfunction to understand how it handles null components. - Assistant
Now I understand the issue! Let me look at the error reproduction to confirm. The error occurs in the
removemethod ofTeleportImplwhen it tries to unmount children of a teleport that was never mounted. When a teleport is inside a pending suspense, its children may havevnode.component === nullbecause they were never instantiated. The current code checks forpendingMountsand setsshouldRemove = false, but it still tries to unmount the children, which callsunmountComponent(vnode.component!, ...)wherevnode.componentis null.Let me first reproduce the error by creating a simple test script:
- Assistant
Let me look at the existing Teleport tests to understand the patterns used, and also check the git log for recent changes.
- Assistant
Now let me look at the exact
removemethod again more carefully to understand the flow: - Assistant
Let me look at the full remove method.
- Assistant
Now I understand the issue clearly. Let me also look at how the
moveTeleporthandles thependingMountscheck: - Assistant
Now I understand the issue completely. Let me trace through the logic:
- The
TeleportImpl.remove()method correctly detectspendingMountand setsshouldRemove = false - But it still iterates over children and calls
unmount()on each child - For component children that were never mounted (because the teleport was pending/deferred),
vnode.componentisnull - In the
unmountfunction (renderer.ts line 2172-2173), it accessesvnode.component!which isnull, causing the crash
The fix is straightforward: when
pendingMountis set (meaning the teleport was never mounted), we should skip unmounting the children since they were never mounted. This is analogous to the fix inmoveTeleport(line 397) which skips moving children when there's a pending mount.Let me check existing tests first:
- The
- Assistant
Let me look at the process method to understand when target markers are created:
- Assistant
Now I understand the issue clearly. Let me trace through the code:
-
In
TeleportImpl.remove(), when there's apendingMount(teleport was never mounted because it's inside a pending suspense), the code correctly:- Disposes the pending mount job
- Deletes from
pendingMountsmap - Sets
shouldRemove = false
-
However, it still proceeds to iterate through children and calls
unmount()on each child. For component children that were never mounted,vnode.componentisnull, and theunmountComponentfunction at line 2173 accessesvnode.component!which is null, causing the crash.
The fix is simple: when there's a
pendingMount, we should skip unmounting the children entirely, since they were never mounted. This is analogous to what was done inmoveTeleportat line 397 where children are skipped if they're in a pending mount.Let me also check the
unmountfunction to understand the full picture: -
- Assistant
Now I understand the issue completely. In
TeleportImpl.remove():- When
pendingMountexists,shouldRemoveis set tofalseand the pending mount is cleaned up - BUT the code still proceeds to iterate through children and calls
unmount()on each child - For component children,
unmount()at line 2173 callsunmountComponent(vnode.component!, ...)butvnode.componentisnullbecause the component was never mounted
The fix is to skip unmounting children when there's a pending mount, similar to how
moveTeleportskips moving children when there's a pending mount (line 397).Let me apply the fix:
- When
- Assistant
Now I need to understand the mount flow better. Let me look at the full mount logic in the
processmethod: - Assistant
Now I fully understand the issue. When a teleport is deferred or inside a pending suspense,
queuePendingMount(n2)is called and the method returns early without callingmountToTarget(). This means:targetStartandtargetAnchorare never set- Children are never mounted, so their
componentisnull
When
remove()is called:- It correctly detects
pendingMountand setsshouldRemove = false - But it still tries to
hostRemove(targetStart!)andhostRemove(targetAnchor!)(which may be undefined) - It still iterates children and calls
unmount(), which callsunmountComponent(vnode.component!, ...)withnullcomponent
The fix: when
pendingMountis found, skip ALL removal logic (target markers and children), since nothing was ever mounted. We've already disposed the queued mount job.Let me apply the fix:
- Assistant
The fix looks correct. Now let me verify it works by running the existing tests:
- Assistant
I see - the tests are failing because when a teleport is removed with a pending mount, the anchor comment node is not being cleaned up. The
elandanchorare always created during the initialprocesscall, even when the mount is deferred. So we need to still clean those up.Let me look at what gets created during mount:
- Assistant
I see - the issue is more nuanced. When a teleport is deferred, its
elandanchor(main view anchors) are always created duringprocess, buttargetStartandtargetAnchorare only created whenmountToTarget()runs (which hasn't happened yet for pending mounts). So we need to still remove the main anchor but skip the target markers and children.Let me update the fix:
- Assistant
Now let me run the tests again:
- Assistant
All Teleport tests pass. Now let me run the Suspense tests too:
- Assistant
Now let me create a reproduction script to verify the fix addresses the exact issue described:
- Assistant
Let me check how to build the project.
- Assistant
Let me check if there's already a built version:
- Assistant
Let me build the project:
- Assistant
The build requires rollup which isn't available. Let me write a proper test using vitest instead. Let me first look at the existing test patterns:
- Assistant
Let me look at the existing discard tests more closely:
- Assistant
Now let me write a test that specifically reproduces the bug described in the issue - Teleport + Suspense with component child:
- Assistant
Let me write a quick test directly in a temp file that will be picked up by vitest:
- Assistant
All 51 Teleport tests pass. Now let me write a direct reproduction test to confirm the fix works for the exact issue scenario (teleport with component child inside suspense that gets unmounted before mount):
- Assistant
All Suspense tests pass too. Now let me create a specific test for the exact bug scenario described in the issue:
- Assistant
Let me create the test file in the right location within the project so it can be picked up by vitest.
- Assistant
The unit test project doesn't have a DOM environment. Let me check how the existing Teleport tests handle this:
- Assistant
I see, I need to add
@vitest-environment jsdomannotation. Let me fix my test file: - Assistant
Both reproduction tests pass. Now let me clean up the temp test file and run the full test suite:
- Assistant
Now let me run the full runtime-core test suite:
- Assistant
All 1014 tests pass. Let me verify the final state of the change:
- Assistant
The change is minimal and clean. Let me verify the final state of the fix:
- Assistant
Let me also run a broader set of tests to make sure nothing else is broken:
- Assistant
The only failure is an unrelated performance test (
should not lead to exponential perf cost with deeply chained computed) which is a flaky timing test. All 3164 other tests pass, including all 51 Teleport tests and 57 Suspense tests.Let me verify my change is complete and correct 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.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →