Skip to content

fix(sidebar): set the icon indent in markup, not with :has() - #2105

Merged
markdumay merged 2 commits into
mainfrom
fix/sidebar-icon-indent-static
Aug 1, 2026
Merged

fix(sidebar): set the icon indent in markup, not with :has()#2105
markdumay merged 2 commits into
mainfrom
fix/sidebar-icon-indent-static

Conversation

@markdumay

Copy link
Copy Markdown
Collaborator

Fixes a layout shift introduced by #2103: the child items visibly move on load.

Cause

The sidebar HTML is cached per section, and critical/sidebar-active.js expands the collapse trail client side — the served markup ships <div class="collapse"> with no show. So the nested list goes from display:none to visible after first paint.

#2103 derived the indent with :has(). That selector has to be re-resolved when the subtree becomes visible, and a browser is free to paint the old ps-3 first and correct it a frame later. That is what the shift is.

I could not reproduce it in Chromium — layout-shift entries came back empty, CLS 0.00000 — so this fixes the mechanism rather than a symptom I observed. The reasoning stands on its own: a value that must be recomputed as a subtree is revealed is inherently a worse choice here than one that is already in the markup.

The fix

The template already knows whether the group has an icon ($pre), so it emits the class instead of CSS deriving it:

{{ if $pre }}sidebar-nav-icon-indent{{ else }}ps-3{{ end }}
.sidebar-nav-icon-indent {
    padding-left: calc(1.25rem + 0.25rem);   // fa-fw width + me-1
}

The class is in the cached HTML, so it is correct at first paint with no re-resolution, no dependence on when the collapse opens, and no !important needed. Groups without an icon keep ps-3 exactly as before — now by being emitted a different class rather than by failing to match a selector.

Evidence

Verified the class is present in the served markup, before any JS:

ul -> btn-toggle-nav list-unstyled pb-1
ul -> btn-toggle-nav list-unstyled fw-normal sidebar-nav-icon-indent
ul -> btn-toggle-nav list-unstyled fw-normal ps-3

Geometry is unchanged from #2103:

Row #2103 This PR
Guides (has icon) 104 104
Organization 104 104
Invite a Member 120 120

Icon-bearing lists compute 24px, the rest 16px, and no :has() rule targeting btn-toggle-nav remains in the stylesheet.

pnpm test passes.

Reported after #2103 shipped: the child items visibly shift on load.

The sidebar HTML is cached per section and the collapse trail is
expanded client side, so the nested list goes from display:none to
visible after first paint. A `:has()` selector has to be re-resolved at
that point, and a browser is free to paint the old `ps-3` first and
correct it a frame later - which is exactly what the shift looks like.

The template already knows whether the group has an icon, so it now
emits `sidebar-nav-icon-indent` in place of `ps-3` and the rule is a
plain class selector. The value is in the cached markup, so it is right
from the first paint with no re-resolution and no dependence on when
the collapse opens.

Geometry is unchanged from #2103 - Guides 104, Organization 104, Invite
a Member 120, with the icon-bearing lists at 24px and the rest at 16px.
Groups without an icon keep `ps-3` exactly as before, now by emitting a
different class rather than by failing to match a selector.
@netlify

netlify Bot commented Aug 1, 2026

Copy link
Copy Markdown

Deploy Preview for gethinode-demo ready!

Name Link
🔨 Latest commit e4d7efa
🔍 Latest deploy log https://app.netlify.com/projects/gethinode-demo/deploys/6a6e16fde04f2d00081a04b5
😎 Deploy Preview https://deploy-preview-2105--gethinode-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@markdumay
markdumay enabled auto-merge August 1, 2026 15:55
@markdumay
markdumay merged commit 141b5d9 into main Aug 1, 2026
17 checks passed
@markdumay

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 3.14.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@markdumay
markdumay deleted the fix/sidebar-icon-indent-static branch August 1, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant