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.
- Assistant
Let me look at the issue more carefully. The issue is about a crash when unmounting a Teleport inside a Suspense before its mount can run. The error is
TypeError: Cannot read properties of null (reading 'type')atunmountComponent.Let me find the relevant source files.
- Assistant
Let me look at the Teleport implementation and the renderer to understand the issue.
- Assistant
Let me look at the Teleport component implementation and the renderer to understand the issue.
- Assistant
Now let me look at the renderer.ts to understand the
unmountandunmountComponentfunctions: - Assistant
Let me look at the
unmountfunction in the renderer.ts to understand how it handles different vnode types. - Assistant
Let me look at the
unmountComponentfunction: - Assistant
Now I understand the issue. Let me look at the exact
removemethod in the Teleport implementation: - Assistant
Let me see the full remove method:
- Assistant
Now I understand the bug. When a Teleport has a pending mount (deferred because of parent Suspense), its children were never actually mounted, so
vnode.componentisnullfor component children. Theremovemethod setsshouldRemove = falseto prevent DOM removal, but still callsunmount()on each child. For component children,unmount()callsunmountComponent(vnode.component!, ...)which crashes becausecomponentisnull.The fix is to skip unmounting children entirely when there's a pending mount, since nothing was ever mounted. Let me create a reproduction first to confirm:
- Assistant
Let me find existing tests to understand the test structure.
- Assistant
Let me look at existing Teleport tests to understand how they test Teleport and Suspense together.
- Assistant
Let me look at the Teleport tests to understand the test patterns:
- Assistant
Now I understand the issue clearly. Let me examine the
removemethod more carefully and apply the fix: - Assistant
Now I understand the issue. When there's a pending mount, the code correctly sets
shouldRemove = falsebut still iterates through children and callsunmount(). For component children that were never mounted,vnode.componentisnull, causing the crash. The fix should skip unmounting children entirely when there's a pending mount.Let me apply the fix:
- Assistant
Now let me look at the
removemethod: - Assistant
Now I can see the issue clearly. The comment on line 336 says "skip removing children because nothing has been mounted yet" but the code only sets
shouldRemove = false— it doesn't actually skip theunmount()loop. Theunmount()on component children withvnode.component === nullstill runs, and that crashes.The fix: when there's a pending mount, skip the children loop entirely (similar to how
moveTeleportalready guards with!pendingMounts.has(vnode)). - Assistant
Let me use the correct syntax for the edit command.
- Assistant
The fix looks correct. Let me verify the full remove method:
- Assistant
Now let me run the existing Teleport tests to make sure the fix doesn't break anything:
- Assistant
Let me run the tests for the Teleport component.
- Assistant
All 51 Teleport tests pass. Let me also run the Suspense tests:
- Assistant
Both test suites pass. Now let me create a reproduction script to confirm the fix works for the specific issue:
- Assistant
Let me look at the existing Teleport + Suspense tests in the test file to understand patterns:
- Assistant
Let me check how the renderer unmount function handles null component:
- Assistant
Now let me verify the fix by building and running the relevant tests. Let me also create a proper test to reproduce the exact scenario:
- Assistant
Let me create a temporary test to verify the fix addresses the reported issue:
- Assistant
Let me look at how the existing tests use
domRender: - Assistant
Let me look at the domRender function used in tests to understand how it works:
- Assistant
Let me write a proper test matching the existing test patterns:
- Assistant
Let me first build the project to make sure my change compiles:
- Assistant
All tests pass. Now let me write a quick reproduction test to verify the exact scenario. Let me check what test infrastructure is available:
- Assistant
Let me write a simple test to verify the fix handles the specific case from the issue:
- Assistant
Let me place the test within the repo:
- Assistant
Let me fix the test - the initial HTML expectation is wrong:
- Assistant
Let me look at how the existing tests use domRender and access the app:
- Assistant
Let me look at how the tests trigger unmounting from Suspense. Let me look at the Suspense tests to see how they handle this pattern.
- Assistant
Let me look at a specific test that does "unmount suspense before resolve" to see the pattern:
- Assistant
Let me write a proper test using the same patterns as the existing Suspense tests:
- Assistant
The test passes with my fix. Let me verify that without the fix, this test would have failed by temporarily reverting:
- Assistant
The test fails without the fix (exactly the crash described in the issue). Let me restore the fix:
- Assistant
Now let me run all the relevant tests together to make sure nothing is broken:
- Assistant
All 109 tests pass. Let me also run the full unit test suite to make sure nothing else is broken:
- Assistant
The only failure is a flaky performance test (
should not lead to exponential perf cost with deeply chained computed- 30.3ms vs 30ms threshold) which is unrelated to my change. All 3165 other tests pass including all Teleport and Suspense tests.Let me clean up the temporary test file:
- Assistant
Let me verify the final state of the changed file:
- Assistant
The change is minimal and correct - a single line change. Let me verify the final diff and run the specific tests once more:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.