Which project does this relate to?#
Router
Describe the bug#
It shows the top of the page then restore the scroll positions. This causes flickering.
Your Example Website or App#
https://stackblitz.com/edit/tanstack-router-k6ncqr?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue#
- At the
/ route (Home tab), scroll to the bottom of the home tab.
- Click the About tab.
- Click the Home tab.
- I can see the red background of the Home tab title appear and then suddenly disappeared.
Expected behavior#
No red background flickering
Screenshots or Videos#
https://github.com/user-attachments/assets/22f05924-bb58-4894-9938-5a7903b51db4
Platform#
- OS: WInd
- Browser: Edge
- Version: 130.0.2849.46
Additional context#
No response
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 gone