Skip to content

[v6] Breaking Change: Full ConcurrentMode Support & Unified Event Handler Code #121

@childrentime

Description

@childrentime
  1. Ensure that each custom hook is concurrent-mode safe. This requires following certain principles, such as:
    • avoiding reading or writing refs during the render process.
  2. When using external state management libraries, useSyncExternalStore must be used. However, this usually doesn't concern us as we generally don't store setState.
  3. Given that stable event handler hooks would only have incorrect values when read within a child component's useLayoutEffect, I believe we can temporarily ignore this scenario and uniformly wrap translated event handlers with useEvent.
function Example(props) {
  const callback = useDynamicCallback(props.callback);
  return <Child callback={callback} />;
}

function Child({ callback }) {
  useLayoutEffect(() => {
    // Child effects are run before parent effects!
    // This means the callback ref has not yet been updated-
    // which means that it still points to the previous version,
    // with stale values and potentially different behavior.
    // This function call will probably cause problems!
    callback();
  }, []);
}

references:
facebook/react#16956 (comment)
facebook/react#18003 (comment)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions