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 and find the relevant files related to the issue.
The issue is about a crash when unmounting a Teleport inside a Suspense before it can mount. The error occurs because
vnode.componentis null and the code tries to accessvnode.component.type.Let me first explore the repository structure and understand the code.
Assistant
Let me explore the packages directory to find the runtime-core package where the Teleport and Suspense implementations are likely located.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /core/packages </tool_call>
Assistant
Let me explore the packages directory to find the runtime-core package where the Teleport and Suspense implementations are located.
Assistant
Now let me look at the runtime-core package structure and find the Teleport implementation.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /core/packages/runtime-core </tool_call>
Assistant
Let me explore the runtime-core package to find the Teleport implementation.
Assistant
Now let me look at the source files in the runtime-core package to find the Teleport implementation.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /core/packages/runtime-core/src </tool_call>
Assistant
Let me explore the runtime-core source directory to find the Teleport implementation.
Assistant
Now let me look at the components directory to find the Teleport implementation.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /core/packages/runtime-core/src/components </tool_call>
Assistant
Let me explore the components directory to find the Teleport implementation.
Assistant
Now let me examine the Teleport.ts file to understand the current implementation and find where the issue is.
Assistant
Let me view the file in sections since it was truncated. Let me search for the specific part where
unmountComponentis called on children.<tool_call> <function=bash_terminal> <parameter=command> grep -n "unmount" /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me search for the unmount references in the Teleport.ts file.
Assistant
Now let me look at the
unmountfunction more carefully. The issue is that when a teleport inside suspense is unmounted before it can mount, the children might havevnode.component === null. The code currently only handles the case where it's a pending mount and skips removing children. But it then still callsunmount()on each child, which in turn might callunmountComponenton a component child withvnode.component === null.Let me see the unmount function in TeleportImpl:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '320,375p' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me view the unmount function in TeleportImpl more carefully.
Assistant
Now I understand the issue. Looking at the unmount function:
- The code already has a check for
pendingMount(lines 335-342) that setsshouldRemove = false - But then the code still iterates through all children and calls
unmount()on each child (lines 355-362) - When a child has
vnode.component === null(because it was deferred in a pending suspense), callingunmount()on it can lead to a crash
The issue is that when there's a pending mount, the children haven't been mounted yet, so calling
unmount()on them can cause issues. The fix should skip the unmount loop entirely when there's a pending mount, similar to howshouldRemoveis set tofalse.Let me also look at the
unmountComponentfunction in the renderer to understand what exactly is failing:<tool_call> <function=bash_terminal> <parameter=command> grep -n "unmountComponent" /core/packages/runtime-core/src/renderer.ts | head -20 </tool_call>
- The code already has a check for
Assistant
Let me search for the unmountComponent function to understand where the crash happens.
Assistant
Let me look at the unmountComponent function to understand the crash:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '2312,2400p' /core/packages/runtime-core/src/renderer.ts </tool_call>
Assistant
Let me look at the unmountComponent function to understand the crash.
Assistant
Now let me understand the issue better. The crash happens when
unmountComponentis called with an instance wheresubTreeis a vnode withvnode.component === null. This is because the teleport's children were never mounted due to the pending suspense.Let me also check the unmount function to see how it handles component vnodes:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "unmount = " /core/packages/runtime-core/src/renderer.ts | head -5 </tool_call>
Assistant
Let me search for the unmount function definition and understand how it handles component vnodes.
Assistant
The crash happens at line 2173 where
unmountComponent(vnode.component!, parentSuspense, doRemove)is called. Thevnode.component!is null because the teleport's children havevnode.component === nullwhen the teleport hasn't mounted yet due to pending suspense.Now I understand the issue:
- When a teleport is inside a suspense and is deferred (pending suspense), its children are never mounted
- When the teleport is unmounted, it calls
unmount()on each child - The children might be component vnodes that have
vnode.component === nullbecause they were never mounted - The
unmountfunction tries to callunmountComponent(vnode.component!, ...)which crashes becausevnode.componentis null
The fix should be to skip unmounting children entirely when there's a pending mount. Let me look at the Teleport.ts unmount function again and apply the fix.
Let me check the existing tests to understand the expected behavior:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /core/packages/runtime-core/tests </tool_call>
Assistant
Let me check the runtime-core test directory to find tests related to teleport and suspense.
Assistant
Let me check the components test directory for teleport-related tests.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /core/packages/runtime-core/tests/components </tool_call>
Assistant
Let me check the components test directory for teleport and suspense related tests.
Assistant
Let me check if there are any tests related to pending suspense and teleport unmount:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "pendingMount|defer" /core/packages/runtime-core/tests/components/Teleport.spec.ts | head -30 </tool_call>
Assistant
Let me search for pendingMount references in the Teleport tests.
Assistant
Now let me see if there are any tests for the unmount case with deferred/defer mode and suspense:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "unmount|remove" /core/packages/runtime-core/tests/components/Teleport.spec.ts | head -50 </tool_call>
Assistant
Let me search for unmount tests in the Teleport spec file.
Assistant
Now, let me look at the issue more carefully. The problem is that when a teleport inside a suspense is unmounted before it can mount (pending mount), the code tries to unmount children even though they were never mounted. If any of those children are component vnodes, they will have
vnode.component === nullwhich causes the crash whenunmountComponentis called.Looking at the unmount function in Teleport.ts (lines 320-364):
javascriptAssistant
Let me search for Teleport references in the Suspense spec file.
Assistant
I see there's a test "should not crash when moving disabled teleport with component children inside suspense". Let me look at this test to understand what's being tested and see if there's a similar unmount test.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '2577,2640p' /core/packages/runtime-core/tests/components/Suspense.spec.ts </tool_call>
Assistant
Let me look at this test to understand the scenario being tested.
Assistant
This test is about moving/disabled teleport with component children, not about unmounting. Let me now look at the reproduction repo to understand the exact test case that fails.
Let me first check if there's a tests directory in the repo mentioned in the issue:
<tool_call> <function=bash_terminal> <parameter=command> find /core -name "teleport-unmount*" -o -name "teleportunmount*" 2>/dev/null </tool_call>
Assistant
Let me search for tests related to teleport unmount in the entire repository.
Assistant
Let me now try to reproduce the issue by running the tests.
Assistant
Let me try a simpler approach - let me look at the issue description and the Teleport.ts file to understand what fix is needed.
Based on the issue description:
- In 3.5.31, PR #8619 introduced
pendingMountsso teleports defer their mount whenparentSuspense.pendingBranchis set - In 3.5.32, PR #14642 added a
pendingMountcheck that gates DOM removal of element children, not theunmountComponent(null, …)call on component children - In 3.5.33, PR #14702 added
pendingMounts.has(vnode)guard inmoveTeleport, but theTeleportImpl.removepath was not touched
The fix should be in the
unmountfunction ofTeleportImplto skip unmounting children when there's a pending mount, not just setshouldRemove = false.Let me look at the exact unmount function again:
- In 3.5.31, PR #8619 introduced
Assistant
Now I understand the issue. When there's a pending mount:
- The code correctly removes the target anchors
- The code sets
shouldRemove = false - But it still calls
unmount()on all children, which can cause a crash if any child is a component vnode withvnode.component === null
The fix should be to skip the unmount loop entirely when there's a pending mount. Let me apply the fix:
<tool_call> <function=bash_terminal> <parameter=command> cat /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Now I understand the issue. The fix should be to skip the unmount loop entirely when there's a pending mount. Let me apply the fix to the Teleport.ts file.
Assistant
Now I understand the issue. The fix should be to skip the unmount loop entirely when there's a pending mount, not just set
shouldRemove = false. Let me apply the fix.Assistant
Let me check the result and apply a better fix. The issue is more nuanced - I need to modify the logic to skip the unmount loop when there's a pending mount.
Assistant
Now I need to add a condition to skip the unmount loop when there's a pending mount. Let me modify the code to add this check.
<tool_call> <function=bash_terminal> <parameter=command> sed -i '354s/ if (shapeFlag & ShapeFlags.ARRAY_CHILDREN)/ if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount)/' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me try again with the correct escaping.
Assistant
Let me verify the fix was applied correctly.
Assistant
The fix wasn't applied. Let me try a different approach using the
editcommand or a different sed command.<tool_call> <function=bash_terminal> <parameter=command> sed -n '355p' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me try a different approach to edit the file. The sed command might not be working as expected due to special characters.
Assistant
Let me verify the fix was applied correctly.
Assistant
The fix was applied. Now let me verify the full context of the fix to make sure it's correct.
Assistant
Assistant
Let me try running the tests again with a simpler command.
Assistant
Ah, I see the issue! The fix was applied to the
removefunction but not to themoveTeleportfunction. The error shows that thependingMountvariable is not defined inmoveTeleport. This is because I accidentally applied the fix to the wrong place.Looking at the error:
code❯ moveTeleport packages/runtime-core/src/components/Teleport.ts:402:51 400| if (!pendingMounts.has(vnode) && (!isReorder || isTeleportDisabled(p… 401| // Teleport has either Array children or no children. 402| if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {It seems like my sed command replaced the
pendingMounts.has(vnode)check inmoveTeleportas well. Let me check themoveTeleportfunction and fix it.<tool_call> <function=bash_terminal> <parameter=command> sed -n '385,430p' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me view the moveTeleport function to understand the issue and fix it.
Assistant
I see the problem. My sed command accidentally replaced the
!pendingMounts.has(vnode)check inmoveTeleportwith!pendingMount, which caused the error becausependingMountis not defined in that function.The original code at line 400 was:
javascriptif (!pendingMounts.has(vnode) && (!isReorder || isTeleportDisabled(props))) {And my sed command changed it to:
javascriptAssistant
Let me check all occurrences of pendingMount in the file to understand what changes were made.
Assistant
The issue is clear now. My sed command replaced
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN)withif (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount)in two places:- Line 355 - This is in the
removefunction, and this is correct. - Line 402 - This is in the
moveTeleportfunction, and this is incorrect becausependingMountis not defined inmoveTeleport.
I need to revert the change in
moveTeleport(line 402). Let me do that.<tool_call> <function=bash_terminal> <parameter=command> sed -i '402s/if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount)/if (shapeFlag & ShapeFlags.ARRAY_CHILDREN)/' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
- Line 355 - This is in the
Assistant
Let me verify the fix was applied correctly.
Assistant
The fix wasn't applied. Let me try again with a different approach.
<tool_call> <function=bash_terminal> <parameter=command> sed -i '402s/&& !pendingMount//' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me check if the fix was applied correctly.
Assistant
The sed command didn't work as expected. Let me try a different approach using the
editcommand to fix the specific line.<tool_call> <function=bash_terminal> <parameter=command> sed -n '402p' /core/packages/runtime-core/src/components/Teleport.ts | cat -A </tool_call>
Assistant
Let me view the raw bytes of line 402 to understand what's happening.
Assistant
I see - the line has
&& !pendingMountat the end. Let me try to replace it using a different approach.Assistant
Let me verify the fix was applied correctly.
Assistant
Now let me also verify that the fix in the
removefunction (line 355) is still there.Assistant
Now let me run the tests again to see if the fix works.
Assistant
All Teleport tests pass. Now let me also run the Suspense tests to make sure the fix doesn't break anything there.
Assistant
All Suspense tests pass as well. Now let me also run all the runtime-core tests to make sure nothing is broken.
Assistant
All 1014 tests in the runtime-core package pass. Now let me also update the comment in the
removefunction to make it clearer that we skip unmounting children when there's a pending mount.<tool_call> <function=bash_terminal> <parameter=command> sed -n '335,365p' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me view the comment in the remove function to make sure it's clear about what we're doing.
Assistant
The comment "an unmounted teleport should always unmount its children whether it's disabled or not" is now misleading because we're not unmounting children when there's a pending mount. Let me update the comment to make it clearer.
Let me also clean up the redundant comment. I'll replace the comment section with a clearer one.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '348,365p' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me update the comment to make it clearer that we skip unmounting children when there's a pending mount.
Assistant
Let me verify the change was applied correctly.
Assistant
I see there's a missing closing brace
}for theif (target)block. Let me fix this.Assistant
Let me verify the change was applied correctly.
Assistant
The file got corrupted. Let me restore it from git and apply the fix properly.
Assistant
Let me now apply the fix properly. First, let me view the original file to understand the structure.
Assistant
Now let me apply the fix properly. I'll use sed to only change the specific line in the
removefunction.Assistant
Let me verify the fix was applied correctly.
Assistant
Now let me verify that the
moveTeleportfunction is not affected.Assistant
It looks like the sed command also affected the
moveTeleportfunction. Let me check line 399 to see what happened.<tool_call> <function=bash_terminal> <parameter=command> sed -n '395,405p' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
The sed command is affecting all lines that match the pattern, not just the one in the
removefunction. I need to revert the changes and apply the fix more carefully, only to the specific line in theremovefunction.Assistant
Let me now apply the fix more carefully. I need to target only the specific line in the
removefunction. Looking at the line numbers, the line I need to change is line 353 (0-indexed 352). Let me use a different approach - I'll use a combination of head, echo, and tail to reconstruct the file with the fix.First, let me see the exact content of the lines around the target:
Assistant
Now I can see that line 352 contains the pattern
if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {. I need to change only this line toif (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {.Let me use a more targeted approach by using the line number:
<tool_call> <function=bash_terminal> <parameter=command> head -n 351 /core/packages/runtime-core/src/components/Teleport.ts > /tmp/teleport_new.ts && echo ' if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {' >> /tmp/teleport_new.ts && tail -n +353 /core/packages/runtime-core/src/components/Teleport.ts >> /tmp/teleport_new.ts && mv /tmp/teleport_new.ts /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me verify the change was applied correctly by viewing the modified lines.
Assistant
The change wasn't applied. It seems the head/tail approach didn't work as expected. Let me check what happened.
Assistant
Let me verify the change was applied correctly.
Assistant
The file got corrupted again. Let me restore it and try a different approach.
Assistant
Let me try using the
editcommand instead, which should be more reliable for editing specific lines.<tool_call> <function=bash_terminal> <parameter=command> edit --file /core/packages/runtime-core/src/components/Teleport.ts 353:353 " if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {" </tool_call>
Assistant
Let me check if the
editcommand works by viewing the file first.Assistant
Let me try using the
opencommand correctly.Assistant
Good, now I can see the file. The line I need to change is line 352. Let me use the
editcommand to change it.<tool_call> <function=bash_terminal> <parameter=command> edit 352:352 " if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {" </tool_call>
Assistant
The
editcommand didn't work. Let me try a different approach - I'll usebash_terminalto run theeditcommand properly.Assistant
It seems like the
bash_terminalcommand is not available within the shell. Let me try to use a Python script to make the replacement.<tool_call> <function=bash_terminal> <parameter=command> python3 -c " import re
with open('/core/packages/runtime-core/src/components/Teleport.ts', 'r') as f: content = f.read()
Replace only the line in the remove function
Find the specific pattern and replace it
old_pattern = ' if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {' new_pattern = ' if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {'
We need to be careful to only replace the one in the remove function
Let's split by lines and replace the specific one
lines = content.split('\n') for i, line in enumerate(lines): if ' if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {' in line: # Check if this line is in the remove function (before line 376 which starts moveTeleport) if i < 375: # Line numbers are 0-indexed, so 375 is line 376 lines[i] = line.replace(' if (shapeFlag & ShapeFlags.ARRAY_CHILDREN) {', ' if (shapeFlag & ShapeFlags.ARRAY_CHILDREN && !pendingMount) {') print(f'Replaced line {i+1}: {lines[i]}') break
Assistant
Let me create a Python script to make the replacement properly:
Assistant
Let me check what's available:
Assistant
Let me use node instead:
Assistant
The fix was applied correctly. Let me verify the change and make sure the
moveTeleportfunction is not affected:Assistant
Now let me also verify that the
moveTeleportfunction is not affected:Assistant
Let me verify that the
moveTeleportfunction at line 397 is not affected by checking if it still usespendingMounts.has(vnode)instead of!pendingMount.Assistant
The fix was applied correctly. The
moveTeleportfunction at line 397-399 is correctly unchanged. Now let me run the tests to verify the fix works:Assistant
All Teleport tests pass. Now let me also run the Suspense tests to make sure the fix doesn't break anything there:
Assistant
All Suspense tests pass as well. Now let me also run all runtime-core tests to make sure nothing is broken:
Assistant
All 1014 tests pass. Now let me also think about edge cases and make sure the fix handles them correctly.
Edge cases to consider:
-
Deferred teleport with component children: This is the main issue that was reported. The fix skips unmounting children when there's a pending mount, which prevents the crash when
unmountComponentis called on a component vnode withvnode.component === null. -
Deferred teleport with element children: The fix should also handle this case. Since the children were never mounted, they should not need to be unmounted.
-
Teleport that was mounted and then unmounted: The fix should not affect this case because there won't be a pending mount.
-
Teleport with disabled prop: The fix should not affect this case because the pending mount check is independent of the disabled prop.
Let me also check if there are any other tests related to teleport unmount that I should run:
<tool_call> <function=bash_terminal> <parameter=command> cd /core && npx vitest run packages/runtime-dom/tests/ 2>&1 | tail -30 </tool_call>
-
Assistant
Let me run the runtime-dom tests to make sure the fix doesn't break anything there.
Assistant
All runtime-dom tests pass as well. Now let me also verify the fix by looking at the final state of the changed file:
<tool_call> <function=bash_terminal> <parameter=command> cd /core && git diff packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me view the git diff to see the changes made to the file.
Assistant
The fix is correctly applied. The only change is adding
&& !pendingMountto the condition on line 352, which skips unmounting children when there's a pending mount.Let me also consider if I should add a comment to explain why we're skipping unmounting children when there's a pending mount. Looking at the existing comments:
Assistant
The comment update command didn't work properly due to the escaping issues. Let me verify the current state of the file and think about whether the comment update is necessary. The fix itself is correct - we're adding
&& !pendingMountto skip unmounting children when there's a pending mount. The comment is already accurate enough since it says "skip removing children because nothing has been mounted yet". Let me verify the fix is complete and run all tests again to ensure everything works.Assistant
The comment update wasn't applied, but the core fix is correct. Let me revert that change (if it was applied) and ensure the fix is clean. Let me check the current state of the file:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '348,365p' /core/packages/runtime-core/src/components/Teleport.ts </tool_call>
Assistant
Let me check the current state of the file to see if the comment was changed.
Assistant
The fix is correctly applied. The change adds
&& !pendingMountto skip unmounting children when there's a pending mount. The comment above the line is still accurate because it says "an unmounted teleport should always unmount its children whether it's disabled or not" - this is true for the normal case where the teleport was mounted. The fix only affects the case where there's a pending mount, in which case the teleport was never mounted.Now let me run all the tests one more time to ensure everything works correctly:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.