Skip to content

Outline highlights a heading inside a closed <details> at the page bottom #5589

Backlog

Description

@hyunbinseo

Describe the bug

At the bottom of the page, the outline highlights a heading inside a closed <details> block instead of the page's last heading.

When the page bottom is reached, setActiveLink highlights the header with the largest getAbsoluteTop(). In Chrome, a heading inside a closed <details> still has an offsetParent and an offsetTop, so it isn't filtered out as NaN. Its position can even be past the end of the page, so it sorts last.

Measured on https://viteplus.dev/guide/global-cli:

Heading Top Visible
Precedence (inside a closed <details>) 12260 no
Next Steps (last heading) 3546 yes
Page height 4202 n/a

Reproduction

Open https://viteplus.dev/guide/global-cli#use-both-clis-together and scroll to the bottom. The outline jumps to "Precedence".

vitepress-outline-details.mp4

Expected behavior

The outline highlights "Next Steps", the last visible heading. Headings that aren't rendered (!element.checkVisibility()) are skipped.

System Info

  • VitePress: 2.0.0-alpha.20. Not tested on the latest (2.0.0-alpha.21), but the outline code is unchanged on main.
  • Browser: Chrome 157, Linux

Additional context

Related: #5473. Its open PRs (#5474, #5539) remove the forced last-item selection, which hides this symptom on the page above. Hidden headings are still counted, so one whose position lands above the active line would still be highlighted.

Validations

Activity

  1. moonlorddev commented on Nov 24, 2026

    @moonlorddev

    I'd like to take this one. I checked the page from the issue in Chrome 156: all 7 headings inside the closed <details> blocks return checkVisibility() === false but still have offsets, several of them past the page height (Precedence at 12766 on a 6616px page), while Next Steps is visible.

    The fix I have makes getAbsoluteTop() return NaN when element.checkVisibility?.() is false, so those headings go through the existing NaN filter in setActiveLink. Browsers without checkVisibility keep the current behavior. It also stops a heading inside a closed <details> from being picked as active mid-page, not just at the bottom. Unit tests are in outline.test.ts.

    It's independent of #5474 / #5539 for #5473 (those change the bottom-of-page logic, this only changes which headings are considered), so it should apply on top of either. Does that sound OK? Happy to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions