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
I’ll first inspect the repository structure and locate the Teleport implementation and related tests. Then I’ll reproduce the failure with the closest existing runtime-core test, patch the pending-mount removal path, and run targeted plus broader tests.
- Assistant
The implementation already tracks deferred mounts in a
WeakMap, including cancellation during updates and inremove. I’ll inspect those exact branches and the existing Teleport/Suspense tests to determine whether removal merely needs to skip child unmounting or needs more nuanced cleanup. - Assistant
The bug is visible in the current code: the pending branch sets only
shouldRemove = false, but still invokes genericunmount()for every never-mounted child. For component children, that reachesunmountComponent(vnode.component!)withnull. Since none of these child VNodes entered the mount lifecycle, they should not enter the unmount lifecycle either. I’ll inspect renderer removal semantics and git history/tests before implementing an early child-skip while preserving Teleport anchor cleanup. - Assistant
Renderer confirms Teleport’s
remove()is responsible for the end anchor and child teardown, while genericremove(vnode)subsequently removes the start anchor. Thus pending removal should cancel the job, remove Teleport anchors as applicable, and skip only the child loop. I’ll review the regression commits and current test harness so I can reproduce the exact Suspense timing without adding repository tests. - Assistant
I’ll reproduce using a standalone
/tmpscript (not a repository test), importing the source throughtsxand using the runtime-core mock renderer. The scenario will mount a pending Suspense containing a Teleport whose child is a component, then synchronously render it away; this directly exercises the reported null component path. - Assistant
There is no ready Vue build or
tsxbinary, so the most reliable reproduction is a temporary Vitest config and test under/tmp, pointed at this repository and aliasing@vue/*packages exactly as the project config does. This keeps all test files outside the repository while running source code directly. - Assistant
Rather than fight Vitest’s project-root include filters, I’ll build the local Vue CJS bundle and run a plain
/tmpjsdom reproduction against it. This validates the public runtime behavior with no test changes. - Assistant
Corepack attempted an interactive confirmation because the repository pins a newer pnpm than the global shim. I’ll rerun with download prompts disabled, which is appropriate for this noninteractive environment.
- Assistant
I’ll now execute the public-API reproduction. It mounts a Suspense default branch containing both a Teleport-with-component-child and an unresolved async component, then removes Suspense on the next render tick. The expected current result is the reported
null.typecrash. - Assistant
The full
vueCJS entry eagerly requires the template compiler, which was not built. Since the reproduction uses only render functions, I’ll build and import@vue/runtime-dominstead; this avoids unrelated compiler artifacts and exercises the same Teleport implementation. - Assistant
The runtime-dom CJS bundle externalizes workspace dependencies, so I’ll build runtime-core, reactivity, and shared CJS bundles as well, then rerun the same script.
- Assistant
The reproduction exactly matches the issue stack. I’ll patch
TeleportImpl.removeso cancellation of a queued mount also suppresses child unmount traversal. This is intentionally based on mount state, not child type: no never-mounted child (component, element with hooks/directives, nested Teleport, etc.) should receive teardown. Teleport’s own anchors remain cleaned up by the existing code. - Assistant
Python is unavailable in this environment, so I’ll apply the same focused edit using the repository’s editor command.
- Assistant
I’ll replace the cancellation block and guard the child loop with the captured pending-job state.
- Assistant
The first edit applied correctly; the one-line shell argument triggered Bash history expansion on
!. I’ll apply that line through a quoted heredoc and then rebuild/re-run the reproduction. - Assistant
The standalone reproduction now completes without error and leaves both root/target clean. Next I’ll run the existing Teleport and Suspense unit suites, then lint/type-check the changed source. These cover normal/deferred Teleport lifecycle behavior and ensure the new guard does not regress mounted-child unmounting.
- Assistant
All 108 targeted tests pass. I’ll now run ESLint on the changed file and the repository TypeScript check, then inspect status/diff to ensure only the intended source change is submitted (build outputs should be ignored).
- Assistant
The lint and full TypeScript check pass, and status contains only the intended source file. I noticed the adjacent comment now needs to acknowledge the pending exception; I’ll clarify it to say “mounted children,” then run both development and production bundle reproductions once more.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.