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 start by exploring the repository structure to understand the codebase and then locate the relevant files for this issue.
Assistant
Let me look at the Teleport component file in runtime-core:
Assistant
Now let me look at the
removemethod more closely. I can see the issue is in theremovefunction around line 235-265. Let me check the unmount function being called:Assistant
This is the key part! The
unmountfunction callsunmountComponent(vnode.component!, ...)when the shapeFlag indicates it's a component. The issue is that when a Teleport is pending (hasn't been mounted yet due to Suspense), its children can havevnode.component === null, but the code still tries to callunmountComponentwith a null component.Let me look at the entire
unmountfunction:Assistant
Now let me look at the TeleportImpl.remove method more carefully:
Assistant
Let me see the remove method:
Assistant
Now I can see the issue! When there's a
pendingMount, the code setsshouldRemove = false, but then it still proceeds to unmount the children. The children of a pending teleport may havevnode.component === null, which causes the crash whenunmounttries to callunmountComponent(vnode.component!, ...).Let me check if there are tests for this:
Assistant
Let me look at the existing Teleport tests to understand the testing patterns:
Assistant
Let me check the Suspense tests:
Assistant
Let me look at those specific tests:
Assistant
Now let me create a test script to reproduce the issue described:
Assistant
Let me check the package structure and build the project first:
Assistant
Let me run the tests to see if they reproduce the issue:
Assistant
Let me try a different approach - let me look for the test file mentioned in the issue:
Assistant
The test file doesn't exist. Let me look at the git history to see if there's any recent changes to Teleport.ts that might give me a clue:
Assistant
Now let me check for issue #14642 that was mentioned:
Assistant
Now I understand the issue. Looking at the
removemethod in Teleport.ts, when there's a pending mount (teleport hasn't mounted yet due to Suspense), the code:- Detects the pending mount and sets
shouldRemove = false - But still proceeds to unmount the children by calling
unmount(child, ...)
The problem is that for component children that haven't been mounted yet,
child.componentisnull. Whenunmountis called on such a child, it tries to callunmountComponent(vnode.component!, ...)which crashes.The fix is simple: when there's a pending mount, we should return early and not try to unmount children at all, since they were never mounted.
Let me first verify the current state of the code:
- Detects the pending mount and sets
Assistant
The comment says "skip removing children because nothing has been mounted yet", but the code doesn't actually skip removing children - it still loops through them and calls
unmount().The fix should be to return early when there's a pending mount, after clearing it. Let me check if the anchor and target anchors exist in this case:
Looking at the code flow:
- When a Teleport is created but deferred (due to Suspense), the
processfunction creates placeholders (elandanchor) but returns early before mounting children. - So
targetStart,targetAnchor, andtargetwould be undefined/null in this case. - The anchor would exist (it's created before the early return).
So the fix is to add a
returnstatement after clearing the pending mount. Let me implement this:- When a Teleport is created but deferred (due to Suspense), the
Assistant
Good! Now I need to think about whether we should also remove the anchor. Let me check what happens when the Teleport is first created:
Assistant
So when a Teleport is created:
- It creates
el(placeholder) andanchor(mainAnchor) and inserts them into the DOM - If deferred/pending, it queues the mount and returns
When unmounting a pending Teleport, we need to remove these anchors from the DOM. Let me update the fix:
- It creates
Assistant
Let me apply the fix manually:
Assistant
Now I need to add the
elto the destructuring and add the return statement. Let me make the edit:Assistant
I see I made a mistake and removed too much code. Let me restore the file and apply the fix correctly:
Assistant
Now I need to add
elto the destructuring and add the return statement. Let me do this step by step:Assistant
I made a mistake with the edit command - I accidentally removed the destructuring assignment. Let me restore the file and try again with the correct approach.
Assistant
Let me use a different approach - use replace instead:
Assistant
Let me use the proper format:
Assistant
Good! Now let me add the return statement after setting
shouldRemove = false:Assistant
Perfect! Now let me verify the fix by looking at the entire remove method:
Assistant
Perfect! The fix is in place. Now let me create a simple test to verify the fix works:
Assistant
Great! The Suspense tests pass. Now let me run the Teleport tests as well to make sure I didn't break anything:
Assistant
Excellent! All tests pass. Now let me create a specific test to reproduce the exact issue described to make sure my fix works:
Assistant
The test file needs to be in the right location. Let me create it properly:
Assistant
The test file I created has issues. Let me fix it and simplify the test:
Assistant
The test doesn't need the async component - the teleport inside Suspense will be pending because Suspense hasn't resolved yet. But the test structure isn't right. Let me look at the existing test that was added for #14701:
Assistant
Now I understand the pattern better. Let me look at the issue description more carefully. The issue says the crash happens when unmounting the Suspense, not when resolving it. Let me write a better test:
Assistant
Let me add a test to the existing Suspense.spec.ts file to verify the fix:
Assistant
Let me add a test after the #14701 test to specifically test unmounting:
Assistant
Now I need to add a test after line 2612 to verify that unmounting a suspense with a pending teleport doesn't crash. Let me insert it right after the #14701 test.
Assistant
I made a mistake - I deleted the closing brace. Let me restore and try again:
Assistant
Let me use replace instead to add the test:
Assistant
Perfect! Now let's run the test to see if it passes with my fix:
Assistant
The test is failing because when we return null from the render function, Vue renders a comment node. Let me fix the test expectation:
Assistant
Now let's run the test again:
Assistant
Great! The test passes now. Let me verify that my fix actually prevents the crash by temporarily reverting it and seeing if the test fails:
Assistant
Let me create a temporary version without my fix to confirm it would fail:
Assistant
The test was skipped because I used git stash. Let me try a different approach - create a simple script to test if the bug exists without my fix:
Assistant
The grep didn't capture the output properly. Let me run it differently:
Assistant
The test doesn't exist without my changes because I added it. Let me restore my changes and run all the tests to make sure everything works:
Assistant
Now let me run all tests to make sure my fix doesn't break anything:
Assistant
Perfect! All component tests pass. Let me also run the full test suite for runtime-core to be extra sure:
Assistant
Excellent! All 1015 tests pass. Now let me check the diff one more time to verify my fix is correct:
Assistant
I need to continue verifying the fix by checking the test changes and then submit the solution.
Assistant
Let me verify the fix is complete by reviewing the checklist:
Assistant
Let me verify my fix one more time by checking the exact code changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.