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
I'll start by exploring the repository to understand the codebase and locate relevant files. Let's first check the current directory and see what's there.
- Assistant
Let me explore the repository structure to understand the codebase and find the relevant files for the teleport and suspense implementation.
- Assistant
Let me search more broadly.
- Assistant
Now let's look at the Teleport implementation, specifically the
removemethod and theunmountComponentfunction. Let me first examine the Teleport.ts file. - Assistant
Let me scroll down to see the
removemethod and the relevant unmount logic. - Assistant
Let me look at the remove method in detail.
- Assistant
Now I need to understand the issue better. Let me look at the unmount function in the renderer to see where the crash occurs. The issue mentions that
unmountComponentis called with a null component. Let me find the renderer file. - Assistant
Let me look at the unmountComponent function in renderer.ts to understand where the null check is missing.
- Assistant
Let me look at the unmount function and unmountComponent to understand the flow.
- Assistant
Let me look at the unmount function:
- Assistant
Let me check the unmount function to see how it handles the case where component might be null.
- Assistant
Let me look more closely at the remove method and understand the flow:
- Assistant
Now I understand the issue. Looking at the
removemethod in Teleport.ts:When there's a
pendingMount(teleport content was never mounted), the code correctly setsshouldRemove = false, but it still callsunmount()on each child. For component children,unmount()callsunmountComponent(vnode.component!, ...)which will crash becausevnode.componentis null (the component was never mounted).The fix is to skip the children unmount loop entirely when there's a pending mount, since the children were never mounted.
Let me first create a reproduction test:
- Assistant
Let me look at the reproduction repository to understand the exact issue. First, let me check the
unmountfunction in renderer.ts more carefully: - Assistant
Now I understand the issue clearly. The problem is in the
TeleportImpl.removemethod:When there's a
pendingMount(children were never mounted), the code correctly setsshouldRemove = falsebut still iterates over children and callsunmount(). For component children,unmount()callsunmountComponent(vnode.component!, ...)butvnode.componentisnullbecause the component was never mounted. This crashes atinstance.typeinunmountComponent.The fix is to skip the children unmount loop entirely when there's a pending mount, similar to how
moveTeleporthandles it.Let me apply the fix:
- Assistant
Let me verify the change looks correct:
- Assistant
Good, the fix is in place. Now let me run the existing tests to make sure nothing is broken:
- Assistant
Let me check how to run tests in this repo.
- Assistant
Let me also run the Suspense tests:
- Assistant
Now let me write a test to reproduce the crash and verify it's fixed:
- Assistant
Let me create the test in the proper location:
- Assistant
Let me check how existing Teleport tests work:
- Assistant
Let me look at how the tests create their test environment for teleport:
- Assistant
Let me look at the specific suspense+deferred teleport test at line 65:
- Assistant
Let me create a proper reproduction test:
- Assistant
Let me verify the fix works by temporarily reverting it and running the test again to confirm it was actually crashing before:
- Assistant
Let me temporarily revert the change to verify the test fails without it:
- Assistant
The test passes without the fix too, so my test doesn't reproduce the exact issue. Let me look at the Suspense resolve method to understand the exact crash path:
- Assistant
Let me look at the Suspense resolve method to understand how the unmount path works:
- Assistant
Let me look at the resolve method more closely:
- Assistant
Let me look at the unmount method of the Suspense:
- Assistant
Let me look at the unmount method at line 780:
- Assistant
Let me look at how the mountJob is set up in Teleport.ts to understand when children are actually mounted:
- Assistant
Now I understand the flow. When a teleport is inside a pending suspense (
parentSuspense.pendingBranchis set), the teleport defers its mount viaqueuePendingMount. At this point, children are NOT mounted. ThemountJobsets up the actual mounting of children. If the teleport is unmounted before themountJobruns (because the suspense itself is being unmounted), the children'scomponentis still null.My fix correctly skips the children unmount loop when
pendingMountexists (meaning children were never mounted). This matches the pattern already used inmoveTeleporton line 397.Let me clean up the test file and run all existing Teleport and Suspense tests:
- Assistant
Let me write a more accurate reproduction that matches the issue description:
- Assistant
Let me verify the fix works properly by reverting, reproducing the crash, then re-applying the fix:
- Assistant
Let me create a proper test to reproduce the crash:
- Assistant
The test files need to have the
.testor.specextension. Let me rename the file. - Assistant
The crash is reproduced. Now let me apply my fix and verify it passes:
- Assistant
Now let me run the test again with my fix applied:
- Assistant
The fix works. Let me clean up the test file and run the full Teleport and Suspense test suites to ensure nothing is broken:
- Assistant
All 108 tests pass. Let me also run the broader runtime-core test suite:
- Assistant
All 1014 tests pass. Let me also run the vue package tests to be safe:
- Assistant
The vue package failures are all e2e browser tests (puppeteer) that can't run in this environment - completely unrelated to my change. Let me verify my final change:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.