-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix double render on selector change #825
Fix double render on selector change #825
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drarmstr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for continuing to improve this optimization!
Could you generate a unit test that helps confirm the situation where this change eliminates an extra render? You can see an example for such test with "Updating with same value doesn't rerender"
test in https://github.com/facebookexperimental/Recoil/blob/master/src/recoil_values/__tests__/Recoil_atom-test.js
Note that I updated the unit tests from importing #820 so compensate for that fix in removing the extra render when the GK is set which you should hopefully see when that merges.
@salvoravida - #820 has now been merged. Notice in the update that it was tweaked to be behind the GK feature flag check and the unit tests were updated. We'll see if that causes any issues with nightly testing.. But, from those examples hopefully you can see how the unit testing works. Could you update this PR with an example test to help clarify the situations it affects and catch potential regressions? |
@salvoravida has updated the pull request. You must reimport the pull request before landing. |
@salvoravida has updated the pull request. You must reimport the pull request before landing. |
Hi @drarmstr, i have just rebased the pr on last master commit, moreover i added the test for this case. |
@salvoravida - Ah, yes, excellent! Thank you for the test! I'll try to review this next week then. With #952 landing now we can start to open up this optimization for our internal testing again. |
@drarmstr has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@salvoravida - I had a chance to go over the test and it looks good. However, I'm still not clear on what change the fix is supposed to do. It looks like the test works both with and without the code changes in |
Hi @drarmstr (as first comment) Issue CodeSandbox: Fixed CodeSandbox: about tests: With this pr(my mod on Recoil_Hooks) Without: ● Components unsubscribe from atoms when rendered without using them [recoil_suppress_rerender_in_callback]
● Components re-render only one time if selectorFamily changed [recoil_suppress_rerender_in_callback]
Are you sure you have tested the OSS version? may have some problems with flags? |
Let me give it another run through with the legacy vs concurrent mode enabled, maybe that was the issue.
On Apr 26, 2021, at 00:55, Salvatore Ravidà ***@***.***> wrote:
@salvoravida<https://github.com/salvoravida> - I had a chance to go over the test and it looks good. However, I'm still not clear on what change the fix is supposed to do. It looks like the test works both with and without the code changes in Recoil_Hooks.js.
Hi @drarmstr<https://github.com/drarmstr> (as first comment)
This pr just set the current value before store subscribe/resubscribe
This prevent double rendering when using selectorFamily in child nodes, controlled by parent props.
Issue CodeSandbox:
codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk
Fixed CodeSandbox:
codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8
about tests:
With this pr(my mod on Recoil_Hooks)
Test Suites: 34 passed, 34 total
Tests: 2 skipped, 811 passed, 813 total
Without:
Test Suites: 1 failed, 33 passed, 34 total
Tests: 2 failed, 2 skipped, 809 passed, 813 total
● Components unsubscribe from atoms when rendered without using them [recoil_suppress_rerender_in_callback]
expect(jest.fn()).toHaveBeenCalledTimes(expected)
Expected number of calls: 3
Received number of calls: 4
825 | act(() => toggleSwitch());
826 | expect(container.textContent).toEqual('0');
827 | expect(Component).toHaveBeenCalledTimes(baseCalls + 3);
● Components re-render only one time if selectorFamily changed [recoil_suppress_rerender_in_callback]
expect(jest.fn()).toHaveBeenCalledTimes(expected)
Expected number of calls: 2
Received number of calls: 3
1758 |
1759 | expect(container.textContent).toEqual('1');
1760 | expect(Component).toHaveBeenCalledTimes(baseCalls + 2);
Are you sure you have tested the OSS version? may have some problems with flags?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#825 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABDVJ2BBEDL5FOSKGJQZ3JLTKUL6ZANCNFSM4V4XFL4Q>.
|
@drarmstr note that Suspence pr is not merged on my branch. |
Hi @drarmstr i tested this PR over the Suspense one. it seems the suspense one has the same effect on the test. it allows one render less on legacy mode, and component unsubscribe. |
Ah, good; glad the additional Suspense fix explains the discrepancy. Ok, I'll test again with that test as soon as I have a chance. Thanks! |
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental#825 Reviewed By: bezi Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: 0c741fc5cda1a8cadfd01660242acc5e51f1d6e1
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental#825 Reviewed By: bezi Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: b317c6095df400546f3623c8f97530875f667648
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental#825 Reviewed By: bezi Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: c6d38d603dded9f4fc61d657d7444f2d3edc751f
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental#825 Reviewed By: bezi Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: 07b1dc3a9eb970693fe46673781f2df150f6ef25
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental#825 Reviewed By: bezi Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: 92d4e52514259059ac862fef26ca8ea09c3f50c7
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental#825 Reviewed By: bezi Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: 0eac0fb24292ae4d07090c661933e8b27c499819
Finally got around to validating and landing this optimization while working on the latest rendering modes. Thanks again @salvoravida. |
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental/Recoil#825 Reviewed By: habond Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: 8fa0491bb6bffb48287a71a619d502f62ce321cb
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental/Recoil#825 Reviewed By: habond Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: 8fa0491bb6bffb48287a71a619d502f62ce321cb
Summary: This pr just set the current value before store subscribe/resubscribe This prevent double rendering when using selectorFamily in child nodes, controlled by parent props. Issue CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk Fixed CodeSandbox: https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8 Pull Request resolved: facebookexperimental/Recoil#825 Reviewed By: habond Differential Revision: D25873280 Pulled By: drarmstr fbshipit-source-id: 8fa0491bb6bffb48287a71a619d502f62ce321cb
This pr just set the current value before store subscribe/resubscribe
This prevent double rendering when using selectorFamily in child nodes, controlled by parent props.
Issue CodeSandbox:
https://codesandbox.io/s/recoil-legacy-selector-change-double-render-issue-fhbxk
Fixed CodeSandbox:
https://codesandbox.io/s/recoil-legacy-selector-change-double-render-fixed-feub8