fix(reactivity): collection iteration should inherit iterator instance methods#12644
fix(reactivity): collection iteration should inherit iterator instance methods#12644edison1105 merged 5 commits intomainfrom
Conversation
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
📝 WalkthroughWalkthroughIterator wrapper in reactivity was changed to inherit from the original iterator via Object.create(innerIterator) and override only next(), preserving the inner iterator’s prototype and properties while keeping the existing value-wrapping behavior. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/reactivity/src/collectionHandlers.ts (1)
56-73: LGTM: iterator wrapper now preserves iterator instance/prototype methods while still wrapping yielded values.
TheObject.create(innerIterator)+ overridenext()approach should fix the reported loss of iterator methods aftervalues()/keys()/entries()while keepinginnerIterator.next()as the source of truth.Add a regression test for “iterator methods preserved” without relying on runtime Iterator Helpers.
Consider a unit test that temporarily augmentsObject.getPrototypeOf(rawMap.values())with a sentinel method (restore afterward), then assertsreactive(map).values()exposes it and still yields wrapped values.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/reactivity/src/collectionHandlers.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: naramdash
Repo: vuejs/core PR: 14058
File: packages/reactivity/src/collectionHandlers.ts:252-271
Timestamp: 2025-11-05T14:53:01.052Z
Learning: In Vue's reactivity system, collection methods that create new collections (like Array's slice(), concat(), filter() and Set's difference(), intersection(), union(), symmetricDifference()) intentionally return raw (non-reactive) collections, not reactive proxies. This is by design - only the values/elements inside can remain reactive if they were originally reactive.
🧬 Code graph analysis (1)
packages/reactivity/src/collectionHandlers.ts (1)
packages/shared/src/general.ts (1)
extend(24-24)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test / e2e-test
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/reactivity/__tests__/collections/Map.spec.ts (1)
475-498: LGTM! Test comprehensively validates iterator property inheritance.The test correctly validates that the wrapped iterator preserves the prototype chain from the raw iterator, including both named properties and symbols. The checks for
next,Symbol.iterator, and the iterable protocol (line 485) are all appropriate.📋 Optional: Consider testing other iterator methods
While
.entries()is tested here, you might also want to verify.values()and.keys()iterators inherit properties correctly, since the original issue #12615 specifically mentioned.values():// Additional test cases const valuesIterator = map.values() expect(typeof valuesIterator.next).toBe('function') expect(typeof valuesIterator[Symbol.iterator]).toBe('function') const keysIterator = map.keys() expect(typeof keysIterator.next).toBe('function') expect(typeof keysIterator[Symbol.iterator]).toBe('function')This would provide more comprehensive coverage of all iterator methods affected by the fix.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/reactivity/__tests__/collections/Map.spec.ts
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: naramdash
Repo: vuejs/core PR: 14058
File: packages/reactivity/src/collectionHandlers.ts:252-271
Timestamp: 2025-11-05T14:53:01.052Z
Learning: In Vue's reactivity system, collection methods that create new collections (like Array's slice(), concat(), filter() and Set's difference(), intersection(), union(), symmetricDifference()) intentionally return raw (non-reactive) collections, not reactive proxies. This is by design - only the values/elements inside can remain reactive if they were originally reactive.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: test / e2e-test
|
/ecosystem-ci run |
|
📝 Ran ecosystem CI: Open
|
close #12615
Summary by CodeRabbit
Refactor
Tests
Chores
Note: No functional or API changes for end users.
✏️ Tip: You can customize this high-level summary in your review settings.