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
Let me analyze this issue step by step:
- The issue is about a crash when unmounting a Teleport inside a Suspense before its mount can run.
- The crash occurs because
vnode.componentisnullwhen trying to unmount. - The problem was partially fixed in PR #14702 for
moveTeleport, butTeleportImpl.removewas not fixed.
Let me start by exploring the repository structure and understanding the codebase.
Assistant
Let me look at the packages directory structure, particularly for the runtime-core package which contains Teleport and Suspense.
Assistant
Let me look at the runtime-core package, which contains the Teleport and Suspense implementations.
Assistant
Let me look at the Teleport implementation. It's likely in the components directory.
Assistant
Let me read the Teleport.ts file to understand the current implementation:
Assistant
Let me look at the
TeleportImpl.removefunction more closely, specifically the area around line handling component children:Assistant
Let me look at the full
removefunction and the unmount path:Assistant
Let me fix the command syntax for sed.
Assistant
Now I understand the issue. Let me look at how
unmounthandles component children in the renderer:Assistant
Let me look at the unmount and unmountComponent functions:
Assistant
Now I understand the issue completely. Let me look at the relevant test files and also the related PRs to confirm my understanding.
Assistant
Now I fully understand the issue. Let me look at the test file to understand the testing patterns:
Assistant
Let me look at the
unmountfunction more closely to understand where the error occurs:Assistant
Now I fully understand the issue. Let me summarize:
- When a Teleport is inside a Suspense that has a pending branch,
queuePendingMountis called which defers mounting viapendingMounts. - When the Teleport is unmounted before the pending mount runs,
TeleportImpl.removeis called. - The current fix sets
shouldRemove = falsebut still iterates over children and callsunmounton each. - For component children that were never mounted,
vnode.componentisnull, causing the crash in theunmountfunction when it tries to callunmountComponent(vnode.component!, ...).
The fix is to skip the children unmount loop entirely when there's a pending mount (since nothing was ever mounted).
Let me implement the fix:
- When a Teleport is inside a Suspense that has a pending branch,
Assistant
Let me open the file first.
Assistant
The
opencommand seems to be interpreted differently. Let me try with theeditcommand using the--fileoption.Assistant
Let me use bash to make the edit directly:
Assistant
Now I understand the issue. Looking at the
removefunction:- When there's a pending mount (teleport deferred),
shouldRemove = falseis set - The comment says "skip removing children because nothing has been mounted yet"
- But the code at lines 352-363 still loops through children and calls
unmount()on them - The
unmount()function doesn't checkshouldRemove- it always tries to process component children - When a component child was never mounted (because the pending mount was cancelled),
vnode.componentisnull, causing the crash
The fix: when there's a pending mount, skip the children unmount loop entirely.
- When there's a pending mount (teleport deferred),
Assistant
Let me check if the change was applied correctly.
Assistant
The comment indentation is off. Let me fix this properly:
Assistant
Let me try with python instead of python3
Assistant
Let me fix it using sed:
Assistant
Let me verify the change:
Assistant
The fix looks good. Now let me verify the fix by examining the codebase more carefully and then creating a test to confirm it works.
Let me look at existing test patterns for Teleport:
Assistant
Let me look at more of the test file to understand the testing patterns. I need to find how tests are written for suspense-related teleport scenarios.
Assistant
Let me look at the Suspense test file to understand how to write tests for this scenario:
Assistant
Let me look at the existing test about teleport with component children inside suspense:
Assistant
Now let me look at how to create a test that reproduces the issue. Let me first check if there are existing tests for this specific scenario:
Assistant
Now let me create a test script to reproduce the bug and verify my fix works:
Assistant
Let me first understand the repository structure better and find the test configuration:
Assistant
Let me look at the package.json to understand how to run tests.
Assistant
Let me run the existing tests for Teleport and Suspense to ensure my fix doesn't break anything:
Assistant
Let me try a different approach - run the test with a timeout:
Assistant
Let me write a simple reproduction script instead:
Assistant
The reproduction script confirms my fix is correct. Now let me verify the actual fix in the Teleport.ts file and make sure it matches what I intended:
Assistant
The fix looks correct. Now let me verify it works with the actual tests. Let me check if there's a simpler way to run tests:
Assistant
I see there are 2 failing tests. Let me examine the failing test to understand the issue:
Assistant
Let me look at this failing test to understand what it expects.
Assistant
Let me examine the current state of the fix more carefully:
Assistant
I see the issue with my fix. Let me understand the failing test better. The test has a
disabled: trueteleport. Let me trace through:- For disabled teleport:
shouldRemove = doRemove || !isTeleportDisabled(props)=doRemove || true=true
So with my fix,
shouldRemove = trueand children should still be unmounted. Let me debug this:- For disabled teleport:
Assistant
Let me check what changed in my fix more carefully:
Assistant
I see the issue. Let me trace through more carefully. The
shouldRemovevariable serves a different purpose than I thought. Let me examine the logic again:Assistant
I see the issue now. Let me examine what
shouldRemove(which isdoRemove) does in theunmountfunction when called on children:Assistant
Let me re-examine the issue. I think my fix is too aggressive - it's skipping unmounting children for disabled teleports when
shouldRemoveis false. Let me look at the original code logic more carefully:Assistant
Let me look more carefully at what
shouldRemoveactually represents and whendoRemovecould be false:Assistant
Now I need to understand the issue better. The
shouldRemovevariable is passed tounmountfor each child. Let me look at whatunmountdoes withdoRemove:In the original code:
shouldRemove = doRemove || !isTeleportDisabled(props)- this means shouldRemove is true if doRemove is true OR if the teleport is not disabled- When there's a pending mount,
shouldRemove = false
Assistant
I understand the issue now. The
shouldRemoveflag has two meanings:- When
shouldRemove = falsedue to a pending mount → children were never mounted - When
shouldRemove = falsedue to a disabled teleport +doRemove=false→ children ARE mounted
My fix incorrectly skips unmounting in case 2 as well, which breaks the test. I need a more targeted approach.
Let me revert my change and implement a proper fix:
- When
Assistant
Now let me implement the correct fix. The key insight is that when there's a pending mount, the children were never mounted, so we should completely skip unmounting them. We shouldn't use
shouldRemovefor this purpose becauseshouldRemovehas a different meaning for disabled teleports.Assistant
Now let me implement the correct fix. The key insight is that when there's a pending mount, nothing was ever mounted, so we should skip unmounting children entirely. We need to track whether there was a pending mount separately:
Assistant
Let me use a different approach with sed to make the fix:
Assistant
Let me try again with history expansion disabled.
Assistant
Let me use sed to make the targeted changes:
Assistant
Let me make the changes step by step using sed:
- Add
let isPendingMount = falseafter line 337 - Add
isPendingMount = trueinside the if block after line 342 - Change line 352 to add
!isPendingMount &&beforeshapeFlag
- Add
Assistant
Let me verify the change and continue with the remaining edits.
Assistant
Good, first change is done. Now I need to:
- Add
isPendingMount = trueafter line 343 (inside the if block) - Change line 353 to add
!isPendingMount &&beforeshapeFlag
- Add
Assistant
Let me verify the change and continue with the remaining edit.
Assistant
Now I need to change line 354 to add
!isPendingMount &&beforeshapeFlag:Assistant
Let me verify the final state of the fix:
Assistant
The fix looks correct. Let me now verify with git diff and run the tests:
Assistant
The fix looks correct. Let me run the tests to verify it works:
Assistant
All 51 Teleport tests pass now. Let me also run the Suspense tests to make sure the teleport-related tests there also pass:
Assistant
All 57 Suspense tests pass as well, including the teleport-related ones. Now let me verify that my fix actually resolves the issue by creating a test case that reproduces the original bug:
Assistant
The fix works correctly for all test cases. Let me run a broader set of tests to ensure nothing is broken:
Assistant
All 1014 runtime-core tests pass, including all Teleport and Suspense tests. Let me verify the final state of my changes:
Assistant
All tests pass. Let me provide a summary of the fix:
Summary
The issue was a crash when unmounting a
<Teleport>inside a<Suspense>before its mount can run. The crash occurred because:- When a Teleport is inside a Suspense with a pending branch, its mount is deferred via
pendingMounts. - If the Teleport is unmounted before the pending mount runs,
TeleportImpl.removeis called. - The original code set
shouldRemove = falsewhen there's a pending mount, but still iterated through children callingunmount()on them. - For component children that were never mounted (because the pending mount was cancelled),
vnode.componentisnull. - When
unmount()is called with such a child, it tries to accessvnode.component.typewhich throwsTypeError: Cannot read properties of null (reading 'type').
The fix adds an
isPendingMountflag that tracks whether the teleport had a pending mount. When unmounting, if there was a pending mount, we skip the children unmount loop entirely since nothing was ever mounted. This is more precise than using because has a different meaning for disabled teleports.- When a Teleport is inside a Suspense with a pending branch, its mount is deferred via
Assistant
The submit command needs to be called properly. Let me just call it directly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.