useLayoutEffect isn't needed here
https://linear.app/comm/issue/ENG-986/regression-uselayouteffect-warning-in-keyserver-console
Differential D3678
[web] [fix] [ENG-986] replace useLayoutEffect with useEffect • benschac on Apr 8 2022, 12:26 PM. Authored by Tags None Referenced Files
Details useLayoutEffect isn't needed here https://linear.app/comm/issue/ENG-986/regression-uselayouteffect-warning-in-keyserver-console open and close the menu button in header
Diff Detail
Event TimelineComment Actions You might want this. The comment seems to indicate that useLayoutEffect is necessary in the browser. I don't have full context though Comment Actions I disagree with the summary:
@benschac for what reasons was such a conclusion made? The useLayoutEffect hook was introduced here by purpose, which is shortly described in a comment above the code (half of which you deleted in the diff, making the comment no sense). This change in my opinion breaks well working solution and introduces bad experience for users. I think the solution in the link provided by @ashoat may solve the issue with the warning in console without breaking the experience, but it should be well tested before introducing the change. Comment Actions I talked offline with @benschac about this, and shared some feedback about submitting diffs like this. If you're making a substantial change to something like this, you should either (1) make sure you have the full context on the decision, or (2) reframe your diff as a proposal, avoid confident assertions like "useLayoutEffect isn't needed here", and provide much more context in the diff description for what you're solving and why you think this is the right decision. That said, the other side of this is that @benschac and I don't fully understand why useLayoutEffect is necessary here. I appreciate @def-au1t's explanation above, but unfortunately after reading it I am still pretty confused. We discussed this briefly in the weekly sync, and I came up with three things I think @def-au1t can do to make the explanation more clear:
Comment Actions I'm going to! Same here, I'm still trying to understand @def-au1t's comment above. A gif/screenshot would be helpful. Going to give it another read momentarily then abandon this diff. Comment Actions Also appologies @def-au1t -- I should have asked and framed a question rather than made an assertion, additionally should have left more of a description in this diff. Comment Actions The issue I had using useEffect is presented on video below: However, it seems to me, that the issue is no longer valid. I wasn't aware, that this behavior was accidentally removed in the last major iteration of D3377 diff introducing the menu: https://phabricator.ashoat.com/D3377?vs=10741&id=10819 Finally, as a part of this diff, we moved calling renderMenu from useCallback to useEffect, what result is that both of them are executed from useEffects. If React executes both useEffects containing these function calls in the same render - what I suppose happens, updatePosition should no longer be called after renderMenu, and its position should be initially correct. I did some tests to confirm, if using useEffect is safe now, and I didn't notice any issues anymore.
|