-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigation issue with Astro <ClientRouter> and Lenis smooth scroll #12725
Comments
I believe the issue stems from the Here's the fix: <script is:inline>
delete window.onscrollend;
</script> Please note, this is a bit of a hacky solution, but it might help in this case. For reference, here’s the relevant section of Astro’s router code: router.ts. Hope this helps! |
Hi @titouan-pellerin 👋🏼 Thank you so much for opening this issue! If available, scrollend is preferred over scroll events in Astro for performance reasons and smoother animation. Its a bit ironic that falling back to scroll events is the solution here, and it might not be the right choice for every case. But I'm happy about a solution that is better than "all or nothing". I have to admit that I still do not understand how Lenis can trigger too many scrollend events. |
Hi @martrapp, glad to help! Honestly, I’m not entirely sure how Lenis works internally. However, I’ve noticed that the browser detects a |
You don’t always have to understand everything. In any case, thanks again. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
Firefox (Chrome also triggers a warning about navigation throttle)
Describe the Bug
When using Astro’s
<ClientRouter>
component in combination with the Lenis smooth scroll library, errors occur (primarily in Firefox) that disrupt client-side navigation. This seems to stem from Lenis overriding the native scroll behavior and manually updating the window.scroll values, which Astro’s router listens to for scroll restoration.The problem arises because Lenis triggers frequent updates via requestAnimationFrame, causing Astro to save the scroll position in history excessively.
Observed Errors
Console errors in Firefox :
Warning in Chrome :
Steps to Reproduce
Integrate the component in an Astro project.
Add Lenis for smooth scrolling.
Attempt client-side navigation while observing console outputs.
Additional Notes
This seems to be related to the interaction between Lenis’ frequent requestAnimationFrame updates and Astro’s scroll restoration mechanism.
Potential workarounds or guidance for compatibility adjustments would be appreciated.
What's the expected result?
Client navigation should work seamlessly, and the integration of Lenis should not interfere with Astro's scroll restoration or produce errors in the console.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-bsnbbzh2?file=src%2Flayouts%2FLayout.astro
The text was updated successfully, but these errors were encountered: