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 inspect the Teleport/Suspense implementation, related regression guards, and existing tests to identify the intended lifecycle behavior before reproducing the crash locally.
- Assistant
The implementation already cancels queued mounts during both updates and removal, but cancellation alone may leave never-mounted child component VNodes in the normal unmount traversal. I’ll read those paths and the renderer’s component-unmount assumptions, then locate the most appropriate existing Teleport test suite.
- Assistant
The crash is confirmed structurally:
Teleport.remove()changes onlydoRemovepassed to children, while renderer unconditionally dereferencesvnode.component!for any component-shaped child. Since a pending Teleport has mounted none of its children, the correct distinction is not “unmount without DOM removal” but “do not traverse unmounted children at all.” I’ll inspect nearby regression tests and package scripts, then run a focused reproduction against the current source. - Assistant
To reproduce the exact timing rather than infer it, I’ll fetch the linked minimal repository into
/tmp(leaving this repository untouched), inspect its three cases, and run them against the reported version. Then I can adapt the same scenario to a temporary script against a locally built patched runtime for verification. - Assistant
The minimal case exactly matches the uninitialized component-child path. I’ll run its suite now to record the baseline failure; afterward I’ll implement the smallest lifecycle correction by tracking whether the queued mount was canceled and skipping child traversal only in that state. Mounted Teleports will retain their existing unconditional child cleanup semantics.
- Assistant
Corepack stopped for an interactive download confirmation, so no test ran. I’ll avoid that unsupported prompt by installing the small reproduction with npm, then execute Vitest directly and return to the core repository.
- Assistant
The baseline reproduces exactly: one failure for a component child, while element and non-pending controls pass. I’ll now add a separate
shouldUnmountdecision inTeleport.remove(): cancellation marks children as never mounted, whileshouldRemoveremains responsible solely for host-node removal. This avoids conflating two different lifecycle states and preserves all behavior for mounted children. - Assistant
The specialized replacement tool located the blocks but requires them in the editor’s visible window. I’ll open the removal method at that location and apply precise line-range edits, taking care not to alter the similar array-child loop in
moveTeleport. - Assistant
I can now safely replace the pending-mount state block and gate only the removal loop.
- Assistant
The edit is functionally correct, but the old “always unmount” comment now needs to acknowledge the explicit never-mounted exception. I’ll also make the gate immutable (
const shouldUnmount = !pendingMount) to express the invariant more clearly before running focused tests and type/lint checks. - Assistant
Review caught an accidental omission: replacing the two-line old comment also replaced
doRemove && hostRemove(anchor!). That main-view anchor must always retain its existing cleanup. I’ll restore it immediately, then run the Teleport suite. - Assistant
The source is restored correctly. Corepack again blocked on a download prompt before Vitest started; I’ll disable that prompt via its environment flag and rerun the focused suite.
- Assistant
All 51 existing Teleport tests pass. To confirm the reported reproduction against this exact source (not merely the released dependency), I’ll build Vue’s self-contained ESM browser bundle, copy the reproduction test to a temporary file outside the repository with its
vueimport redirected to that bundle, and run the same three tests. - Assistant
The exact three-case reproduction now passes against the patched local bundle, including the formerly crashing component child. I’ll complete validation with the broader Suspense suite, linting the changed file, and the repository TypeScript check; then I’ll inspect the final diff/status for generated artifacts or unintended changes.
- Assistant
All broader validation passed: 57 Suspense tests, lint, and TypeScript checking. I’ll now review the final patch and repository status, ensuring only the intended source file is changed and that the control flow still removes Teleport anchors while skipping only never-mounted children.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.