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)
bashpnpm 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)
bashpnpm 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:
codeTypeError: 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
shellSystem: 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.34 Assistant
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Now let's look at the Teleport implementation:
Assistant
Let me see the full Teleport file with line numbers and look specifically at the
removemethod:Assistant
me look at the related tests and understand the structure better:
Assistant
Let me look at git log to understand what was changed in the related PRs:
Assistant
Now let me look at PR #14642 for the suspense related
Assistant
Now let me reproduce the issue. First, let me look at the reproduction repository structure:
Assistant
Let me now look at the test repository to understand the issue better:
Assistant
me look at the reproduction test that the issue links to:
Assistant
Let me write a reproducer test:
Assistant
Now let me create a reproducer script:
Assistant
Let me think about this differently. The issue happens when:
- A
<Teleport>is inside a<Suspense>withparentSuspense.pendingBranchset. - The teleport's children include a component.
- The Suspense is unmounted before the teleport's pending mount can run.
The crash occurs because:
- When
removeis called on the teleport, it setsshouldRemove = false(no DOM removal). - But it still iterates through children and calls
unmount(child, ...). - For component children that were never actually mounted (still have
vnode.component === null),unmountis called on a vnode with no component, which crashes.
Let me look at the
unmountfunction to confirm this:- A
Assistant
Now let me look at
unmountComponentto understand the crashAssistant
me look at the entire
removefunction once more, and look at the existing test:Assistant
me run the existing tests first to see baseline:
Assistant
Let me create a reproducer script that closely mimics the issue:
Assistant
The first test passes because we wait for the teleport to mount. Now let me create a test that unmounts before the teleport mounts:
Assistant
Let me look at the reproduction repo's App.vue from the issue:
Assistant
Let me look at Suspense.resolve to understand the stack:
Assistant
Assistant
Now I understand the flow:
- When Suspense is shown initially,
activeBranchis the fallback (showing fallback content). - When Suspense resolves, it calls
unmount(activeBranch, ...)to remove the fallback. - The unmount cascade eventually reaches TeleportImpl.remove.
But the fallback shouldn't have a Teleport. Unless... in the reproduction, the fallback contains a Teleport?
Let me look at the reproduction repo - https://github.com/pont1s/vue-teleport-unmount-crashes.
Actually, let me check if there's a way to find it on disk or perhaps check the issue more carefully.
The issue description says:
- "Click 'Unmount Suspense'"
- The crash happens at
Suspense.resolve-> unmount -> unmountComponent -> ... -> TeleportImpl.remove
Hmm, but the crash trace starts at Suspense.resolve, which is called during the Suspense resolve process (when the default content is shown).
Wait, I wonder if the issue is that the parent of the Suspense is unmounted, and that's what triggers the Suspense to resolve its pending state (since the suspense is unmounted while still pending)?
- When Suspense is shown initially,
Assistant
Now I understand. The fix in
removeis incomplete: it setsshouldRemove = falsebut still callsunmount(child, ...)on each child, which crashes if the child is a component vnode that was never mounted (so itsvnode.component === null).Let me verify this is the issue with a proper repro:
Assistant
The test still passes. Let me try to construct a more accurate repro that matches the issue. Let me look at the Suspense resolve more carefully.
Actually, the issue says "Click Unmount Suspense", which means the Suspense itself is being unmounted (not replaced with another element). The crash is at
Suspense.resolve, which means the Suspense is being resolved.Wait, looking at the Suspense code again:
- When you call
Suspense.unmount(...), it unmounts both activeBranch and pendingBranch. - When you call
Suspense.resolve(...), it unmounts the activeBranch (fallback) and moves the pendingBranch (default) to the active state.
- When you call
Assistant
Now I understand the issue. The
pendingMountcheck inremoveonly setsshouldRemove = false(skipping DOM removal), but it still iterates through children and callsunmount(child, ...). For component children that were never mounted, this crashes becausevnode.component === null.Let me look at the actual repro to write a test that fails:
Assistant
Let me look at the resolve code more carefully:
Assistant
Let me look at the actual repro from the linked repo:
Assistant
Now I have the actual reproduction tests. Let me convert them and verify the bug:
Assistant
I've successfully reproduced the issue. The test "unmounts cleanly: pending mount + component child" fails with the exact stack trace from the issue. Now let me fix the
removefunction inTeleport.ts:Assistant
Now I have a clean reproduction matching the issue. The crash is at
unmountComponenttrying to readinstance.typewheninstanceisnull(because the child component vnode hasvnode.component === null).Now let me apply the fix:
Assistant
The edit duplicated some lines. Let me revert and re-apply the fix properly:
Assistant
Now let me apply the fix cleanly using
replace:Assistant
Now let me run the test to verify the fix:
Assistant
The fix works. Now let me clean up the repro test file and run existing tests to make sure nothing is broken:
Assistant
Now let me run the existing tests:
Assistant
All 57 Suspense tests pass and all 51 Teleport tests pass. Now let me also run the related hydration tests:
Assistant
All hydration tests pass too. Let me run the full test suite to make sure nothing is broken:
Assistant
All 3165 tests pass. Let me also run the unit-jsdom tests:
Assistant
All 377 jsdom tests pass too. Let me verify the final state of my fix:
Assistant
Let me also do a final verification by re-running the repro test (using a temporary test):
Assistant
Let me also think about edge cases. The fix uses the local
pendingMountvariable, which is the value before it's deleted from the map. Let me verify this is correct:Assistant
Let me also run the SSR Teleport tests to be safe:
Assistant
All tests pass. Let me also run the SSR Suspense tests:
Assistant
Let me do a final check to ensure the diff is clean and correct:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.