Skip to content

fix(tooltip): reset escaped content without innerHTML - #1418

Open
jase88 wants to merge 1 commit into
openng-org:mainfrom
jase88:fix/tooltip-trusted-types
Open

fix(tooltip): reset escaped content without innerHTML#1418
jase88 wants to merge 1 commit into
openng-org:mainfrom
jase88:fix/tooltip-trusted-types

Conversation

@jase88

@jase88 jase88 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #223

Problem

With a Trusted Types CSP (require-trusted-types-for 'script'), showing a tooltip throws:

Uncaught TypeError: Failed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment.

Tooltip.updateText() assigned an empty string to innerHTML purely to clear previously rendered text before appending the escaped text node. Trusted Types rejects any plain-string innerHTML assignment, including the empty one.

Change

Clear the tooltip text with textContent = '' instead. Same effect (removes all child nodes), no Trusted Types violation.

The escape: false branch still assigns innerHTML — that path intentionally renders HTML and is out of scope here.

Test

Added a unit test that makes innerHTML throw on the tooltip text element (mimicking a Trusted Types document) and asserts updateText() still replaces the previous content.

ng test optimus-ui --include='**/tooltip/tooltip.spec.ts' → 45/45 passing.

Assigning a plain string to innerHTML throws under a Trusted Types CSP
("This document requires 'TrustedHTML' assignment"). Clearing the
tooltip text via textContent has the same effect without triggering the
policy.

Fixes openng-org#223
@jase88

jase88 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

@geromegrignon @dominicbachmann
Recreated this MR from PrimeNG PR.
Would love to see this being reviewed and will port more of my pending PRs if this lands

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.

CSP Trusted Types fails for Tooltip

1 participant