Skip to content

fix(audit): use textContent instead of innerText#15568

Open
ematipico wants to merge 3 commits intomainfrom
flue/fix-15558
Open

fix(audit): use textContent instead of innerText#15568
ematipico wants to merge 3 commits intomainfrom
flue/fix-15558

Conversation

@ematipico
Copy link
Member

@ematipico ematipico commented Feb 18, 2026

Changes

Closes #15558

Did some research and textContent is generally safer than innerText, so it's safe to use.

Testing

Added a test

Docs

…vent false positives inside closed <details>
@changeset-bot
Copy link

changeset-bot bot commented Feb 18, 2026

🦋 Changeset detected

Latest commit: 1da384f

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Feb 18, 2026
@ematipico ematipico changed the title fix(audit): use textContent instead of innerText in a11y rules to pre… fix(audit): use textContent instead of innerText Feb 18, 2026
@ematipico ematipico marked this pull request as ready for review February 18, 2026 14:52
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 18, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing flue/fix-15558 (1da384f) with main (e959698)

Open in CodSpeed

'Headings and anchors must have an accessible name, which can come from: inner text, aria-label, aria-labelledby, an img with alt property, or an svg with a tag <title></title>.',
selector: a11y_required_content.join(','),
match(element: HTMLElement) {
// innerText is used to ignore hidden text
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we purposely used innerText for this reason and it used to be textContent before?

Copy link
Contributor

Choose a reason for hiding this comment

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

what is "hidden text"?

Copy link
Member

Choose a reason for hiding this comment

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

IIRC, it was something with if you had elements nested in a certain common way, you can see the original PR that changed this here: #9483

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately there aren't tests for possible regressions :/

Copy link
Contributor

@matthewp matthewp Feb 18, 2026

Choose a reason for hiding this comment

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

Oh yeah, textContent collects children element text too.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ematipico use const text = element.firstChild?.nodeType === 3 ? element.firstChild.nodeValue.trim() : ""; instead

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

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit tool reports Missing content in <details> headings/anchors with inner text

4 participants

Comments