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 first inspect the Teleport/Suspense implementation, recent related guards, and the available runtime-core tests. Then I’ll reproduce the pending-mount unmount path with the existing test infrastructure, apply the smallest lifecycle-safe fix, and run targeted plus broader tests.
- Assistant
The implementation already cancels a pending scheduler job in
remove, but likely continues into ordinary child unmounting afterward. I’ll inspect that section and existing Teleport test conventions, as well as the relevant history/diff context, before deciding whether pending children should be skipped entirely or passed through a specialized unmount path. - Assistant
shouldRemove = falseonly suppresses host-node removal; rendererunmount()still dispatches component-shaped VNodes tounmountComponent(child.component!), so an unprocessed component child crashes exactly as reported. Since none of a pending Teleport’s children have enteredpatch/mount at all, they have no component instances, directive hooks, refs, or effects to tear down; the correct symmetric action is to cancel the mount and skip child unmounting. I’ll confirm this with a temporary focused test (not committed), then implement an explicit early/guarded child skip while still removing the Teleport’s own main anchor. - Assistant
The test command was blocked before execution by Corepack’s interactive package-manager download prompt, and the timeout left the temporary test file in place. I’ll avoid interactive tooling by checking installed binaries/package metadata, run Vitest directly if dependencies exist, and ensure the temporary file is removed afterward.
- Assistant
Vitest is installed; only the Jest-specific
--runInBandflag was invalid. I also need the reproduction to await Vue’s queued reactive update rather than invoke an unchanged root render synchronously. I’ll rerun a corrected asynchronous temporary test and capture the pre-fix failure. - Assistant
That attempt mixed runtime-test’s virtual renderer with a real DOM target and also violated Suspense’s single-root requirement, so it failed earlier for unrelated reasons. I’ll correct both: use
nodeOps.createElement()as the Teleport target and wrap the async dependency plus Teleport in one element. - Assistant
The corrected reproduction now matches the reported stack exactly (
unmountComponentreadinginstance.typewherechild.componentis null). I’ll introduce awasPendingboolean, cancel the job as before, and gate the child loop on!wasPending. The Teleport anchor cleanup remains unchanged, and already-mounted Teleports retain their existing unmount behavior. - Assistant
Python is not installed in this environment, so no source change occurred. I’ll use the repository’s provided literal replacement utility instead, then inspect the diff to ensure only the intended block changed.
- Assistant
The replacement utility located both blocks but requires them to be visible in the editor window. I’ll open the relevant section and repeat the exact replacements.
- Assistant
The diff is minimal and preserves
shouldRemovefor every mounted case; for a pending case it is now irrelevant because children are skipped. I’ll rerun the exact temporary regression test against the fix, then run the full Teleport component spec and type/lint checks relevant to this file. - Assistant
The exact regression now passes and confirms both the replacement content and Teleport target are clean; all 51 existing Teleport tests also pass. I’ll check formatting/lint/type scripts, run the narrowest applicable static checks, and inspect the final diff/status for accidental files.
- Assistant
Formatting and ESLint pass, and the working tree contains only the intended source file. I’ll run the repository TypeScript
checkscript directly through its installed binary (avoiding Corepack), then perform a final diff review. - Assistant
TypeScript passes. One nearby comment says an unmounted Teleport “always” unmounts children, which is now intentionally false for never-mounted pending children. I’ll clarify it to “mounted children,” rerun the lightweight checks, and then submit.
- Assistant
The comment-edit command had shell quoting conflict around the apostrophe, so it made no change and did not run the chained checks. I’ll repeat it using double-quoted arguments.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.