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:
- The problem is about a Vue.js Teleport + Suspense unmount crash
- The crash happens when a Teleport inside a Suspense is unmounted before its mount can run
- The error is
TypeError: Cannot read properties of null (reading 'type')atunmountComponent - The issue is in
TeleportImpl.removepath, which wasn't fixed in previous patches
Let me start by exploring the repository structure to understand the codebase.
Assistant
This is the Vue.js core repository. Let me explore the structure to find the relevant Teleport and Suspense code.
Assistant
The Teleport component is likely in runtime-dom or runtime-core. Let me look for the Teleport implementation.
Assistant
Let me look at the Teleport.ts file to understand the issue.
Assistant
Now I can see the
TeleportImpl.removefunction. The issue is clear from the description:- The
pendingMountcheck inremovehandles clearing the pending mount for element children, but doesn't handle the case where teleport children are components that haven't been mounted yet. - When
unmountis called on a component child whose component hasn't been set (because the teleport never mounted), it crashes trying to readcomponent.type.
Let me look at the
unmountfunction to understand exactly how it handles component children.- The
Assistant
Let me look at the renderer.ts file to understand the unmount logic.
Assistant
Let me look at the specific lines in the renderer around the
unmountfunction to understand how it handles component children.Assistant
Now I understand the issue clearly. Let me look at the
TeleportImpl.removefunction more closely:Assistant
Let me look at the
TeleportImpl.removefunction more closely:Assistant
Now I understand the issue. Let me look at the
unmountfunction to see where the crash happens with null component:Assistant
Now I understand the issue. Let me look at the git history to see what previous fixes looked like:
Assistant
Now I fully understand the issue. Let me look at the unmountComponent function to see exactly what happens:
Assistant
Now I have a clear understanding of the issue:
- When a Teleport is deferred (inside a Suspense with
pendingBranch), its children are queued for deferred mounting viaqueuePendingMount. - If the Teleport is unmounted before mounting,
pendingMountis cleared andshouldRemove = falseis set. - However, the code still iterates over children and calls
unmount(child, ...)on each. - If a child is a component,
unmountcallsunmountComponent(vnode.component!, ...), but since the teleport never mounted,vnode.componentisnull, causing the crash.
The fix should skip unmounting children when
pendingMountexists, because nothing has been mounted yet.Let me first create a test script to reproduce the issue, then apply the fix.
- When a Teleport is deferred (inside a Suspense with
Assistant
Let me look for existing tests related to teleport and suspense.
Assistant
Let me try a different approach to find test files.
Assistant
Let me continue looking for test files, specifically for Teleport tests.
Assistant
Let me look at the existing Teleport tests to understand how tests are structured.
Assistant
Now let me look at how they test Suspense + Teleport scenarios:
Assistant
Let me look at some specific tests around unmount with teleport in suspense:
Assistant
Let me write a test to reproduce the issue:
Assistant
Let me write a more focused reproduction script:
Assistant
Let me run this test to reproduce the issue. But first, let me check how to run TypeScript files in this project.
Assistant
Let me look at the runtime-test package to understand what it exports.
Assistant
The runtime-test exports everything from @vue/runtime-core, so Suspense should be available. Let me check if it's exported from runtime-core.
Assistant
It seems the issue might be with module resolution. Let me try running the tests using vitest instead, as that's how this project runs tests. Let me write a proper test file in the existing test suite.
Assistant
Good, the test framework works. Let me create a proper reproduction test.
Assistant
Let me look at the issue more carefully. The comment in the code says "skip removing children" but the code still iterates over them.
Assistant
Now I understand the issue completely. The problem is:
- When
pendingMountexists, the code setsshouldRemove = falsebut still iterates over children and callsunmount()on each. - When a child is a component,
unmount()callsunmountComponent(vnode.component!, ...), butvnode.componentisnullbecause the teleport never mounted.
The fix is simple: when
pendingMountexists, we should skip the children unmounting loop entirely since nothing has been mounted yet.Let me verify this understanding by looking at the
unmountfunction for components:- When
Assistant
Now I fully understand the issue. Let me apply the fix. The problem is in
TeleportImpl.remove:When
pendingMountexists (meaning the teleport never got mounted because suspense was still pending), the code setsshouldRemove = falsebut still iterates over children and callsunmount()on each. If a child is a component,unmount()callsunmountComponent(vnode.component!, ...), butvnode.componentisnullbecause the teleport never mounted.The fix is to skip unmounting children entirely when
pendingMountexists, since nothing has been mounted yet.Assistant
Now I need to apply the fix. The fix should be to skip unmounting children when
pendingMountexists, since nothing has been mounted yet. Let me apply the change:Assistant
Let me apply the fix directly using the edit command instead.
Assistant
Now let me apply the fix. The issue is that when
pendingMountexists (meaning the teleport never mounted because suspense was still pending), the code still tries to unmount children, which crashes when a child is a component (sincevnode.componentis null).Assistant
Let me use the replace command to fix the issue. The fix is to add a check for
!pendingMountin the condition that unmounts children.Assistant
I need to use the proper
replacecommand format. Let me use the correct syntax.Assistant
Let me use the
--fileoption:Assistant
The replace command needs to use a relative path from the current directory. Let me use the correct path.
Assistant
Let me verify the change was applied correctly:
Assistant
Good, the fix has been applied. Now let me verify that existing tests pass and then create a test to confirm the fix resolves the issue.
Assistant
I see the fix is causing test failures. Let me analyze the issue more carefully by looking at the error details:
Assistant
I see the issue - my change is too broad. Let me examine the file more carefully to understand why this broke:
Assistant
I see! The
sedcommand replaced the same pattern in both theremovefunction and themoveTeleportfunction. I need to revert this and make a more targeted fix. Let me fix this properly:Assistant
I see the problem - my sed command also changed the moveTeleport function which already has proper guards. Let me revert and apply a more targeted fix.
Assistant
Now let me look at the original file again and apply a more targeted fix.
Assistant
Now I'll apply a targeted fix only to the
removefunction's condition, being more precise with the sed command:Assistant
Let me use a more precise sed command to only change line 352:
The issue is:
- Line 352 has:
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) { - We need to change it to:
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {
But I need to be careful to only change this occurrence in the
removefunction, not inmoveTeleport.- Line 352 has:
Assistant
Let me verify the fix was applied correctly:
Assistant
Good. Let me verify that the moveTeleport function wasn't affected:
Assistant
The moveTeleport function is unchanged. Now let me run the tests again:
Assistant
All Teleport tests pass. Now let me run the Suspense tests as well to make sure everything works:
Assistant
All existing tests pass. Now let me create a reproduction script to verify the fix resolves the reported issue:
Assistant
Now let me run the reproduction test to verify the fix works.
Assistant
I need to rename the file to match the test pattern:
Assistant
I see the issue -
defineAsyncComponentis not being used correctly. Let me look at how it's done in the existing tests:Assistant
I see -
defineAsyncComponentin the tests returns promises that resolve differently. Let me update my test:Assistant
Now let me run the test again:
Assistant
Let me look at the existing Suspense test more carefully to understand the async component setup:
Assistant
I see - the
defineAsyncComponentin existing tests is a local helper function defined in the test file, not the imported one. Let me look at how it's imported/used:Assistant
I see - the
defineAsyncComponentis a local helper function. Let me update my test to use the same pattern:Assistant
Now let me run the test again:
Assistant
The issue is that
depscontains promises, not functions. Let me fix the test:Assistant
Now let me run the test again:
Assistant
The fix is working! The test now doesn't crash. The first test (component child) doesn't crash anymore, which confirms the fix works. The only issue is the expected output after suspense resolves - since we toggled the teleport off before suspense resolved, the teleport should not be mounted at all.
Let me fix the expected output:
Assistant
Now let me run the test again to confirm the fix works.
Assistant
Both tests pass. The fix works correctly. Now let me clean up and run all related tests to make sure nothing is broken.
Assistant
Now let me run the full test suite for both Teleport and Suspense tests to make sure my fix doesn't break anything else.
Assistant
All 108 tests pass. Let me also run other related tests to ensure the fix doesn't break anything else.
Assistant
Let me verify the final state of my fix:
Assistant
The fix is complete. Let me provide a summary of my reasoning:
Summary
Issue
When a
<Teleport>inside a<Suspense>is unmounted before its mount can run (due to pending suspense), Vue throws:codeTypeError: Cannot read properties of null (reading 'type')Root Cause
The bug is in
TeleportImpl.removein/core/packages/runtime-core/src/components/Teleport.ts.When a deferred teleport (inside a pending Suspense) is unmounted:
- The existing
pendingMountcheck correctly clears the queued mount job and setsshouldRemove = false. - However, the code then iterates over children and calls
unmount()on each. - If a child is a component, calls , but is because the teleport never mounted (its children were never processed).
- The existing
Assistant
Let me run the full test suite to ensure everything passes before submitting.
Assistant
All tests pass. Let me submit my solution.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.