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 the issue:
- The bug is about Vue's Teleport + Suspense interaction causing a crash when unmounting
- The error is
TypeError: Cannot read properties of null (reading 'type') - The issue occurs when a
<Teleport>inside a<Suspense>is unmounted before its mount can run - The root cause is that
pendingMountswas added in PR #8619, and subsequent fixes didn't fully address theTeleportImpl.removepath
Let me start by exploring the repository structure to understand the codebase.
Assistant
This is the Vue core repository. Let me explore the packages directory to find the Teleport implementation.
Assistant
The Teleport implementation should be in runtime-dom. Let me look for it.
Assistant
Found the Teleport component in
/core/packages/runtime-core/src/components/Teleport.ts. Let me look at this file to understand the current implementation.Assistant
I need to use bash to open the file. Let me use cat or a similar approach.
Assistant
Now I understand the issue. Let me look at the
removefunction more closely and understand the full context. Let me also check the renderer to see howunmountworks.Assistant
Let me check the renderer to understand how unmount works:
Assistant
The grep returned no output. Let me try a different search.
Assistant
Let me look at the unmount and unmountComponent functions to understand the issue better.
Assistant
Let me also see the
unmountComponentfunction:Assistant
Now I understand the issue. Let me look at the
removefunction in Teleport.ts more closely:Assistant
Let me find the TeleportImpl.remove function specifically.
Assistant
Let me find the full
removefunction in the Teleport.ts file.Assistant
Now I understand the issue. Let me look at the test file mentioned in the issue to better understand the reproduction:
Assistant
Let me look at the test file for teleport:
Assistant
Let me look for existing tests in the packages:
Assistant
Assistant
Let me find the test directories.
Assistant
Let me look for existing teleport tests to understand the test patterns.
Assistant
Let me look at the existing Teleport tests.
Assistant
Let me also look at the Suspense tests for reference:
Assistant
Now I understand the issue. Let me first create a script to reproduce the error, then apply the fix.
Assistant
Let me run this reproduction script to see if it reproduces the error.
Assistant
Let me try running the existing tests first to understand the testing setup, then create a proper test.
Assistant
Let me look at the git history to understand what was changed:
Assistant
Let me now look at what commits introduced the
pendingMountscheck in the remove function.Assistant
Let me look at the commits to understand what changes were made.
Assistant
Let me look at the specific changes made in this commit to understand the pendingMount check that was added.
Assistant
Let me see more of the diff to understand how the remove function was changed in that commit.
Assistant
Now I understand the issue. When a teleport with component children is unmounted while it still has a pending mount (because it was inside a suspense with a pending branch), the
TeleportImpl.removefunction:- Correctly detects the pending mount and sets
shouldRemove = false - BUT it still iterates through children and calls
unmount()on each one - For component children that were never mounted (because the teleport was deferred),
vnode.componentis null - When
unmount()tries to callunmountComponent(vnode.component!, ...)on a component child withcomponent === null, it crashes
The fix: when there's a pending mount (meaning the teleport was never actually mounted), we should skip the entire children unmount loop because nothing was ever mounted.
Let me apply the fix:
- Correctly detects the pending mount and sets
Assistant
Now I understand the issue completely. Let me apply the fix. The problem is in the
removefunction:When there's a pending mount (teleport was never actually mounted because it was deferred), the code:
- Correctly marks the pending mount as disposed
- Sets
shouldRemove = false - BUT still iterates through children and calls
unmount()on each
For component children that were never mounted (because the teleport was deferred and never ran),
vnode.componentisnull, causingunmountComponent(null, ...)to crash.The fix: when there's a pending mount, we should skip unmounting children entirely since nothing was ever mounted.
Assistant
Now I'll apply the fix. The issue is that when there's a pending mount, the code sets
shouldRemove = falsebut still callsunmount()on children. For component children that were never mounted (because the teleport was deferred),vnode.componentis null, causing the crash.The fix: when there's a pending mount, skip unmounting children entirely since nothing was ever mounted.
Assistant
Now I'll apply the fix. I need to modify the
removefunction to skip unmounting children when there's a pending mount.Assistant
Let me use a different approach to edit the file:
Assistant
The user wants me to verify the change was applied correctly by looking at the modified file.
Assistant
The fix has been applied. Let me verify the change is correct by viewing the full
removefunction:Assistant
The fix has been applied correctly. Now let me verify by running the existing tests:
Assistant
I see the problem - my sed command was too broad and also modified the
moveTeleportfunction. Let me check the damage:Assistant
I see the problem - the sed command was too broad and also modified the
moveTeleportfunction. Let me revert the file and apply the fix more carefully.Assistant
Let me verify the fix is applied:
Assistant
Good, the file has been reverted. Now let me apply the fix more carefully - only modifying the line inside the
removefunction, not themoveTeleportfunction.Assistant
Let me use sed to only modify line 352 (which is in the
removefunction):Assistant
Let me verify the change was applied correctly:
Assistant
The fix has been applied correctly. Now let me run the existing tests to make sure everything passes:
Assistant
All 51 tests pass. Now let me run the Suspense tests to make sure the fix doesn't break anything:
Assistant
All tests pass. Now let me create a test to reproduce the specific bug and verify it's fixed. First, let me look at the reproduction repo to understand the exact test case:
Assistant
The user wants me to continue testing the fix I've applied. Let me run the test I created to verify the fix works correctly.
Assistant
Let me place the test in the proper location with the correct naming:
Assistant
The user wants me to continue from where I left off. I was trying to run a test file to verify my fix works correctly. Let me run the test now.
Assistant
The test shows that the fix is working - it didn't crash with the original
TypeError: Cannot read properties of null (reading 'type')error. The test failures are just about assertion expectations, not about the actual bug. Let me fix the test assertions:Assistant
The user wants me to run the test I just updated to verify the fix works. Let me run the test now.
Assistant
The test is failing because it's not properly wrapping things in a Suspense. Let me fix the test to properly use Suspense:
Assistant
The user wants me to run the test I just updated to verify the fix works. Let me run the test now.
Assistant
All tests pass. Let me now run the full existing test suites for Teleport and Suspense to make sure my fix doesn't break anything:
Assistant
Let me clean up the temporary test file I created (since the instructions say not to modify tests or add new tests to the repository) and verify the final state:
Assistant
Let me verify the fix by viewing the git diff:
Assistant
The fix is correctly applied. Let me run a broader test suite to make sure nothing is broken:
Assistant
All 1014 tests in the runtime-core package pass, including the Teleport and Suspense tests. Let me summarize the fix:
Summary
Issue: When a
<Teleport>inside a<Suspense>is unmounted before its mount can run (becauseparentSuspense.pendingBranchis set), Vue throwsTypeError: Cannot read properties of null (reading 'type').Root cause: In the
TeleportImpl.removefunction, when a teleport has a pending mount (deferred because of a parent suspense with a pending branch), the code correctly clears the pending mount and setsshouldRemove = false. However, it still iterated through children and calledunmount()on each. For component children that were never mounted (because the teleport was deferred and never actually mounted),vnode.componentisnull, causingunmountComponent(null, ...)to crash atinstance.type.Fix: Added a check for
!pendingMountbefore the children unmount loop. When there's a pending mount, the teleport was never actually mounted (its children were never mounted either), so there's nothing to unmount in the children loop.The fix is minimal (one line change) and all existing tests pass.
Assistant
The user wants me to submit my changes. I need to call the submit command properly.
Assistant
The user wants me to submit my changes. I've already fixed the issue and verified it works. I need to call the submit command to submit my work. Let me use the submit tool.
Assistant
The user is trying to submit their changes using the submit command. I need to call the submit tool with the correct syntax. Looking at the function definition, submit takes an optional
messageparameter. Let me try calling it correctly.Assistant
Let me verify my fix is still in place and then submit:
Assistant
Let me run the tests one more time to confirm everything still passes, then submit:
Assistant
All tests pass. Let me verify the fix one more time by checking the complete changed file:
Assistant
The user wants me to submit my changes. I've already:
- Identified the issue
- Applied the fix
- Verified all tests pass
- Cleaned up temporary test files
The only change is a single-line modification in the Teleport.ts file that adds a
!pendingMountcheck before unmounting children. This is the correct fix for the issue described.Now I need to submit my changes using the submit command.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.