RFC: warn when returning different hooks on subsequent renders - #14585
Conversation
like it says. adds a field to Hook to track effect 'type', and compares when cloning subsequently.
|
Maybe we could use react-debug-tools to print a warning that shows the expected the hook structure versus the actual one cc @bvaughn |
|
ReactDOM: size: 0.0%, gzip: 0.0% Details of bundled changes.Comparing: 3fbebb2...3ad6523 react-dom
react-art
react-native-renderer
react-test-renderer
react-reconciler
Generated by 🚫 dangerJS |
|
I’m thinking the message should emphasize the name of the top most hook that doesn’t match. Otherwise it’s not very helpful for custom hooks. |
|
I have an odd bug in my test, where even though I'm matching the warning message exactly, |
- numbered enum for hook types - s/hookType/_debugType - better dce
|
thanks for reviewing my PR on a sunday y'all :) |
|
a couple that are missing
EDIT: done |
need to verify dce still works
|
Looks like there's some overlap here with #14594 for tracking the hook name/type in DEV |
|
@aweary hrmm yeah you're right. I'll refactor. thanks for the catch! |
…#14585) * warn when returning different hooks on next render like it says. adds a field to Hook to track effect 'type', and compares when cloning subsequently. * lint * review changes - numbered enum for hook types - s/hookType/_debugType - better dce * cleaner detection location * redundant comments * different EffectHook / LayoutEffectHook * prettier * top level currentHookType * nulling currentHookType need to verify dce still works * small enhancements * hook order checks for useContext/useImperative * prettier * stray whitespace * move some bits around * better errors * pass tests * lint, flow * show a before - after diff * an error stack in the warning * lose currentHookMatches, fix a test * tidy * clear the mismatch only in dev * pass flow * side by side diff * tweak warning * pass flow * dedupe warnings per fiber, nits * better format * nit * fix bad merge, pass flow * lint * missing hooktype enum * merge currentHookType/currentHookNameInDev, fix nits * lint * final nits
^ like it says. adds a field to
Hookto track hook 'type', and compares when cloning on further renders.started this PR/mvp to discuss how you folks would like this implemented?
I have run the tests (and added one!)