Skip to content
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

Update ReactDebugHooks to handle composite hooks #18130

Merged

Commits on Feb 25, 2020

  1. Update ReactDebugHooks to handle composite hooks

    The useState hook has always composed the useReducer hook. 1:1 composition like this is fine.
    
    But some more recent hooks (e.g. useTransition, useDeferredValue) compose multiple hooks internally. This breaks react-debug-tools because it causes off-by-N errors when the debug tools re-renders the function.
    
    For example, if a component were to use the useTransition and useMemo hooks, the normal hooks dispatcher would create a list of first state, then callback, then memo hooks, but the debug tools package would expect a list of transition then memo. This can break user code and cause runtime errors in both the react-debug-tools package and in product code.
    
    This PR fixes the currently broken hooks by updating debug tools to be aware of the composite hooks (how many times it should call nextHook essentially) and adds tests to make sure they don't get out of sync again. We'll need to add similar tests for future composite hooks (like useMutableSource facebook#18000).
    Brian Vaughn committed Feb 25, 2020
    Configuration menu
    Copy the full SHA
    76ba30b View commit details
    Browse the repository at this point in the history