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)
pnpm 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)
pnpm 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:
TypeError: 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
System: 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.34Any additional comments?
This is a continuation of the regression chain that started in 3.5.31:
- PR #8619 (3.5.31) introduced
pendingMountsso teleports defer their mount whenparentSuspense.pendingBranchis set. This is what created the situation where a teleport's children can havevnode.component === null. - Issue #14640 + (3.5.32) added the check shown above. That gates DOM removal of children, not the call on children.
Assistant
I'll start by exploring the repository structure to understand the codebase and then investigate the issue.
Assistant
I'll explore the repository structure first.
Assistant
Let me look at the relevant source files for the Teleport implementation and runtime-core.
Assistant
Let me look at the Teleport.ts file, particularly the
removefunction.Assistant
Let me see the full
removefunction and theunmountfunction in the renderer.Assistant
Now let me look at the
unmountfunction in the renderer to understand how component vnodes are handled.Assistant
Let me look at the
unmountComponentfunction to understand the crash.Assistant
Let me see the rest of the
unmountfunction after the teleport case.Assistant
Now I understand the issue clearly. Let me write a reproduction test first to confirm the crash. Let me look at existing teleport/suspense tests for reference.
Assistant
Let me create a reproduction test to confirm the crash. I'll create a temporary test file.
Assistant
I need to use the DOM test environment. Let me check how existing teleport tests are configured.
Assistant
Let me look at the Suspense tests for how they handle async setup and unmount.
Assistant
Now I understand the test setup. They use
nodeOps,serializeInnerfrom@vue/runtime-test, andh,render,Suspensefrom the source. Let me rewrite my reproduction test using the same setup.The key scenario is:
- A Teleport inside a Suspense
- The teleport has a component child
- The Suspense is pending (async component not yet resolved)
- While pending, unmount the Suspense
The teleport's mount is deferred because
parentSuspense.pendingBranchis set. When the Suspense is unmounted, the teleport'sremoveis called, which tries to unmount the component child, butchild.componentisnullbecause the teleport's mount never ran.Let me use the
@vue/runtime-testsetup withnodeOps.Actually, the
@vue/runtime-testusesnodeOpswhich is a mock DOM. The teleport target needs to be resolvable. Let me check how the existing teleport tests handle thetoprop with nodeOps.Looking at the existing test at line 65, it uses
createDOMAppanddocument. But therunSharedTestsfunction uses . Let me look at how the teleport target is set up with nodeOps.Assistant
Now let me rewrite the reproduction test using the proper test setup.
Assistant
I need to wrap the Suspense default slot in a single root node. Let me fix the test.
Assistant
I've successfully reproduced the crash. The error matches exactly the stack trace in the issue:
TypeError: Cannot read properties of null (reading 'type') ❯ unmountComponent packages/runtime-core/src/renderer.ts:2317:29 ❯ unmount packages/runtime-core/src/renderer.ts:2173:7 ❯ Object.remove packages/runtime-core/src/components/Teleport.ts:355:9The root cause: In
TeleportImpl.remove, when the teleport's mount is pending (deferred),shouldRemoveis set tofalsewhich prevents DOM removal of element children, but the children unmount loop still runs. For component children,child.componentisnull(becausemountChildrennever ran), sounmountcallsunmountComponent(null, ...)which crashes.The fix: when the mount is pending, skip the children unmount loop entirely since the children were never mounted. Let me apply this fix.
Assistant
Now let me apply the fix. I'll gate the children unmount loop on
!pendingMountso that when the mount is pending (children were never mounted), we skip unmounting them entirely.Assistant
Now let me run the reproduction test to confirm the fix works.
Assistant
The fix works. Now let me run the existing Teleport and Suspense tests to make sure nothing is broken.
Assistant
All 108 existing tests pass. Now let me test additional edge cases to make sure the fix is robust. Let me expand the reproduction test to cover element children, mixed children, the
deferprop path, and the normal mount-then-unmount case.Assistant
I need to import
onMounted. Let me fix the import.Assistant
All 5 edge case tests pass, including the normal mount-then-unmount case (verifying cleanup still works correctly). Let me run a broader set of tests to ensure nothing else is broken.
Assistant
All 1019 runtime-core tests pass. Let me also run the runtime-dom tests since Teleport interacts with DOM operations.
Assistant
Let me also run any e2e tests related to teleport and suspense to be thorough.
Assistant
The Transition.spec.ts failure is because it requires a browser environment (e2e test). Let me confirm this is pre-existing/environmental and not related to my change.
Assistant
The Transition.spec.ts failure is purely environmental — puppeteer can't launch Chrome as root without
--no-sandbox. This is unrelated to my change.Now let me refine the comment I added. The
#14701reference is for themoveTeleportfix, not theremovepath. Let me make the comment more accurate.Assistant
Let me check the changelog to find the appropriate issue/PR number for this fix.
Assistant
I'll update the comment to be accurate and descriptive without referencing a potentially-wrong issue number.
Assistant
Let me run the reproduction test one final time to confirm everything still works after the comment edit.
Assistant
All tests pass. Now let me clean up by removing the temporary test file since I shouldn't add new tests to the repository.
Assistant
Let me verify the final state of my changes with git diff.
Assistant
Let me verify git status to confirm only the intended change remains.
Assistant
The change is clean and minimal. Let me add explicit parentheses for clarity to match the code style used in
moveTeleport(which uses explicit grouping), making the operator precedence unambiguous.Assistant
Let me run the existing test suites one final time to confirm everything passes with the final version of the fix.
Assistant
Let me do a final verification by recreating the reproduction test to confirm the fix resolves the original crash.
Assistant
The fix is confirmed working. Now let me remove the temporary test file and verify the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.