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 Vue.js Teleport + Suspense causing a crash when unmounting a pending teleport with a component child. The error is
TypeError: Cannot read properties of null (reading 'type')occurring inunmountComponent.Let me start by exploring the repository structure to understand the codebase and then find the relevant files.
Assistant
This is the Vue.js core repository. Let me explore the runtime-core package where the Teleport and Suspense logic lives.
Assistant
Assistant
Let me try the grep command again with the proper tool call format.
Assistant
The grep command failed because there's no match. Let me try a different pattern to find the unmount function in the renderer.
Assistant
Let me look at the unmount function and unmountComponent function to understand the issue better.
Assistant
I need to use the correct format for opening a file with a line number. Let me try a different approach.
Assistant
Let me look at more of the unmount function and the unmountComponent function to understand the issue.
Assistant
I see the issue now. When
shapeFlag & ShapeFlags.COMPONENTis true, it callsunmountComponent(vnode.component!, parentSuspense, doRemove). The problem is that if the teleport has a pending mount, its children may havevnode.component === nullbecause they haven't been mounted yet.Let me look at the
unmountComponentfunction to see what happens whenvnode.componentis null.Assistant
Let me now understand the issue better. Looking at the
TeleportImpl.removemethod, when there's a pending mount:- The pendingMount is cleared
shouldRemoveis set tofalse- BUT the children are still being unmounted
The problem is that the children were never mounted (because the teleport was pending), so their
vnode.componentisnull. Whenunmount()is called on such a child withShapeFlags.COMPONENT, it tries to callunmountComponent(vnode.component!, ...)which crashes becausevnode.componentisnull.Let me first check if there are any tests I can run:
Assistant
The grep command failed. Let me just list the files in the tests directory and look for teleport tests.
Assistant
I need to continue investigating the issue. Let me look at the components test directory for teleport tests.
Assistant
I need to continue investigating the issue. Let me look at the components test directory for teleport tests and check for existing tests related to the Suspense + Teleport unmount issue.
Assistant
The grep command returned empty (exit code 0 but no output). Let me search for relevant patterns in the Teleport tests:
Assistant
Let me look at the Teleport spec file to understand its structure:
Assistant
Let me search for any tests related to unmount with suspense in the teleport spec file:
Assistant
Let me look at the TeleportImpl.remove method more closely and understand the issue. The problem is that when there's a pending mount, the children were never mounted, so their
vnode.componentisnull. When we try to unmount them, it crashes.Let me create a test script to reproduce the issue first:
Assistant
The test file was created. Now let me run it to see if I can reproduce the issue.
Assistant
The test file name doesn't match the vitest patterns. Let me rename it and run it from the right location:
Assistant
I need to add the jsdom environment directive. Let me update the test file:
Assistant
I need to fix the test - Suspense slots expect a single root node. Let me update the test:
Assistant
I successfully reproduced the issue. The error matches exactly what was reported:
codeTypeError: Cannot read properties of null (reading 'type')Now let me understand the fix. Looking at the
TeleportImpl.removemethod, when there's a pending mount, the children were never mounted, so we shouldn't unmount them. The fix is to skip unmounting children when there's a pending mount.Let me look at the
removemethod in Teleport.ts again:Assistant
I've successfully reproduced the issue. The error is exactly what was reported:
codeTypeError: Cannot read properties of null (reading 'type')The issue is in
TeleportImpl.removein/core/packages/runtime-core/src/components/Teleport.ts. When there's a pending mount (the teleport was deferred due to a pending Suspense), the children were never actually mounted, so theirvnode.componentisnull. The code still tries to unmount them, which crashes when it callsunmountComponent(vnode.component!, ...)on a component child.The fix is straightforward: when there's a pending mount, we should skip unmounting the children entirely, since they were never mounted.
Let me apply the fix:
Assistant
I've successfully reproduced the issue. The error is exactly as described:
codeTypeError: Cannot read properties of null (reading 'type')The problem is in the
removemethod ofTeleportImpl. When there's a pending mount, the comment says "skip removing children because nothing has been mounted yet" - but the code only setsshouldRemove = falsewhich only affects DOM removal, not the actualunmount()call on children.The fix is to skip unmounting children when there's a pending mount. Let me apply the fix:
Assistant
Now I need to apply the fix. The issue is in the
removemethod - when there's a pending mount, we should skip unmounting children entirely since they were never mounted. Let me edit the file:Assistant
Let me scroll down to find the
removemethod in the Teleport.ts file.Assistant
The user is pointing out that my previous response didn't have a proper tool call. Let me continue working on the fix. I need to scroll to the
removemethod at line 317 and make the fix.Assistant
Now I understand the issue. The comment at line 337-338 says "skip removing children because nothing has been mounted yet" but the code still calls
unmount()on children at lines 352-361. When a child is a component that was never mounted,child.componentisnull, causing the crash.The fix is to skip unmounting children when there's a pending mount. I need to add a
returnor guard the children unmount loop.Assistant
The fix has been applied. I changed line 354 from:
typescriptif (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {to:
typescriptif (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {This ensures that when a teleport has a pending mount (meaning its children were never actually mounted), we skip unmounting the children. Let me now run the reproduction test to verify the fix:
Assistant
The test passes now. Let me run the existing Teleport tests to make sure I didn't break anything:
Assistant
All 51 existing Teleport tests pass. Let me also run the Suspense tests to ensure the fix doesn't break anything with Suspense:
Assistant
All existing tests pass. Now let me clean up my test file and run a broader test suite to make sure nothing is broken:
Assistant
Let me run a broader set of tests related to the runtime-core to make sure my change doesn't break anything else:
Assistant
All 1014 tests in the runtime-core package pass. Let me verify my change by looking at the diff:
Assistant
Let me fix the formatting issue (the extra blank line removed) and verify everything is correct:
Assistant
I see there's an extra blank line that got removed. Let me restore that to keep the formatting consistent:
Assistant
I need to fix the formatting - there should be a blank line after
},beforemove:. Let me fix that:Assistant
Now let me verify the final diff looks correct:
Assistant
The diff looks clean now. Let me run the tests one more time to make sure everything is still passing:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.