You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
<ScrollRestoration /> does not restore the scroll positions before DOM paint #2601
I identified that the issue occurs because the onResolved event is triggered after the <HomeTab /> component has mounted. Since the <ScrollRestoration /> component performs scroll restoration when the onResolved event is emitted, it consistently restores the cached scroll position after <HomeTab /> becomes visible to the user.
I resolved this issue using a workaround. Here’s how I addressed it:
Removes the isTransitioning check in isAnyPending in Transitioner.tsx
With the above change, the onResolved event will be emitted before the useLayoutEffect in <Page /> component. And the flash is gone
I understand that the above workaround is not a real solution to this issue. As isTransitioning is obviously useful, removing it might cause some serious bugs in the other places. Hope we can find a real solution to this problem.
I propose a solution which is to make the router emit a new event called onBeforePageMount.
The onBeforePageMount is designed to trigger actions that should occur just before a new page component mounts. This event allows developers to perform pre-render operations, such as scroll restoration, ensuring that these actions complete before the page content becomes visible to the user.
Activity
xiaohai-huang commentedon Oct 23, 2024
I identified that the issue occurs because the
onResolvedevent is triggered after the<HomeTab />component has mounted. Since the<ScrollRestoration />component performs scroll restoration when theonResolvedevent is emitted, it consistently restores the cached scroll position after<HomeTab />becomes visible to the user.I resolved this issue using a workaround. Here’s how I addressed it:
isTransitioningcheck inisAnyPendingin Transitioner.tsxWith the above change, the
onResolvedevent will be emitted before theuseLayoutEffectin<Page />component. And the flash is gonexiaohai-huang commentedon Oct 23, 2024
I understand that the above workaround is not a real solution to this issue. As
isTransitioningis obviously useful, removing it might cause some serious bugs in the other places. Hope we can find a real solution to this problem.xiaohai-huang commentedon Oct 26, 2024
I propose a solution which is to make the router emit a new event called
onBeforePageMount.The
onBeforePageMountis designed to trigger actions that should occur just before a new page component mounts. This event allows developers to perform pre-render operations, such as scroll restoration, ensuring that these actions complete before the page content becomes visible to the user.