Fix sidebar scroll restoration issue#2569
Conversation
|
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
delucis
left a comment
There was a problem hiding this comment.
Took a quick look at the preview and certainly seems to be working as expected. Don’t love that this forces moving more stuff out of the <SidebarPersister> component. Maybe there’s another way to break it up 🤔 I think currently the reason to keep <SidebarPersister> in <Sidebar> is to receive and hash the sidebar as mutated by any sidebar overrides. Maybe after #2390 that wouldn’t be so important.
|
Yeah, not super happy about it either, even more it breaks Prettier now in #2390 would definitely help, altho, I'll have to find and check some previous discussions, I wonder if also one point to keep it there was also the possibility to bypass it by not rendering the default component maybe? 🤔 |
Yeah, that’s also true. Moving things to |
|
More than 1 year later, I'm still not happy with this change, and considering it's only an issue in Astro Docs from what we know, I'd like to explore other options rather than seeing this merged. Closing this PR for now. |

Description
This PR fixes a sidebar restoration issue in projects that uses a
<Sidebar>component override which adds content after the default sidebar, e.g. like the sponsors in the Astro Docs.Repro:
The sidebar scroll position is not properly restored as it should be. The restoration happens after the default sidebar content is rendered but before the entire override content is rendered. Any extra content added after the default sidebar content is not taken into account when restoring the scroll position.
This PR is a draft testing the easiest fix by just moving the restoration script after the
<Sidebar>component. The goal is to see if this is a viable solution and if it doesn't break anything else.The preview in this PR includes a reproduction of the issue so that we can easily test the fix.
Remaining tasks
Sidebaroverride indocs/astro.config.mjsdocs/src/components/Sidebar.astrofilepackages/starlight/components/SidebarPersister.astro