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 exploring the repository structure to understand what we're working with.
Assistant
Let me look at the full
removemethod and understand the issue:Assistant
Let me look at the
TeleportImpl.removefunction more carefully to understand the issue.Assistant
Now let me find the unmount function to understand what happens:
Assistant
Let me look at the unmount function more carefully to understand the exact issue:
Assistant
Let me check the git history of this file:
Assistant
Let me set up a test to reproduce the issue:
Assistant
Let me look at the existing tests to understand how to set up:
Assistant
Now let me look at how Suspense tests are structured to understand the framework:
Assistant
me create a temporary test to reproduce the issue:
Assistant
Let me check how Vue test setup works in this repo. The
compileanddomRenderneed the runtime-dom, but I see they usevue. Let me also look at how Suspense tests are typically done:Assistant
Let me look for existing test patterns with deferred teleport and Suspense:
Assistant
me look at the issue's reproduction repo. Let me create a temporary test file in the existing test folder structure:
Assistant
Let me run the temporary test file I created to see if it reproduces the issue:
Assistant
I've reproduced the issue. Now I can see the exact problem. Let me look at the trace:
TypeError: Cannot read properties of null (reading 'type') ❯ unmountComponent packages/runtime-core/src/renderer.ts:2317:29In
unmountComponent:if (__DEV__ && instance.type.__hmrId) { // Line 2317 - throws here unregisterHMR(instance) }When
instanceis null. The current code inTeleportImpl.removesetsshouldRemove = falsewhen there's a pendingMount, but still iterates over the children callingunmounton each. For component vnodes that have not been mounted yet (because the teleport was deferred),child.componentis null, andunmountcallsunmountComponent(null, ...), which crashes.Let me look at the relevant section again to understand the existing logic:
Assistant
Now I understand the issue. Let me look at the moveTeleport function for the pattern used:
Assistant
Now I understand the fix. The
moveTeleportfunction already has thependingMounts.has(vnode)guard pattern, but theremovemethod doesn't. Let me apply the fix:Assistant
me look at the exact lines to make sure I get the replacement right:
Assistant
Let me use a different approach to make the edit. Let me use the
editcommand:Assistant
Now let me run the temporary test to verify the fix works:
Assistant
fix works. Now let me think about edge cases. Let me add more test scenarios to my temporary test file:
Assistant
All tests pass with the fix. Now let me run the existing Teleport and Suspense tests to make sure I didn't break anything:
Assistant
All existing Teleport and Suspense tests pass. Let me also run the broader runtime-core tests to make sure nothing else is broken:
Assistant
1019 tests pass. Let me also run the vue package tests:
Assistant
Let me look at the test for the update case:
Assistant
Let me check what calls
remove:Assistant
Let me look at how Suspense handles unmount:
Assistant
OK so when Suspense is unmounted:
activeBranchis unmounted withdoRemove(the one passed to Suspense's unmount)pendingBranchis unmounted withdoRemove(same)
And in the Suspense's resolve path:
activeBranch(which is the placeholder) is unmounted withdoRemove = true:
unmount(activeBranch, parentComponent, suspense, true)So when the Suspense is unmounted (the user clicks "Unmount Suspense" in the reproduction),
doRemovepropagates through to the teleport, then to the children.In my reproduction, the show is set to false, which causes Suspense to be unmounted via patch. Let me check that path:
Assistant
Let me also test by creating the exact scenario described in the issue with templates:
Assistant
Let me investigate the template-based test failure:
Assistant
Let me look at what calls resolve:
Assistant
The template test fails for a different reason (Suspense multi-root slot issue). Let me remove that test since it's not the issue we're addressing:
Assistant
All 5 tests pass. Let me verify by temporarily reverting the fix to confirm my test would fail without it:
Assistant
The tests fail without the fix, confirming my reproduction is correct. Now let me re-apply the fix:
Assistant
Now let me run the entire test suite once more to confirm nothing is broken:
Assistant
All tests pass. Let me also run the full test suite to be extra sure:
Assistant
The only failures are e2e tests (need a browser, can't run here) and a performance test (environment-specific). My fix doesn't break any tests.
Let me clean up my temporary test file:
Assistant
Let me check my final diff:
Assistant
me look at the final file to confirm the fix is clean:
Assistant
run the relevant tests one more time to confirm everything is good:
Assistant
All 175 tests pass for the components. Let me also confirm by looking at the final state of the change:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.