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 repository structure and the Teleport/Suspense implementation, then locate relevant existing tests and recent pending-mount guards. After reproducing the failing lifecycle with the project’s test tooling, I’ll make the smallest source-only fix and run the focused and broader affected test suites.
- Assistant
rgis unavailable, so I’ll use recursivegrep. The working tree is clean and dependencies are already installed. - Assistant
The implementation already cancels pending jobs during both update and remove, while
moveTeleportseparately avoids moving unmounted children. I’ll read the full mount/update/remove flow and renderer unmount assumptions to identify whether removal should skip child unmount entirely or selectively handle never-mounted children. - Assistant
The current comment and behavior disagree: pending mount sets
shouldRemove = false, but still calls rendererunmountfor every never-mounted child. Element children happen not to crash because DOM removal is suppressed; component children reachunmountComponent(vnode.component!)withcomponent === null. Since none of those children ever entered mount, they also should not receive unmount processing or hooks. I’ll inspect Teleport tests and git history/context, then reproduce with a focused existing-test-style temporary script or test invocation before editing. - Assistant
The history confirms the pending-removal branch was introduced specifically for never-mounted content, and no existing test covers component children in that state. I’ll use an external
/tmpVitest file with the repository’s config and runtime-dom source aliases if supported; first I’m checking the test conventions and root scripts/config so the reproduction matches Vue’s own environment without modifying repository tests. - Assistant
I can reproduce without browser globals by using Vue’s in-memory
@vue/runtime-testrenderer. The script will mount a Suspense whose default branch contains both an unresolved async component and a Teleport with a synchronous component child, then immediately rendernull; this precisely leaves the Teleport mount buffered on the pending boundary before unmount. The script lives only in/tmp, not in the repository. - Assistant
pnpm exectriggered Corepack’s interactive version download, which this environment cannot answer. I’ll invoke the already-installed local binary directly instead. - Assistant
There is no
vite-nodeshim in the installed dependency layout. I’ll inspect available package-manager metadata and binaries, then use the existing Vitest executable or the repository’s declared pnpm version with Corepack downloads disabled. - Assistant
Vitest is available. I’ll place a temporary test in
/tmpand provide a temporary config there that imports the repository aliases and defines Vue’s compile-time flags, explicitly setting/tmpas Vitest’s root. This keeps all reproduction artifacts outside the repository. - Assistant
The absolute package subpath is export-only rather than a physical module.
defineConfigis only a typing helper, so I’ll remove it and export the plain config object; the repository alias module can still be imported by physical path. - Assistant
Python is also unavailable, so I’ll rewrite the small temporary config directly with shell redirection.
- Assistant
The reproduction exactly matches the reported stack. The correct invariant is to cancel the buffered job, remove only Teleport’s own anchors, and return before traversing children: those child VNodes were normalized but never patched, so component instances, DOM nodes, refs, directives, and mount lifecycle state do not exist. This also avoids incorrectly firing unmount hooks on never-mounted element children. I’ll implement that guard while preserving anchor cleanup.
- Assistant
The line-range replacement retained the original loop’s closing brace, leaving one extra brace. I’ll remove it and restore the blank line after destructuring to match project formatting, then run syntax/diff checks before testing.
- Assistant
One duplicate method terminator remains (the earlier edit replaced the extra brace with a terminator rather than deleting the line). I’ll delete the second
},and then run the TypeScript-aware focused reproduction. - Assistant
The external reproduction now passes. Next I’ll run the complete existing Teleport and Suspense component suites, which cover eager/deferred updates, removal semantics, lifecycle hooks, nested boundaries, and pending branch resolution. I’ll then run formatting/lint or type checks available for the changed file and review the final diff.
- Assistant
All 108 focused repository tests pass. I’ll make the nearby invariant comment precise (“mounted teleport”), since pending teleports are intentionally the exception, then run the repository formatter/linter on the source file and the runtime-core type check if scripts support focused execution.
- Assistant
There is no dedicated typecheck script, but Vitest already transformed and type-aware syntax-checked the changed module. I’ll run ESLint and Prettier directly on the modified source, then inspect status/diff and ensure no temporary repository artifacts exist.
- Assistant
The final diff is limited to Teleport removal, passes lint/format, and preserves mounted Teleport behavior unchanged. As a broader regression check, I’ll run the full runtime-core unit suite, not just Teleport/Suspense, because unmount traversal interacts with components, refs, directives, KeepAlive, and scheduler effects.
- Assistant
Final verification and requested checklist:
- Successfully reproduced the reported error. An external
/tmpVitest reproduction mounted an unresolved Suspense branch containing a Teleport with a component child, then immediately unmounted it. Before the fix it failed atunmountComponentwithCannot read properties of null (reading 'type'). - Confirmed the fix resolves the error. The exact same external reproduction passes after the change.
- Considered edge cases. Pending Teleport children have never entered the renderer mount flow, regardless of whether they are components, elements, fragments, refs, or directives. The fix cancels the pending scheduler job, still cleans up Teleport-owned anchors, and skips child unmount traversal only in that never-mounted state. Normal mounted, disabled, deferred-after-mount, and target cleanup paths remain unchanged.
- Successfully reproduced the reported error. An external
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.