Skip to content

Bug: useId IDs have special characters that conflict with certain DSLs (like CSS) #26839

@EthanStandel

Description

@EthanStandel

The ID scheme for the useId hook returns IDs that look like ":S1:", but : is not a valid character for CSS identifiers and must be escaped. On client-only components, you can wrap the ID in CSS.escape but the CSS global object doesn't exist on the server so this doesn't work for server-component renders.

React version: 18.2

Steps To Reproduce

  1. Try utilizing the id's created by useId in CSS identifiers.
  2. It doesn't work.

Link to code example: https://stackblitz.com/edit/react-ts-zhtk6u?file=Example.tsx

The current behavior

The current implementation of useId creates IDs with special characters which can conflict with certain DSLs (in this example, CSS) that React has to commonly interact with.

The expected behavior

Don't use special characters in IDs created by useId.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions