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
Let me start by understanding the issue:
- There's a regression since Vue 3.5.31 related to Teleport + Suspense
- When a
<Teleport>inside a<Suspense>is unmounted before its mount can run, Vue throws:TypeError: Cannot read properties of null (reading 'type') - The issue traces back to PR #8619 which introduced
pendingMountsfor teleports - PR #14642 added a
pendingMountcheck that gates DOM removal of element children, but not theunmountComponent(null, …)call on component children - PR #14702 added
pendingMounts.has(vnode)guard, but only inmoveTeleport, not inTeleportImpl.remove
So the fix should be adding a similar guard in the
TeleportImpl.removepath.Let me first explore the repository structure and find the relevant code.
Assistant
Let me find the Teleport-related source code.
Assistant
The key files are:
/core/packages/runtime-core/src/components/Teleport.ts/core/packages/runtime-core/src/renderer.ts
Let me look at the Teleport.ts first.
Assistant
Let me just read the file with cat.
Assistant
The output was truncated. Let me see the full remove function:
Assistant
Let me read from line 317 onwards.
Assistant
Now I can see the issue. Let me also check how
unmounthandles thedoRemoveparameter and where the crashAssistant
Let me look at the unmount function and unmountComponent.
Assistant
Now I have a clear understanding of the issue. Let me also check the existing tests for teleport
Assistant
Let me search for existing tests related to
pendingMountor the specific issue.Assistant
Let me verify the
moveTeleportpattern more clearly, and also look at the exact code we need to change:Assistant
Now I have a clear understanding. The fix is to skip unmounting children when there's a pending mount (children never mounted). This mirrors the existing
!pendingMounts.has(vnode)guard inmoveTeleport.The change is on line ~350: change
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN)toif (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount).Let me apply the fix:
Assistant
Let me try a different approach. Let me use a simpler replace strategy
Assistant
Let me use sed to make the precise edit.
Assistant
I see the exact line. Let me use sed to make the change
Assistant
Let me verify the change:
Assistant
Let me verify line 399 is the
moveTeleportone that should NOT be changed:Assistant
Good - line 399 is in
moveTeleportand it already has the outer guard!pendingMounts.has(vnode), so it doesn't need changes.Now let me run the existing teleport tests to make sure nothing is broken
Assistant
All 51 teleport tests pass. Let me also run Suspense tests since this is about Teleport + Suspense interaction
Assistant
All tests pass. Let me also run the full runtime-core test suite to be thorough
Assistant
All 1014 tests pass. Let me verify my change is correct with git diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.