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 + PR #14642 (3.5.32) added the
pendingMountcheck shown above. That gates DOM removal of element children, not theunmountComponent(null, …)call on component children. - Issue #14699 (3.5.32) reported the same crash with the same stack as this issue. Closed by the author with a note about re-filing with a more accurate reproduction.
- Issue #14701 + PR #14702 (3.5.33) added
pendingMounts.has(vnode)guard, but only inmoveTeleport. TheTeleportImpl.removepath was not touched, so 3.5.33 and 3.5.34 still crash.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /core, current file: none) bash-$
Assistant
Let me analyze this issue. The problem is about Vue.js Teleport + Suspense causing a crash when unmounting a pending teleport with a component child. The error is
TypeError: Cannot read properties of null (reading 'type')inunmountComponent.Let me start by exploring the repository structure to understand the codebase and then find the relevant files to fix this issue.
Assistant
This is the Vue.js core repository. Let me explore the runtime-core package since the issue is about Teleport and Suspense.
Assistant
Now I can see the Teleport code. Let me look at the
removemethod more closely. The issue is in theremovefunction where it callsunmounton children even when there's a pending mount. Let me check the currentremoveimplementation:Assistant
I can see the issue now. When there's a
pendingMount, the code setsshouldRemove = false(which skips DOM removal), but it still callsunmount()on the children. The problem is that when a component child hasvnode.component === null(because it was never mounted due to the pending state), theunmountfunction will try to access properties onnull.Let me look at the renderer to understand the unmount function:
Assistant
I can see the issue. When
shapeFlag & ShapeFlags.COMPONENTis true, the code callsunmountComponent(vnode.component!, parentSuspense, doRemove). But when a component is in a pending teleport,vnode.componentisnullbecause the component was never mounted. The!assertion is wrong in this case.The fix should be in the
TeleportImpl.removefunction: when there's a pending mount, we should skip callingunmounton children entirely since nothing was ever mounted.Let me verify this by checking the error more carefully:
Assistant
Now let me check the exact issue. The error says
Cannot read properties of null (reading 'type')atunmountComponent. But looking atunmountComponent, it receives aninstanceparameter. The issue is thatvnode.componentisnullwhen it's passed fromunmount.Let me look at the unmount function where it calls unmountComponent:
Assistant
The problem is clear now:
- When a Teleport is inside a Suspense and is pending (deferred mount), its children vnodes are created but never mounted
- For component children,
vnode.componentisnullbecause the component was never initialized - When the Teleport is unmounted before it can mount, the
removefunction tries tounmountthe children - The
unmountfunction seesshapeFlag & ShapeFlags.COMPONENTis true and callsunmountComponent(vnode.component!, ...)withvnode.componentbeingnull - This causes
TypeError: Cannot read properties of null (reading 'type')
The fix should be in
TeleportImpl.remove: when there's a pending mount, we should skip unmounting children entirely since nothing was ever mounted.Let me check the current code and create a test to reproduce the issue first:
Assistant
Let me look at existing Teleport tests related to Suspense:
Assistant
bash command failed with exit code and I should respond to ninja
Assistant
The previous command likely failed because there's no "Suspense" text in the Teleport spec file. Let me continue with a different approach - I'll check the Suspense spec file for Teleport tests, and also create a test script to reproduce the issue.
Assistant
Good - there are existing tests for defer mode. Let me look at the test around line 65 for "defer mode should work inside suspense" to understand the test patterns, and then check if there's already a test for unmounting a pending teleport with component child.
Assistant
Let me look at the remove function in the Teleport file more closely:
Assistant
Now I understand the bug. The comment says "skip removing children because nothing has been mounted yet" but the code still calls
unmount()on children. The children were never mounted, so theircomponentproperty isnullfor component vnodes, causing the crash.Let me first create a test script to reproduce the issue:
Assistant
Let me check the package.json for test commands and then run the existing tests to understand the testing setup.
Assistant
Let me first run the existing tests to understand the testing setup, then create a reproduction script:
Assistant
Good, existing tests pass. Now let me create a reproduction script to confirm the bug:
Assistant
The previous response was cut off. Let me continue by running the reproduction script to confirm the bug exists.
Assistant
The test file needs to be in the right location. Let me create it in the proper test directory.
Assistant
Let me run this test to confirm the bug exists.
Assistant
The test needs DOM environment. Let me check how the existing Teleport spec handles this since it uses DOM:
Assistant
I see - it uses
@vitest-environment jsdomand imports from@vue/runtime-test. Let me update my test file to match this pattern.Assistant
Let me check how the existing Teleport tests handle the target selector in runtime-test.
Assistant
Let me look at how the defer tests use target. The issue is that the runtime-test environment doesn't support string selectors. Let me check if the defer tests use document elements or nodeOps elements.
Assistant
Let me respond to the user with the next step. I see the tests use
document.createElementfor DOM-based tests that need selectors, andnodeOps.createElementfor tests that don't need selectors. The defer mode tests use real DOM withdocument.createElementanddocument.body.appendChild.Let me look for
createDOMAppanddomRenderto understand how to use them. )<tool_call>
Assistant
Let me use grep instead to find how createDOMApp and domRender are defined.
Assistant
I see - I need to include a proper tool call. Let me update my test file to use the DOM-based approach with vue's createApp and render functions.
Assistant
The user's message is telling me that my last action (creating/updating the test file) was successful. Now I need to run the test to confirm the bug exists. Let me run the test.
Assistant
The test passed, which means I might not be triggering the exact conditions of the bug. Let me look more carefully at the reproduction case. The issue mentions that the crash happens when a Teleport inside a Suspense is unmounted before its mount can run. Let me create a more accurate reproduction that matches the stack trace showing the crash happens during Suspense resolution.
Assistant
I've successfully reproduced the bug. The test fails with exactly the error described in the issue:
TypeError: Cannot read properties of null (reading 'type')Now let me fix the issue. The problem is in the
TeleportImpl.removefunction - when there's a pending mount, it still callsunmount()on children, but those children havevnode.component === nullbecause they were never mounted.Assistant
The user seems to have sent an empty message. The previous tool call to open the file failed with an error about not being able to extract the command. Let me try opening the file again with the correct format.
Assistant
The tool calls are failing. Let me try using bash commands to view and edit the file instead.
Assistant
Now I can see the issue clearly. The comment says "skip removing children because nothing has been mounted yet" but the code below still calls
unmount()on children. When a component child hasvnode.component === null(because it was never mounted), callingunmount()causes the crash.The fix is to skip the children unmount loop when there's a pending mount. Let me apply the fix:
Assistant
Let me use
sedto make the fix instead.Assistant
The user hasn't provided any new information. I was in the middle of fixing the issue. Let me check if my sed command worked correctly and verify the fix.
Assistant
Good, the fix is applied. Now let me run the reproduction test again to confirm the fix works.
Assistant
The crash is fixed! The test no longer throws
TypeError: Cannot read properties of null (reading 'type'). The only failure is the assertion aboutinnerHTMLbeing<!---->instead of'', which is likely just a Suspense placeholder comment node. Let me update the test to verify the fix properly:Assistant
The user is waiting for me to continue. I was in the process of testing my fix. I updated the test file to have a less strict assertion. Now I need to run the test again to confirm the fix works.
Assistant
The fix works. Now let me run the existing Teleport tests to make sure I didn't break anything.
Assistant
Oh no, my sed command was too broad! It also replaced code in the
moveTeleportfunction wherependingMountis not defined. I need to fix this by reverting the change inmoveTeleportand only keeping the fix in theremovefunction.Assistant
I need to fix the accidental change in
moveTeleport. ThemoveTeleportfunction already has the correct check!pendingMounts.has(vnode)on line 397, so the inner condition should just beif (shapeFlag & ShapeFlags.ARRAY_CHILDREN).Assistant
Let me verify the fix is applied correctly in both places - the
removefunction should have the!pendingMountcheck, and themoveTeleportfunction should not have it.Assistant
Good, the
moveTeleportfunction is restored. Let me verify theremovefunction still has the fix.Assistant
Good, both places are now correct. Let me run the Teleport tests again to verify everything passes.
Assistant
All 51 Teleport tests pass. Let me also verify the reproduction test still passes.
Assistant
Now let me also run the Suspense tests to make sure nothing is broken there.
Assistant
All tests pass. Let me now clean up my reproduction test file and verify the final change I made.
Assistant
Now let me verify the final diff of my change:
Assistant
I've completed my fix. Let me now verify the solution against the checklist and run a broader test suite to ensure nothing is broken.
Checklist Review:
-
Reproduced the error - ✅ Created a reproduction test that confirmed the
TypeError: Cannot read properties of null (reading 'type')crash. -
Confirmed fix resolves the error - ✅ The reproduction test passes after applying the fix.
-
Edge cases - Let me think through the edge cases:
- Teleports already mounted:
pendingMountwould beundefined(falsy), so children unmount normally ✅ - Disabled teleports with pending mounts:
pendingMountis still truthy, so children are skipped ✅ - Teleports without array children: The
shapeFlag & ShapeFlags.ARRAY_CHILDRENcheck already handles this ✅ - Teleports with element children (not components): These would also have
vnode.component === null, but the fix skips all unmount calls, which is correct since nothing was mounted ✅
- Teleports already mounted:
-
Existing tests - Let me run the broader runtime-core tests to ensure nothing is broken.
-
Assistant
All 1014 tests in the runtime-core package pass. The fix is complete and verified. Let me submit the solution.
Summary
The Bug: When a
<Teleport>inside a<Suspense>is unmounted before its mount can run (pending state), Vue crashes withTypeError: Cannot read properties of null (reading 'type'). This happens because:- PR #8619 introduced
pendingMountsso teleports defer their mount whenparentSuspense.pendingBranchis set - In this pending state, a teleport's component children have
vnode.component === null(never mounted) - When unmounting,
TeleportImpl.removecallsunmount()on children regardless of whether they were ever mounted - The
unmount()function tries to callunmountComponent(vnode.component!, ...)which crashes onnull
The Fix: Added a
!pendingMount &&guard inTeleportImpl.removebefore unmounting children. If the teleport has a pending mount, its children were never mounted, so we skip callingunmount()on them entirely.Checklist:
- ✅ Reproduced the error - Created a test that confirmed the crash
- ✅ Confirmed fix resolves the error - Test passes after the fix
- ✅ Edge cases handled - Already-mounted teleports, disabled teleports, non-array children all work correctly
- ✅ Ran existing tests - All 1014 runtime-core tests pass (51 Teleport, 57 Suspense, 104 hydration, etc.)
- PR #8619 introduced
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →
- gpt-5.6-lunaCompare side by side →