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 to understand the codebase and locate the relevant files. Let's first see what's in the current directory.
- Assistant
Let me look at the Teleport implementation to understand the issue.
- Assistant
Let me look at the Teleport implementation file.
- Assistant
Let me look at the TeleportImpl.remove method specifically.
- Assistant
Let me look at the
removemethod in Teleport.ts to understand the issue. - Assistant
Now I understand the issue. Let me look at the
unmountfunction in renderer.ts to see how it handles components: - Assistant
Let me look at the
unmountComponentfunction to understand the issue. - Assistant
Now let me look at the
unmountfunction to see how it handles component vnodes: - Assistant
Now I understand the issue. In
TeleportImpl.remove, when there's apendingMount, we setshouldRemove = falsebut still callunmounton children. When children are components that were never mounted,vnode.componentisnull, causing the crash.The fix is to skip unmounting children entirely when there's a pending mount, since nothing was ever mounted:
- Assistant
Now I understand the issue. When a Teleport has a pending mount (never mounted yet), we correctly set
shouldRemove = false, but we still callunmounton each child. When a child is a component that was never mounted,vnode.componentisnull, causing the crash.The fix: when there's a pending mount, we should skip unmounting children entirely since nothing was ever mounted. Let me also check how
unmounthandles components: - Assistant
Let me check the
moveTeleportfunction to see how it handles pending mounts: - Assistant
Now I understand the issue. When a teleport has a pending mount (never mounted), the
removemethod correctly marks the pending mount as disposed but still callsunmounton each child. For component children,unmountComponentis called withvnode.component!which isnullsince the component was never mounted.The fix is to skip the unmounting of children when there's a pending mount, because nothing was ever mounted. Let me apply the fix:
- Assistant
I see there's a duplicate line and an extra closing brace. Let me fix that:
- Assistant
I see there's still a duplicate line. Let me look at the file more carefully:
- Assistant
I see multiple issues - there's a duplicate
let shouldRemoveline and a duplicate},. Let me fix this properly by resetting to the original and doing the edit correctly: - Assistant
Now let me look at the exact original file again and make a clean edit:
- Assistant
Now I'll make a clean edit - just change the condition on the children unmount loop:
- Assistant
Let me use the heredoc syntax for the edit command.
- Assistant
The edit didn't work correctly - it inserted the new line without removing the old one. Let me revert and try again:
- Assistant
Let me use sed to make the change directly:
- Assistant
I need to replace the
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {line withif (!pendingMount && shapeFlag & ShapeFlags.ARRAY_CHILDREN) {along with a comment. Let me use sed to do this. - Assistant
Let me check if the edit was applied correctly.
- Assistant
The fix looks correct. Now let me verify the full context:
- Assistant
The fix looks correct. Let me verify the diff:
- Assistant
The diff is clean and minimal. Now let me run the existing teleport-related tests to make sure nothing is broken:
- Assistant
Let me check the build/test setup:
- Assistant
Let me check what testing framework is used.
- Assistant
Now let me run the Teleport tests to make sure nothing is broken:
- Assistant
All 51 Teleport tests pass. Let me also run Suspense tests:
- Assistant
All tests pass. Now let me create a reproduction test to verify the fix resolves the reported issue:
- Assistant
Hmm, looks like the file only has 1 line. Let me check the content.
- Assistant
Let me write the test file using bash:
- Assistant
Now let me run the test to verify the fix:
- Assistant
The test file isn't being found by vitest because it's outside the project. Let me move it into the project structure.
- Assistant
Let me check how existing tests set up the teleport target:
- Assistant
Let me look at how they use runtime-test nodeOps in the existing test file:
- Assistant
Let me look at the test at line 106 which is about "update before mounted with defer" and at line 243 "should not mount discarded teleport after deferred updates":
- Assistant
Let me look at the Suspense tests for teleport patterns:
- Assistant
Let me look at the Suspense tests around line 2484 and 2525:
- Assistant
Let me look at the test around line 65 - the "defer mode should work inside suspense":
- Assistant
Now I understand the patterns. Let me write a proper reproduction test:
- Assistant
Let me copy the test file into the test directory and run it:
- Assistant
All 3 tests pass with my fix. Let me verify the test would fail without my fix to ensure it's testing the right thing:
- Assistant
The tests fail without the fix (crash in
unmountComponentwith null component), confirming the fix is correct. Let me restore the fix: - Assistant
Now let me run all the Teleport and Suspense tests again to confirm everything passes:
- Assistant
All 108 tests pass. Let me clean up the test file and run a broader set of tests:
- Assistant
All 1014 tests pass across all 44 runtime-core test files. Let me verify the final diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.