-
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
over_react analyzer not reporting at compile time required props that are missing, and at runtime, reporting error on required props that are specified #942
Comments
While I'm at it, there's another strange (and more serious) bug, where I am being told I missed a required prop even though I did specify it: Although I am providing a non-null
I added a statement react_dom.render(
over_react_components.ErrorBoundary()(
(ReduxProvider()..store = app.store)(
ConnectedDesignFooter()(), // this is the line corresponding to (design.dart:897:36)
),
),
this.footer_element,
); I can fix that error by declaring that I haven't migrated very many of my react components to null safety yet, but the difference between this and the others I have migrated is that this is a connected component, whereas the others were rendered by a parent react component. Are connected components treated differently? It's as though OverReact is trying to render the component once before actually calling the |
For anyone stumbling on this issue looking for the I guessed that putting this in my
would cause OverReact to warn about required props that were not given when creating a component, but so far I haven't seen that error show up even when I try to trigger it. |
I figured out a workaround for this error. For a connected component (unlike in non-null-safe-mode, i.e., if you don't have UiFactory<DesignLoadingDialogProps> ConnectedLoadingDialog = connect<AppState, DesignLoadingDialogProps>(
mapStateToProps: (state) =>
DesignLoadingDialog()..show = state.ui_state.show_load_dialog;
)(DesignLoadingDialog); and when you hook up the React tree to the DOM: render_loading_dialog() {
react_dom.render(
over_react_components.ErrorBoundary()(
(ReduxProvider()..store = app.store)(
(ConnectedLoadingDialog()..show = state.ui_state.show_load_dialog)(),
),
),
this.dialog_loading_container,
);
} This seems redundant. I am writing some code to help avoid repeating the same code over and over for each connected component (most of mine have many more props than one, so I don't want to have so much duplicated code). But I assume this is not the intended usage; if anyone from the team can point me to a better way to handle this in null-safe code, I'd appreciate it. |
Hey @dave-doty! The over_react analyzer plugin should be warning about required props, under the code If you're seeing that not working, you could try the following steps to debug it (first, though, see my notes below about fully-invoked usages and connect). Click to expand debugging steps
However, it currently only warns about component usages that have been fully invoked to create // Should warn about missing required props
(DesignFooter()
// ..mouseover_datas = state.ui_state.mouseover_datas
)()
// Will not warn about missing required props
(DesignFooter()
// ..mouseover_datas = state.ui_state.mouseover_datas
) Generally, it's because there are cases where you might want to construct a map that contains a "partial" set of props, and we found a lot of existing code using that pattern that would be broken if we linted for those cases. We could potentially add a special-case to lint for the return value of That leads us into the runtime error you're hitting, and having to set the required prop both in The returned connected component uses the same props implementation as the underlying component, so it still validates at runtime that all required props are set, since at that point in time We'll have to think a little more on what the best way to deal with that case is, but in the meantime, two potential solutions come to mind:
|
Regarding the original issue that analyzer was not reporting when I failed to specify a required prop, I now see that it does correctly report this. I suspect the issue was that I was migrating the components one-by-one to null safety, and perhaps there was some issue where if one of the parent or child components was still not null-safe (i.e., had the But if there is something to my guess, you might consider adding that to the migration guide, that the warnings only appear if all components involved lack the line |
Would you mind fleshing out the hook examples a bit more? For instance there's this at the page you linked: import 'package:over_react/over_react_redux.dart';
import 'package:over_react/react_dom.dart' as react_dom;
main() {
react_dom.render(
(ReduxProvider()..store = yourReduxStoreInstance)(
// Function components that use the hooks in this section go here.
),
querySelector('#id_of_mount_node'));
} but I don't know what to replace Is there a complete, self-contained example somewhere for how to use functional components with Redux? Thanks so much. |
Ah, sorry about that; I wonder if it was caused by this bug #948, fixed in over_react 5.3.2? We had only discovered that after I responded to this thread, and I hadn't thought about how it might impact this.
A little further in on that section, the useSelector and useDispatch sections show more complete examples of those function components. We also have an example here (not-ideally, hidden in the web directory): https://github.com/Workiva/over_react/blob/master/web/over_react_redux/examples/simple/components/counter.dart#L21-L37 |
I got the analyzer plugin set up, and it is indeed showing some warnings in WebStorm, so it's running:
However, the main bug I had with pre-null-safe overreact was forgetting to include a required prop and having it default to
null
. I had really hoped to be warned about this (in fact it seems like the severity should default to error), but in the following code, I have commented out the line// ..mouseover_datas = state.ui_state.mouseover_datas
to see if the analyzer plugin will warn me that the required propmouseover_datas
is not being specified, but that does not show up:I did try restarting the analyzer server by clicking the red curved arrows in the upper left, but still nothing about this error.
Is there something I need to configure in the overreact analyzer to ask it to warn me about missing required props?
I noticed that this page mentions some customization:
"To configure the plugin, add a over_react key to analysis_options.yaml:"
But I can't find any documentation of what all the options are for the analyzer, and what "
over_react_missing_required_prop
" would actually be.The text was updated successfully, but these errors were encountered: