Skip to content

fix(unplugin): avoid Iterator helpers for Node 20 compat#2635

Merged
posva merged 1 commit intovuejs:mainfrom
cwandev:fix/iterator-compat-node20
Feb 24, 2026
Merged

fix(unplugin): avoid Iterator helpers for Node 20 compat#2635
posva merged 1 commit intovuejs:mainfrom
cwandev:fix/iterator-compat-node20

Conversation

@cwandev
Copy link
Copy Markdown
Contributor

@cwandev cwandev commented Feb 24, 2026

Closes #2633

Summary by CodeRabbit

  • Refactor
    • Optimized internal route conflict detection logic for improved code maintainability.

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 24, 2026

Deploy Preview for vue-router canceled.

Name Link
🔨 Latest commit e402617
🔍 Latest deploy log https://app.netlify.com/projects/vue-router/deploys/699dc5c6d378540008618b4c

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

The change fixes a Node.js 20 compatibility issue in collectDuplicatedRouteNodes by reformatting the dups array construction. Instead of calling .filter() directly on a MapIterator (unavailable before Node.js 22), the code now converts the iterator to an array first using Array.from(), then applies filter and map operations.

Changes

Cohort / File(s) Summary
Node.js 20 Compatibility Fix
packages/router/src/unplugin/core/tree.ts
Refactored collectDuplicatedRouteNodes to wrap Map.prototype.values() with Array.from() before applying .filter() and .map(), since iterator helper methods are unavailable in Node.js 20 (V8 11.x). Maintains identical observable behavior and method signature.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • posva

Poem

🐰 A tiny hop to fix Node 20,
Iterator helpers? Not quite ready!
Array.from() saves the day,
Filtering works the proper way,
Compatibility hops, steady and true!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing Node 20 compatibility by avoiding Iterator helpers in the unplugin.
Linked Issues check ✅ Passed The code changes directly address issue #2633 by refactoring collectDuplicatedRouteNodes to avoid Iterator.prototype.filter, restoring Node 20 compatibility.
Out of Scope Changes check ✅ Passed All changes are focused on fixing the Node 20 compatibility issue in collectDuplicatedRouteNodes; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/router/src/unplugin/core/tree.ts (1)

626-638: Prefer nodes.length for duplicate detection (Line 627).
nodes is an array; Object.keys(nodes).length allocates and is less idiomatic. nodes.length is clearer and avoids surprises if the array ever becomes sparse.

♻️ Suggested change
-  const dups = Array.from(seen.values())
-    .filter(nodes => Object.keys(nodes).length > 1)
+  const dups = Array.from(seen.values())
+    .filter(nodes => nodes.length > 1)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/router/src/unplugin/core/tree.ts` around lines 626 - 638, The
duplicate-detection is using Object.keys(nodes).length on the array `nodes`
inside the `dups` computation; change that to use `nodes.length > 1` for clarity
and performance. Update the filter in the `dups` pipeline (the block using
`seen.values()` and mapping to `nodes.toSorted(...)`) to check `nodes.length >
1` instead of `Object.keys(nodes).length > 1`, leaving the rest of the logic
involving `nodes`, `seen`, and `treeNodes` unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/router/src/unplugin/core/tree.ts`:
- Around line 626-638: The duplicate-detection is using
Object.keys(nodes).length on the array `nodes` inside the `dups` computation;
change that to use `nodes.length > 1` for clarity and performance. Update the
filter in the `dups` pipeline (the block using `seen.values()` and mapping to
`nodes.toSorted(...)`) to check `nodes.length > 1` instead of
`Object.keys(nodes).length > 1`, leaving the rest of the logic involving
`nodes`, `seen`, and `treeNodes` unchanged.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f7bbf1 and e402617.

📒 Files selected for processing (1)
  • packages/router/src/unplugin/core/tree.ts

@posva
Copy link
Copy Markdown
Member

posva commented Feb 24, 2026

Thanks!

@posva posva merged commit 4713069 into vuejs:main Feb 24, 2026
5 checks passed
@cwandev cwandev deleted the fix/iterator-compat-node20 branch February 24, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Build fails on Node 20: seen.values(...).filter is not a function in collectDuplicatedRouteNodes

2 participants