-
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
FED-1889 Null Safety: Audit public utility components #855
FED-1889 Null Safety: Audit public utility components #855
Conversation
aaronlademann-wf
commented
Nov 13, 2023
- Prop nullability, upgrade props/state to late for public components, update class component prop defaulting
- ErrorBoundary
- ResizeSensor
- AbstractTransition
- WithTransition
- FluxUiComponent
- ConnectFluxPropsMixin
- ReduxProviderPropsMixin
- ReduxMultiProvider (storesByContext)
Since they are internal implementation details that are never set to null.
No reason for these local vars that are initialized immediately to be nullable / typed on the left side.
I’m not actually sure this would cause a problem, but it seemed like an awkward way to set the default IMO.
Since it is an internal implementation detail that is never set to null. This also required that the `initiallyShown` abstract getter become non-nullable.
Since it is an internal implementation detail that is never set to null.
Same with the actions params that get passed around `connectFlux` utils
Security InsightsNo security relevant content was detected by automated scans. Action Items
Questions or Comments? Reach out on Slack: #support-infosec. |
…-safety_public-util-components
since Dart can’t infer non-null types on class fields :(
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.
Just two small comments, one of em a question. This looks great!
/// There is no strict rule on the [ActionsT] type. Depending on application | ||
/// structure, there may be [Action]s available directly on this object, or | ||
/// this object may represent a hierarchy of actions. | ||
@override | ||
ActionsT? actions; | ||
late ActionsT actions; |
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.
Hmmm thinking it a little more, making actions
required might be a little tricky.
While it'll be present in most cases, there are usages that only wire up a component to redraw on the store, because the actions aren't used. Internally, it looks like ~5% of flux component usages had a store with no actions.
So our options are either:
- Make it optional
- Make it required, and plan on migrating consumers to also set
..actions =
(either to an actions class that will be unused, or to set..actions = null
and potentially update theTActions
generic of the consuming component to bewith FluxUiPropsMixin<MyStore, Null>
)
5% isn't a lot, so I'm leaning toward making it required, but it'll be a little bit of a pain to update those usages.
Thoughts?
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 like making it required.
@@ -68,7 +67,7 @@ class ReduxMultiProviderComponent | |||
get propTypes => { | |||
keyForProp((p) => p.storesByContext): (props, info) { | |||
final storesByContext = props.storesByContext; | |||
if (storesByContext != null && storesByContext.isEmpty) { |
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.
Looks like there's a failing test:
❌ [Chrome, Dart2Js] test/over_react_redux_test.dart: ReduxMultiProvider works as expected when storesByContext is null (failed)
Expected: emits the propType warning some element contains 'RequiredPropError: Prop ReduxMultiProviderProps.storesByContext is required.'
Actual: <Closure: () => TestJacket<Component> from: () => {
let t9;
return jacket$.mount(react.Component, redux_multi_provider.ReduxMultiProvider().call((t9 = dom_components.Dom.div(), (() => {
t9.addTestId("content");
return t9;
})()).call("foo")));
}>
Which: has propType warning with value [
'Warning: Failed prop type: Expected a value of type \'Map<Context<dynamic>, Store<dynamic>>\', but got one of type \'Null\''
]
That test should probably just be removed, since when we add required prop validation it'll fail for that case when invoking the builder.
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.
Removed the test in 136eb83
…-safety_public-util-components # Conflicts: # lib/src/component/resize_sensor.dart # test/over_react_redux/fixtures/connect_flux_counter.dart # test/over_react_redux/fixtures/flux_counter.dart
…-safety_public-util-components
…ty_public-util-components
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.
Changes look good, +10 assuming CI passes