Skip to content

Setting innerHTML of <style> elements will cause issues with trusted types #3117

@terrymun

Description

@terrymun

Bug report

Current Behavior

There are several Radix UI Primitives that rely on dangerouslySetInnerHtml to inject content into <style> tags, for example the <ScrollArea> (see code) and <Select> (see code) components.

This causes issues in React apps that has set trusted types in their CSP headers.

p/s: Not all browsers support the trusted types CSP header yet.

Expected behavior

Using these components should not cause warnings in browsers that support trusted types CSP headers serving a React App with such headers set.

Suggested solution

  • Find alternatives to using dangerouslySetInnerHtml to set inline styles
  • Use DOMPurify (but that comes at a cost of using a very heavy library)

Your environment

Software Name(s) Version
Radix Package(s) @radix-ui/react-scroll-area, @radix-ui/react-select Latest on both
React n/a 19 (via Next.js)
Browser Chrome 128
Assistive tech n/a n/a
Node n/a 20.14.0
pnpm n/a 9.10.0
Operating System macOS Sonoma (14.6.1)

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