[Fast Refresh] Don’t Scan the Tree #21139
Labels
Component: Fast Refresh
Difficulty: challenging
React Core Team
Opened by a member of the React Core Team
Resolution: Backlog
We had a conversation with @sebmarkbage about #20417. He had a different implementation idea that should resolve such issues. I probably won't do this now but I want to write it down for future reference.
Currently, after we gather a list of types that need to be updated in the tree, we scan the tree and tag Fibers to be updated. This happens here. But like #20417 shows, this doesn't work if the type is not in the tree. E.g. if the function we changed is only being called directly, and its "type" is not the actual wrapper that exists in the tree.
An alternative implementation could instead inject a special Hook call into each registered component. For example by generating a wrapper. That Hook would return the latest actual implementation, and schedule updates on itself when it changes. Which means there would be no need to scan the tree at all. Instead, each component would register itself for updates. For false positives outside of React rendering, the Hook would just be callthrough so it wouldn't break anything.
This seems like a pretty significant change to the implementation so I'm probably not going to work on this now. Maybe we could consider it next time we need to change the implementation details. Or maybe somebody sufficiently motivated wants to hack on this. I can provide some code pointers but it’s not a beginner-friendly issue.
The text was updated successfully, but these errors were encountered: