Fix My Jetpack route crash in Chrome (And Protect)#50465
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Protect plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
|
anomiex
left a comment
There was a problem hiding this comment.
Looks reasonable. Fixes the issue on the JN site I was using for reproduction.
146166f to
65c9b8d
Compare
Fixes: p1783960683602709-slack-C0299DMPG
Summary
ScrollToTopeffect from returning the result ofwindow.scrollTo().Causes a blank page.
Why this happens in Chrome
ScrollToTopused a concise arrow effect:useEffect( () => window.scrollTo( 0, 0 ), [ location ] ). React treats any value returned from an effect callback as that effect cleanup. In Firefox,window.scrollTo( 0, 0 )returnsundefined, so there is no cleanup. In Chrome/Chromium, the same call can return aPromise; React stores that promise as the cleanup value and then tries to call it during the next route change/unmount. Because the promise is not a function, React throws from its effect cleanup path, which leaves the My Jetpack admin page blank.The fix keeps the scroll behavior but uses a block body so the effect callback returns
undefinedconsistently across browsers.Testing instructions:
Does this pull request change what data or activity we track or use?
No