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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data: Include more details when shallow equality fails in 'useSelect' #67713
Data: Include more details when shallow equality fails in 'useSelect' #67713
Changes from 2 commits
9f92c5e
39bc8c1
b53a3a3
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Object.keys
should work equally well also for arrays. The only difference is that.keys()
returns numbers, whileObject.keys
are strings.The
a.constructor
check will crash whena
isnull
orundefined
, we should guard for that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I should have guessed that 😅
I've borrowed the check for
isShallowEqual
, so it should be safe in this case.Based on your suggestion, I think we can simplify logic to the example below. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But
isShallowEqual
does anif ( a && b )
check before it starts looking ata.constructor
.typeof null
is also'object'
🙀 It will all work only if you exit early whena
orb
is falsy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should stop ignoring the "everything is an object" JS motto 😄
Pushed update in 39bc8c1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning will be confusing when the
b
object has some field that thea
object doesn't have. Then it will report an empty list of non-equal keys.It can happen in practice when we write code like this:
To fix this, we could construct a set of all fields on both objects and then filter it:
But this will fail again for objects like
{}
and{ a: undefined }
which are not shallow equal butkeys
will be[]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means that the
b
run happened with different state or parameters (mostly params, based on your example). That shouldn't be the case for this warning, as it only makes sense with the same state/params.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's true, I've been overthinking it 🙂 Running the
mapSelect
callback twice with the same state shouldn't produce objects like this unless you're doing it on purpose.