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 and Suspense implementation, locate the pending-mount guards and relevant existing tests, then reproduce the failing lifecycle with the repository’s test tooling before making the smallest general fix.
- Assistant
The implementation already tracks a deferred mount in a
WeakMap, cancels it during removal, and suppresses DOM movement while pending. I’ll now examine exactly how removal propagates its flags to child unmounts and how Teleport regressions are tested in this repository. - Assistant
The crash mechanism is confirmed in code:
shouldRemove = falseonly suppresses host-node removal, but the loop still calls rendererunmount()for every never-mounted child. A component VNode hascomponent === null, so that call is invalid. The correct distinction is not “unmount without DOM removal,” but “do not unmount children whose mount never ran.” I’ll inspect tests and renderer assumptions, then run a focused existing or temporary reproduction against the source build. - Assistant
Renderer
unmount()explicitly assumes every component-shaped VNode passed to it has an instantiatedcomponent; therefore passing never-mounted children is not supported. The pending state can only originate before Teleport’s initial child mount (updates replace that pending VNode without patching children), so skipping the entire child-unmount loop is both safe and general. Anchors still need normal cleanup, and the queued scheduler job still needs disposal. I’ll implement that distinction while retaining ordinary removal behavior unchanged. - Assistant
Python is not installed in this environment, so no file changed. I’ll apply the same targeted edit with the repository’s editor command.
- Assistant
The first line-range edit accidentally consumed the
if (target)line because line numbers shifted from the earlier display; the editor output exposed this before testing. I’ll repair the full removal block atomically and include the intended pending guard around child unmounting. - Assistant
The repaired diff now does exactly two semantic things for a pending Teleport: dispose its queued mount and bypass child unmount; all mounted Teleports continue through the original loop and receive the original
shouldRemovevalue. I’ll inspect the closest existing deferred-discard tests and run the Teleport suite to validate ordinary and pending element-child behavior before constructing a non-persistent component-child reproduction. - Assistant
The test command did not run because Corepack attempted an interactive pnpm download (unsupported here); this is environment setup rather than a test failure. I’ll check installed dependencies and available package-manager shims, then run with Corepack’s prompt disabled if dependencies are present.
- Assistant
Dependencies and the local Vitest binary are available; Corepack has now provisioned the declared pnpm version. I’ll run the focused suite directly with the local binary to avoid further package-manager prompting.
- Assistant
All 51 existing Teleport tests pass, including discarded pending Teleports with element children and normal component unmount hooks. To directly verify the reported component-child crash without adding or modifying repository tests, I’ll use a temporary standalone script outside the repository and execute it through Vitest’s installed Vite-node runtime if available.
- Assistant
There is no standalone TypeScript runner exposed. A robust alternative is to exercise
TeleportImpl.removedirectly with a temporary JavaScript script: seed a pending mount by callingprocesswith a fake pending Suspense and renderer internals, provide a component-shaped child withcomponent: null, then callremove. However importing TS source still needs transformation. The local Vite CLI can transform and execute a temporary module through a tiny temporary Vite config, but that is disproportionate. Better: create temp spec in /tmp and ask vitest explicitly? likely config excludes. We can create intemp/and remove (script, test semantics). User says no add tests. Could useviteSSR API in .mjs: createServer middlewareMode, ssrLoadModule('/packages/runtime-core/src/components/Teleport.ts'), imports aliases config existing vite.config? Vitest aliases. inspect config alias. - Assistant
I’ll use Vite’s SSR module loader from a temporary
/tmpscript (not a repository test). It will create a real Teleport VNode with a real component VNode child, queue its mount against a pending Suspense, and then remove it. The fake renderer’s unmount deliberately mirrors renderer’s component-instance dereference, allowing the script to distinguish whether removal incorrectly reaches the never-mounted child. I’ll first verify this script against the fixed source, then temporarily restore only the source file toHEADto confirm the original crash and immediately restore the patch. - Assistant
The fixed source passes the direct lifecycle reproduction: the child remains uninstantiated and is not sent to unmount. I’ll now run the same script against the unmodified
HEADimplementation, capture its expected failure, and restore the fixed file in the same shell command so the working tree cannot be left reverted. - Assistant
The same reproduction against
HEADfails with the reportedCannot read properties of null (reading 'type'), and the fixed source was restored automatically. This confirms both reproduction and resolution. I’ll rerun the fixed reproduction after restoration, run the focused suite again, then run TypeScript checking and linting for the changed file. - Assistant
The restored fix passes the direct reproduction, all 51 Teleport tests, ESLint, and the repository TypeScript check. I’ll perform a final diff/status review, verify formatting, and ensure no temporary or generated repository files were introduced.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.