GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Double Invoke Effects in __DEV__ by lunaruan · Pull Request #19523 · react/react Conversation
|
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b9b5750:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Details of bundled changes.Comparing: a99bf5c...b9b5750 react-dom
Size changes (stable) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Details of bundled changes.Comparing: a99bf5c...b9b5750 react-dom
Size changes (experimental) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
It can cause some issues. For example, in where I work we have a component that have this kind of effect: React.useEffect(() => { navigator.clipboard.readText().then(/* …And content to state variable */); }, []); Also some components that sends analytics / fetch some data, which will probably break many tests. EDIT: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'm not sure if this is what you're saying, but you probably shouldn't be sending analytics in DEV mode (or you should be sending them somewhere different than production analytics). As for your concern about testing, that's something I haven't thought much about. I can see where this might cause hassle. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@bvaughn Well, the analytics is not about sending them. We have a logger of analytics (to browsers devtools console), so while developing we can make sure they logged in correct scenarios. If sometimes it called twice and sometimes once, we can't predict if analytics correct. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This looks like it might brake a lot of code. This changes implies that effects can only be used when they have very specific semantics: they should either be idempotent or reversible. Also it makes it a requirement to implement a cleanup even if it is never supposed to run. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The change is fully behind a flag and does not affect any of the code on npm. Indeed, it is likely to break some code, so we want to try it at FB to see how large the impact is. We appreciate your concern but researching this more is the whole point of this PR. Hope this makes sense. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I'll add though that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
fe64e03 to
e51e75b
Compare
|
Ready for review! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
e51e75b to
8cee981
Compare
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
8cee981 to
b4f716a
Compare
|
Updated the PR based on everyone's comments! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| let fiber = firstChild; | ||
| while (fiber !== null) { | ||
| if (fiber.child !== null) { | ||
| // Should we add a separate subtree tag for this? |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What's this comment for? I'm not sure I understand it.
Is this pointing out the fact that we're going to end up traversing all of the subtree paths that have layout effects even if they're all updates and none of them are mounts? So we could add a DEV-only tag e.g. MountLayoutSubtreeTag or something.
Maybe we could add some additional clarification to the wording here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't sure how OK it was to add a subtree tag vs. just traversing extra in DEV since it takes extra bytes to add an extra subtreetag, and I know at least with effectTag, we don't seem to want to add too many. If it's in DEV though it makes sense that it's OK. Thanks for clarifying!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| case ForwardRef: | ||
| case SimpleMemoComponent: | ||
| case Block: { | ||
| invokeGuardedCallback( |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Technically, after https://github.com/facebook/react/pull/19605/files this will be unnecessary since commitHookEffectListUnmount should be safe now.
It's an awkward inconsistency since the equivalent mount isn't safe. I don't know what the answer is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'll leave it as is for now for consistency and maybe do a separate PR to make everything more consistent (Will creating a safelyCallCreate function cause perf issues)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This PR double invokes effects in __DEV__ mode. We are thinking about unmounting layout and/or passive effects for a hidden tree. To understand potential issues with this, we want to double invoke effects. This PR changes the behavior in DEV when an effect runs from create() to create() -> destroy() -> create(). The effect cleanup function will still be called before the effect runs in both dev and prod. (Note: This change is purely for research for now as it is likely to break real code.) **Note: The change is fully behind a flag and does not affect any of the code on npm.**
We originally added a new DEV behavior of double-invoking effects during mount to our new reconciler fork in PRs react#19523 and react#19935 and later refined it to only affect modern roots in PR react#20028. This PR adds that behavior to the old reconciler fork with a small twist– the behavior applies to StrictMode subtrees, regardless of the root type. This commit also adds a few additional tests that weren't in the original commits.
This combines changes originally made in react#19523, react#20028, and react#20415 but with slightly different semantics: "strict effects" mode is enabled only for the experimental root APIs (never for legacy render, regardless of <StrictMode> usage). These semantics may change slightly in the future.
This PR double invokes effects in __DEV__ mode. We are thinking about unmounting layout and/or passive effects for a hidden tree. To understand potential issues with this, we want to double invoke effects. This PR changes the behavior in DEV when an effect runs from create() to create() -> destroy() -> create(). The effect cleanup function will still be called before the effect runs in both dev and prod. (Note: This change is purely for research for now as it is likely to break real code.) **Note: The change is fully behind a flag and does not affect any of the code on npm.**
We originally added a new DEV behavior of double-invoking effects during mount to our new reconciler fork in PRs react#19523 and react#19935 and later refined it to only affect modern roots in PR react#20028. This PR adds that behavior to the old reconciler fork with a small twist– the behavior applies to StrictMode subtrees, regardless of the root type. This commit also adds a few additional tests that weren't in the original commits.
This combines changes originally made in react#19523, react#20028, and react#20415 but with slightly different semantics: "strict effects" mode is enabled only for the experimental root APIs (never for legacy render, regardless of <StrictMode> usage). These semantics may change slightly in the future.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.