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
Let me start by exploring the repository structure to understand the codebase.
Assistant
This is the Vue core repository. Let me explore the relevant files. The issue is about Teleport + Suspense unmount crashes. Let me look at the teleport implementation.
Assistant
Let me look at the Teleport implementation:
Assistant
Let me look at the full
removefunction of the TeleportImpl which is the key part of the issue:Assistant
Now let me look at the
unmountandunmountComponentfunctions in the renderer:Assistant
Now let me look at the
unmountComponentfunction:Assistant
Let me look at the git history for the Teleport.ts file to understand the regression:
Assistant
Let me look at the changes made by PR #14642 and #14702:
Assistant
Now let me look at the PR #14702:
Assistant
Now I understand the regression chain. Let me look at existing tests related to teleport + suspense to understand the test structure:
Assistant
Let me search for tests that combine teleport and suspense in either test file.
Assistant
Let me look at the test setup (defineAsyncComponent, deps, etc.) at the top of the Suspense spec:
Assistant
Now let me create a reproduction test to confirm the error:
Assistant
The mutation didn't trigger reactivity because I used a plain object. Let me fix the test to use
ref:Assistant
I've successfully reproduced the exact error from the issue. The stack trace matches:
codeTypeError: Cannot read properties of null (reading 'type') at unmountComponent (renderer.ts) at unmount at Object.remove (Teleport.ts:355) ...Now let me examine the
removefunction closely to implement the fix:Assistant
I've confirmed the error. Now let me understand the Suspense behavior to make sure my fix is correct. Let me look at the Suspense unmount and resolve logic:
Assistant
Let me look at how the suspense mounts its pending branch:
Assistant
Let me look at the Suspense's
unmountmethod:Assistant
Now I have a complete understanding of the issue. Let me trace through the flow:
mountSuspensepatches thependingBranch(the div with Async + Teleport) into a hidden container.- When the Teleport is patched, since
parentSuspense.pendingBranchis set,queuePendingMountdefers the mount. The Teleport's children (Comp) are NOT mounted yet (vnode.component === null). - When the suspense is unmounted before resolving,
suspense.unmountunmounts thependingBranch, which calls the Teleport'sremove. - The Teleport's
removefinds the pending mount, setsshouldRemove = false(skipping DOM removal of element children), but STILL callsunmounton each child. For the component child,unmountcallsunmountComponent(null, ...)→ crash.
The fix: when there's a pending mount, the children haven't been mounted at all, so we should skip the entire children unmount loop. Let me implement this:
Assistant
Now let me implement the fix. I'll modify the
removefunction so that when there's a pending mount, we skip the entire children unmount loop (since none of the children were mounted):Assistant
Now let me run my reproduction test again to verify the fix:
Assistant
The crash is resolved. The remaining failure is just my test assertion expecting `` but rendering
nullat the root produces a comment placeholder<!---->, which is normal Vue behavior. Let me update my reproduction test to verify the fix properly and check edge cases:Assistant
The first two tests (the real reproduction scenarios) pass. The third test's assumption is wrong — for a deferred teleport without suspense, the mount job runs in the post-render flush right after
render(), so the target is populated immediately. The "pending mount + unmount" race only occurs with Suspense buffering the post effects. Let me remove that invalid third test:Assistant
Let me recreate a temporary test file for verification (I'll remove it before submitting):
Assistant
All 3 tests pass, including the regression check that the normal resolve flow still works. Now let me run the existing Teleport and Suspense test suites to make sure I didn't break anything:
Assistant
Both pass. Let me also run the broader renderer tests and runtime-dom teleport tests to ensure nothing else is affected:
Assistant
Let me check the project names in vitest.config.ts.
Assistant
Let me also run the runtime-dom teleport tests which use the real DOM renderer:
Assistant
Let me run the e2e Transition tests and customElement tests since they involve teleport:
Assistant
The e2e Transition tests require a real browser (puppeteer) which isn't available in this environment — that's a pre-existing environment limitation, not related to my change. Let me run the customElement tests which use jsdom and involve teleport:
Assistant
Let me also run the useCssVars spec since it involves teleport:
Assistant
Let me verify the file uses ASCII comments (to match style) and check my edit didn't introduce non-ASCII characters:
Assistant
I introduced a non-ASCII em-dash. Let me replace it with ASCII to match the file's style:
Assistant
Now let me review the final state of the
removefunction and reconsider theshouldRemove = falseline, which is now a dead store since the loop is gated by!pendingMount:Assistant
The
shouldRemove = falseline is now a dead store since the loop is gated by!pendingMount. This is consistent with the parallel fix inmoveTeleport(PR #14702) which uses!pendingMounts.has(vnode)to gate the move without any dead store. Let me clean this up by removing the redundant assignment and makingshouldRemoveaconst:Assistant
The code is now clean and consistent with the parallel fix in
moveTeleport. Let me re-run my reproduction tests to confirm the fix still works after cleanup:Assistant
All pass. Let me run the full Teleport and Suspense suites once more to confirm everything passes after cleanup:
Assistant
Now let me run a TypeScript typecheck to ensure my changes compile correctly:
Assistant
The full vue-tsc type-check is too slow for this environment, but my change is type-safe by analysis (
pendingMountisSchedulerJob | undefinedfrom the WeakMap'sget, and!pendingMountis a valid boolean gate). The vitest tests compile via esbuild. Let me also verify the element-child case (fixed by #14642) still works and add a regression test for it:Assistant
The appended test landed outside the
describeblock. Let me rewrite the test file cleanly:Assistant
All 4 tests pass, including the element-child regression check (#14642) and the normal resolve flow. Let me run the broader runtime-core components and renderer test suites to be thorough:
Assistant
All 302 tests pass. Let me also run the runtime-dom and vue tests that involve teleport, plus the SSR teleport tests:
Assistant
All tests pass. Now let me clean up my temporary test file before submitting:
Assistant
Let me review the final diff to confirm the changes are clean:
Assistant
The diff is clean and minimal. Let me run the linter on the changed file to ensure no lint errors:
Assistant
No lint errors. Let me run prettier check on the file to ensure formatting is correct:
Assistant
Everything passes. Let me do a final review of the complete
removefunction:Assistant
The fix is complete. Let me verify there are no leftover temporary files and confirm the final git status:
Assistant
The fix is complete and clean. Let me run the two most relevant test suites one final time to confirm everything is green:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.