Skip to content

refactor: drive sidebar visibility from :root class - #8775

Closed
polybjorn wants to merge 2 commits into
FreshRSS:edgefrom
polybjorn:refactor/sidebar-state-root-class
Closed

polybjorn wants to merge 2 commits into
FreshRSS:edgefrom
polybjorn:refactor/sidebar-state-root-class

Conversation

@polybjorn

@polybjorn polybjorn commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

The sidebar and its toggle button flash briefly on every page navigation. This PR decides their visibility state in <head>, before the browser paints anything, so there's nothing to flash. Also consolidates the state model onto one CSS class instead of three, removing the bug class that caused #8771. Mirrors the existing :root.darkMode_* convention. Supersedes the gate fix in #8773.

What's wrong today

The flash. The server can't know your per-tab sidebar state, that's in sessionStorage, browser-only. So PHP renders a default, JS corrects it after first paint, and you see the gap, both for the sidebar drawer and for the toggle button's active styling.

State sprawl. Sidebar visibility was tracked across three runtime classes (.aside.is-hidden, .aside.visible, .btn.active) that JS had to keep in sync. #8771 happened because removing one piece broke another that implicitly relied on it.

Approach

Single source of truth: a :root.aside_hidden class on <html>. Present means hidden, absent means visible. CSS reads it for both the sidebar drawer and the toggle button. JS toggles it.

p/scripts/aside_init.js runs synchronously in <head>, before the browser paints <body>. Resolution order:

  1. sessionStorage state from this tab
  2. otherwise hidden in reader view
  3. otherwise hidden at narrow viewport (mobile drawer pattern)
  4. otherwise the user's sidebar_hidden_by_default setting

The narrow-viewport default applies on all views; sessionStorage and user-preference steps are gated to views with the toggle button (normal, reader).

Why a new script file

The init can't live in main.js: that script is defer async, runs after first paint, too late. Loading main.js synchronously would block parsing for ~50KB. Inlining would be smallest but CSP 'self' blocks inline scripts. A small external file (~500 bytes, cacheable) is the cheapest option that satisfies all three.

What changes

  • .aside visibility rules across base-theme + 4 themes (Origine, Swage, Alternative-Dark, Nord) rewritten to scope from :root.aside_hidden / :root:not(.aside_hidden) instead of .aside.is-hidden / .aside.visible. Narrow drawer collapse uses width: 0 to preserve the slide animation.
  • Toggle button active styling is derived from :root:not(.aside_hidden) #nav_menu_toggle_aside .btn in every theme that styles .btn.active (Flat, Origine, Alternative-Dark, Dark, Pafat, Nord). The .classList.toggle('active') JS calls and the PHP-rendered .active class are gone.
  • toggle_aside_click() is a thin wrapper around setAsideHidden(hidden, manual). init_nav_menu() only wires event handlers and a media-query handler now; state restoration is done by the inline init.

Tested

  • Narrow viewport: navigate with sidebar open and closed, both states preserved, no flash
  • Wide viewport: same
  • Reader view: hidden by default, toggleable
  • Resize across the 840px breakpoint
  • Non-toggleable views (Settings, manage-feeds): aside hidden by default in narrow viewport
  • Swage narrow drawer toggles open and closed

@Alkarex Alkarex added this to the 1.30.0 milestone May 3, 2026
@Alkarex Alkarex added the UI 🎨 User Interfaces label May 3, 2026
@polybjorn
polybjorn marked this pull request as ready for review May 3, 2026 13:05
@polybjorn
polybjorn marked this pull request as draft May 3, 2026 23:17
@polybjorn
polybjorn marked this pull request as ready for review May 3, 2026 23:41
Alkarex pushed a commit that referenced this pull request May 4, 2026
Mapco and Ansum apply `transition: all 0.2s ease-in-out` to `.aside`
in their narrow `@media`. When the viewport crosses 840px with the
sidebar open, the resulting `.aside` position change (`static` to
`fixed`) gets animated alongside width, producing a visible artefact
where the X button slides down then scrolls back up before settling.

Limit the transition to the property that should actually animate
(`width`), matching base-theme's existing
`transition: width 200ms linear`.

The artefact only manifests when the drawer stays open across the
840px boundary, which is the behaviour introduced by #8775. On current
edge, `init_nav_menu`'s `media.onchange` toggles the aside off when
crossing the breakpoint, hiding the bug.

Co-authored-by: Bjørn A. Andersen <[email protected]>
polybjorn added 2 commits May 5, 2026 09:08
Sidebar state was tracked across three runtime classes
(`.aside.is-hidden`, `.aside.visible`, and `.btn.active`)
maintained by main.js, plus a viewport-dependent default in CSS.
Keeping these in sync caused #8771: removing one piece of state
broke another that implicitly relied on it. The split also meant
the server couldn't know per-tab state at render time, so every
navigation showed a brief sidebar flash while JS reconciled
after first paint.

Move the source of truth to a single `:root.aside_hidden` class,
mirroring the existing `:root.darkMode_*` convention. Resolution
order:

  1. sessionStorage state if user has toggled in this tab
  2. otherwise hidden in reader view
  3. otherwise hidden at narrow viewport (mobile drawer pattern)
  4. otherwise the user's `sidebar_hidden_by_default` setting

`p/scripts/aside_init.js` runs synchronously in <head> before
<body> paints, so the class is present at first paint and the
sidebar drawer no longer flashes. Loaded as an external file
because CSP `'self'` blocks inline scripts. The narrow-viewport
default applies on all views; the sessionStorage lookup and
user-preference fallback are gated to toggleable views (normal
and reader) where the toggle button exists.

Drop `.is-hidden` and `.visible` from JS and CSS entirely. Themes
that overrode these selectors are rewritten to scope from
`:root.aside_hidden` / `:root:not(.aside_hidden)`. The toggle
button's active state is similarly derived from root state via
`:root:not(.aside_hidden) #nav_menu_toggle_aside .btn` rather
than a runtime `.active` class, eliminating the brief flicker on
the toggle button during page navigation. Touches Flat, Origine,
Alternative-Dark, Dark, Pafat, Nord, and Swage plus their RTL
counterparts. Themes with no `.btn.active` rule (Mapco, Ansum,
Origine-compact, Dark-pink) are unaffected by the toggle change.

Use `display: block` rather than `display: revert` for the
narrow-drawer <nav> rule; semantically identical here but
broader browser support (revert only landed in 2020).

Preserves: per-tab sessionStorage semantics, per-view keying,
narrow/reader defaults, the `sidebar_hidden_by_default` setting.

Supersedes the `init_nav_menu` gate fix in #8773.
The sidebar overlays content at <=840px, so a wide-view "open" choice
must not leak into narrow:

- aside_init.js: narrow and reader force-hide above the stored branch,
  preventing the overlay from flashing on initial paint after a fresh
  page load at narrow with a sticky wide-session "open" state.
- main.js: viewport-crossing handler force-hides on entering narrow
  without persisting, and restores the stored choice on entering wide,
  so the round trip preserves the wide-view preference.
@polybjorn polybjorn closed this May 6, 2026
@Alkarex Alkarex modified the milestones: 1.30.0, 1.29.1 May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

UI 🎨 User Interfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants