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 start by exploring the repository structure to understand the codebase and find the relevant files.
Assistant
Let me explore the repository structure first.
Assistant
Let me look at the packages directory.
Assistant
The Teleport component is probably in runtime-core or runtime-dom. Let me search for the Teleport implementation.
Assistant
I need to make single tool calls. Let me search for the Teleport implementation.
Assistant
Let me see the full
removemethod of the Teleport implementation.Assistant
Now let me look at the
unmountandunmountComponentfunctions in the renderer.Assistant
Now let me look at the git history of this file to understand the regression.
Assistant
Let me look at the commit that introduced the pendingMount check in the remove method (PR #14642).
Assistant
Let me see the rest of this diff to understand what was in the
removemethod before and after.Assistant
Now I have a clear understanding. Let me look at existing tests for teleport + suspense to understand the testing patterns.
Assistant
Let me look at how teleport + suspense tests are structured, particularly around unmount.
Assistant
Let me look at the test setup (helpers, defineAsyncComponent, etc.) at the top of the Suspense spec file.
Assistant
Now let me create a reproduction test to confirm the issue.
Assistant
Let me fix the import path - I'll place the test inside the test directory structure.
Assistant
The crash didn't reproduce because in my test the default branch isn't mounted while the async is pending. Let me examine the Suspense implementation to understand the timing.
Assistant
I see - the Teleport needs to be a direct child of the Suspense content (mounted in hidden container) alongside the async dep, so its
processruns whilependingBranchis set. Let me fix the reproduction.Assistant
I've reproduced the crash. Now let me understand the full unmount flow - particularly how the teleport's main placeholders are removed. Let me look at the Suspense unmount.
Assistant
Let me check how the unmount is triggered in the patch path (when n2 is null).
Assistant
I've confirmed the crash. Now I understand the full picture:
- When a Teleport is inside a pending Suspense branch, its
processruns but defers the actual children mount viapendingMounts(a post-render effect that runs only when Suspense resolves). - If the Suspense is unmounted before resolving, the Teleport's
removeis called. It setsshouldRemove = falsefor the pending mount case, but still iterates over children and callsunmount. For a component child,vnode.componentisnull(never mounted), sounmountComponent(null, …)crashes oninstance.type.
The fix: when there's a pending mount, the children were never mounted, so skip the children unmount loop entirely. Let me open the file and apply the fix.
- When a Teleport is inside a pending Suspense branch, its
Assistant
Now let me apply the fix:
Assistant
Now let me apply the fix:
Assistant
Now let me run my reproduction test to confirm the fix:
Assistant
The crash is fixed, but there's a leftover
<!---->. Let me investigate whether this is related to my fix or pre-existing. Let me check what happens with an element child (which didn't crash before) and debug the root contents.Assistant
The
<!---->leftover appears for both element and component children — so it's pre-existing behavior unrelated to my fix. It's the Root component's placeholder when it rendersnull(a component rendering null leaves a comment node). Let me verify this is standard component-renders-null behavior:Assistant
Confirmed — a component rendering
nullalways leaves a<!---->placeholder. So the leftover is just the Root component's normal null placeholder, unrelated to my fix. My fix correctly resolves the crash.Let me clean up my temp test files and run the existing Teleport and Suspense test suites:
Assistant
All tests pass. Let me also run the renderer and hydration tests to ensure nothing else broke:
Assistant
All tests pass. Now let me verify the fix handles the related
deferprop case (which also usespendingMounts) — a deferred teleport unmounted synchronously before its mount post-effect runs:Assistant
Let me verify these defer cases would have crashed before my fix by temporarily reverting:
Assistant
Interesting — the defer cases pass even without my fix, because for a non-suspense deferred teleport, the post-render mount effect flushes at the end of the first
render()call (before the unmount). The crash only manifests in the suspense path, where the pending mount is deferred until the suspense resolves. My earlier suspense repro confirmed the crash before the fix and confirmed the fix resolves it.Let me clean up the temp test files:
Assistant
Let me do a final verification by re-creating the exact suspense crash repro and confirming it passes with the fix:
Assistant
The crash is resolved. Let me also confirm it crashes without the fix (revert temporarily):
Assistant
Confirmed: without the fix, it crashes; with the fix, it passes. Let me clean up the temp test file and run the broader test suite one final time:
Assistant
All passing. Let me run the broader runtime-core and runtime-dom test suites to ensure nothing is broken:
Assistant
All 1244 tests pass. Let me verify the TypeScript type-check passes for the changed file:
Assistant
The full type-check is too slow (timeout). My change is simple and type-safe (moved
shouldRemoveinto the guarded block as aconst, added!pendingMount &&). Let me do a final review of the changed region:Assistant
The fix looks clean. Let me run eslint on the changed file to ensure no lint issues:
Assistant
No lint errors. My fix is complete and verified. Let me review the final diff one more time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.