forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use double render to detect render phase mutation
PR facebook#20665 added a mechanism to detect when a useMutableSource source is mutated during the render phase. It relies on the fact that we double render components during development in Strict Mode. If the version in the double render doesn't match the first, that indicates there must have been a mutation during render. However, I realized during review that is true of all errors that occur during the double render. A pure component will never throw during the double render, because if it were pure, it would have also thrown during the first render... in which case it wouldn't have double rendered! So instead of tracking and comparing the source's version, we can instead check if we're inside a double render when the error is thrown. We probably shouldn't be throwing during the double render at all, since we know it won't happen in production. (It's still a tearing bug, but that doesn't mean the component will actually throw.) I considered suppressing the error entirely, but that requires a larger conversation about how to handle errors that we know are only possible in development. I think we should probably be suppressing *all* errors (with a warning) that occur during a double render.
- Loading branch information
Showing
4 changed files
with
83 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters