fix(mobx): ObservableSet union/intersection/symmetricDifference result ordering#4681
Open
spokodev wants to merge 1 commit into
Open
fix(mobx): ObservableSet union/intersection/symmetricDifference result ordering#4681spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
union, intersection and symmetricDifference delegated to the argument when it was a plain Set, so results came out in the argument's order instead of the receiver's. Build every result from the receiver, as difference/isSubsetOf/isSupersetOf already do, to match native Set.
🦋 Changeset detectedLatest commit: cf9f892 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Pull request overview
This pull request fixes ObservableSet’s ES2024 Set-method result ordering (union, intersection, symmetricDifference) so it matches native Set semantics when the argument is a plain (non-observable) Set, and aligns isDisjointFrom to the same delegation pattern for consistency.
Changes:
- Update
ObservableSetES2024 set methods to always compute results from the receiver vianew Set(this).<method>(otherSet), ensuring receiver-based ordering. - Add an order-sensitive test that compares
ObservableSetiteration order against a nativeSetcopy using the same operations. - Add a patch changeset documenting the ordering fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/mobx/src/types/observableset.ts | Ensure ES2024 Set operations on ObservableSet preserve receiver-based result ordering by delegating through new Set(this) consistently. |
| packages/mobx/tests/base/set.js | Add an order-sensitive regression test to verify behavior matches native Set when operating with a plain Set argument. |
| .changeset/fix-observableset-receiver-order.md | Document the behavioral fix as a patch-level change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ObservableSetimplementsSet<T>, so its ES2024 set methods should match nativeSetresult ordering:unionappends the argument's new elements after the receiver's, andintersectionandsymmetricDifferencekeep the receiver's order. When the argument is a plain (non-observable)Set,union,intersectionandsymmetricDifferenceinstead delegate to the argument (otherSet.method(this)), so the result comes out in the argument's order.Values and membership are correct, so this slipped past the existing tests, which compare with
toEqual(new Set([...]))(order-insensitive). It surfaces whenever the result is iterated (spread,Array.from,forEach, rendering a list) after moving from a plainSettoobservable.set.Fix
Build the result from the receiver in every case:
return new Set(this).method(otherSet), matching the already-correctdifference,isSubsetOfandisSupersetOf. The observable-argument case already used this form (the previouselsebranch), so the#3919stack-overflow behavior is unchanged; only the plain-Setpath changes, from argument-order to receiver-order.isDisjointFromis aligned to the same form as well (its boolean result was already correct, so this is only for consistency).Testing
Added an order-sensitive test to
__tests__/base/set.jsthat compares against a nativeSetbuilt from the same receiver. It fails before this change; the full set suite (28 tests, including the#3919case) stays green with it.