Skip to content

Conversation

@ettfemnio
Copy link
Contributor

The modern template currently uses innerText to get the text from h2 and h3 tags for the "In This Article" section of the affix. However, this can cause links with empty text content to be generated for headers which are not visible at the moment the navigation is generated, such as those in a <details> element. Using textContent instead will still properly retrieve the text from these headers.

I've created a repository containing a small example where the use of innerText causes a problem. The example uses a custom template alongside the custom containers and attributes Markdig extensions to render each version in a changelog inside a <details> element, expanding only the first of them by default. When the navigation is generated, anchor elements are created for the headers inside the collapsed sections, but they do not appear because they do not have any text content.

The modern template currently uses `innerText` to get the text from h2
and h3 tags for the "In This Article" section of the affix. However,
this can cause links with empty text content to be generated for headers
which are not visible at the moment the navigation is generated, such as
those in a `<details>` element. Using `textContent` instead will still
properly retrieve the text from these headers.
@yufeih yufeih requested a review from Copilot September 2, 2025 02:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue where navigation links in the "In This Article" section appear empty for headers that are not visible when the navigation is generated (e.g., headers inside collapsed <details> elements). The fix changes from using innerText to textContent to properly extract text from all headers regardless of their visibility state.

  • Replace innerText with textContent for extracting header text in navigation generation
  • Ensure navigation links display properly for headers in collapsed sections

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@yufeih yufeih enabled auto-merge (squash) September 2, 2025 02:19
@yufeih yufeih merged commit 9f239e5 into dotnet:main Sep 2, 2025
9 checks passed
This was referenced Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants