KEMBAR78
Use underscore instead of « » for useId algorithm by sebmarkbage · Pull Request #33422 · facebook/react · GitHub
Skip to content

Conversation

sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Jun 3, 2025

Alternative to #33421. The difference is that this also adds an underscore between the "R" and the ID.

The reason we wanted to use special characters is because we use the full spectrum of A-Z 0-9 in our ID generation so we can basically collide with any common word (or anyone using a similar algorithm, base64 or even base16). It's a little less likely that someone would put _R_ specifically unless you generate like two IDs separated by underscore.

9w2ogt

@sebmarkbage sebmarkbage requested a review from eps1lon June 3, 2025 14:37
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Jun 3, 2025
@react-sizebot
Copy link

react-sizebot commented Jun 3, 2025

Comparing: 2b4064e...7d3cefc

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 529.84 kB 529.82 kB = 93.52 kB 93.51 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 650.94 kB 650.91 kB = 114.65 kB 114.63 kB
facebook-www/ReactDOM-prod.classic.js = 675.89 kB 675.86 kB = 118.93 kB 118.91 kB
facebook-www/ReactDOM-prod.modern.js = 666.17 kB 666.14 kB = 117.32 kB 117.30 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-noop-renderer/cjs/react-noop-renderer-server.development.js = 7.95 kB 7.93 kB = 1.67 kB 1.67 kB
oss-stable-semver/react-noop-renderer/cjs/react-noop-renderer-server.development.js = 7.95 kB 7.93 kB = 1.67 kB 1.67 kB
oss-stable/react-noop-renderer/cjs/react-noop-renderer-server.development.js = 7.95 kB 7.93 kB = 1.67 kB 1.67 kB
oss-experimental/react-server/cjs/react-server.development.js = 210.48 kB 210.04 kB = 36.48 kB 36.40 kB
oss-stable-semver/react-server/cjs/react-server.development.js = 193.36 kB 192.92 kB = 34.29 kB 34.21 kB
oss-stable/react-server/cjs/react-server.development.js = 193.36 kB 192.92 kB = 34.29 kB 34.21 kB

Generated by 🚫 dangerJS against 7d3cefc

Copy link
Collaborator

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

packages/react-dom-bindings/src/server/fizz-instruction-set/ReactDOMFizzInstructionSetInlineCodeStrings.js has the lowercase unicode delimiters e.g. \u00ab

@sebmarkbage sebmarkbage merged commit 1ae0a84 into facebook:main Jun 3, 2025
240 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 3, 2025
Alternative to #33421. The difference is that this also adds an
underscore between the "R" and the ID.

The reason we wanted to use special characters is because we use the
full spectrum of A-Z 0-9 in our ID generation so we can basically
collide with any common word (or anyone using a similar algorithm,
base64 or even base16). It's a little less likely that someone would put
`_R_` specifically unless you generate like two IDs separated by
underscore.

![9w2ogt](https://github.com/user-attachments/assets/21b2d2ac-1a3a-4657-ba0b-1616e49dfdee)

DiffTrain build for [1ae0a84](1ae0a84)
github-actions bot pushed a commit that referenced this pull request Jun 3, 2025
Alternative to #33421. The difference is that this also adds an
underscore between the "R" and the ID.

The reason we wanted to use special characters is because we use the
full spectrum of A-Z 0-9 in our ID generation so we can basically
collide with any common word (or anyone using a similar algorithm,
base64 or even base16). It's a little less likely that someone would put
`_R_` specifically unless you generate like two IDs separated by
underscore.

![9w2ogt](https://github.com/user-attachments/assets/21b2d2ac-1a3a-4657-ba0b-1616e49dfdee)

DiffTrain build for [1ae0a84](1ae0a84)
@davejsdev
Copy link

I see things have settled on using _R_ after all the headaches with special chars. Not sure if I missed something while sifting through the discussions, but I'm wondering why we don't want to prefix the ids with a more identifiable namespace like __react__.

The benefit to making this more explicit is if I came across _R_ in an app and didn't know the implementation details of useId(), I wouldn't immediately infer this came from React.

Off the top of my head, I'm thinking perhaps shorter names are marginally more performant? Is that a concern, or are there any other valid concerns that made _R_ preferable to something like __react__?

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

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants