Hi,
I’ve been thinking for quite some time about how to implement a page with a sidebar. This type of layout is very common in documentation pages.
For example:
- Configuration | Docusaurus
- Getting Started | VuePress
- Create deploys | Netlify Docs
- Search & Quick find | GitBook Documentation
The main requirement is that when a user clicks inside the sidebar, two things should happen:
- The main content area loads the new page.
- The sidebar gets updated — the selected page should be highlighted, or something even more dynamic could happen. Ideally, this should be done without relying on JavaScript. In other words, the sidebar’s current state should be rendered by the server. At the same time, the scroll position in the sidebar should not jump — it should stay exactly where it was at the moment of the click.
I’ve been thinking about possible ways to achieve this. Initially, I considered using a turbo frame.
I could easily set the data-turbo-frame="main"
attribute on the sidebar links, and then the main
frame (containing the main content) would reload on click. However, it’s not clear how to update the sidebar’s state in this case.
In the end, I came to the conclusion that the only feasible solution is to use turbo streams.
What do you think? Are there any other options to solve this?