-
Notifications
You must be signed in to change notification settings - Fork 58
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
CPLAT-16997 Fix selector hooks redrawing when values haven't changed #730
Conversation
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
@@ -27,8 +27,7 @@ import 'package:over_react/over_react.dart'; | |||
/// list of children and pass that in as shown in the example below: | |||
/// | |||
/// ```dart | |||
/// import 'package:memoize/memoize.dart'; | |||
/// | |||
/// // imemo1 is from the `memoize` package |
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 changed this to work around dependency_validator flagging imports in comments
@@ -497,14 +501,9 @@ class ReactJsReactReduxComponentFactoryProxy extends ReactJsContextComponentFact | |||
|
|||
/// Converts a Redux.dart [Store] into a Javascript object formatted for consumption by react-redux. | |||
JsReactReduxStore _reduxifyStore(Store store) { | |||
// Memoize this so that the same ReactInteropValue instances will be used | |||
// for a given state, allowing JS `===` checks to not fail when the same | |||
// state object is passed. |
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.
Since we pass through the value directly (and memoize it in the cases we wrap it in DartValueWrapper.wrapIfNeeded
), this is no longer necessary
}); | ||
}); | ||
}); | ||
} |
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.
These tests have moved to store_bindings_tests.dart. I started by refactoring them to use custom components so they could be run with multiple types of selected values, and they eventually morphed into tests that could also be shared with connect, thus the new file name.
@@ -0,0 +1,420 @@ | |||
// Copyright 2022 Workiva Inc. |
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'm open to better name suggestions for this file
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.
QA +1
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.
+1, looks great! Those are some dope tests 🎉
if (allValues.toSet().length != allValues.length) { | ||
throw ArgumentError('initialValue and updatedValues must all be unique.'); | ||
} |
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.
Oohh this is clever. TIL
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.
+1
@Workiva/release-management-p |
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.
+1 from RM
Motivation
The
useSelector
hook and hooks created bycreateSelectorHook
allow consumers to subscribe to store updates and rerender the component only when a value returned from the selector function changes.However, the Dart versions of these APIs were always rerendering, even when the selected value didn't change.
This was caused by two issues:
ReactInteropValue
object, which meant that when you didn't provide a custom equality function, the default behavior on the JS side of comparing the value using===
would always think the value changednull
into the hook as an equality function as opposed to conditionally calling it, which was causing null errors in React Redux JS that were getting ignoredChanges
Release Notes
Review
See CONTRIBUTING.md for more details on review types (+1 / QA +1 / +10) and code review process.
Please review:
QA Checklist
webdev serve
BigCounter
buttons, and stop the profileMerge Checklist
While we perform many automated checks before auto-merging, some manual checks are needed: