GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — useId: Use 'H' to separate main id from hook index (#23363) · react/react@5d08a24

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • react-dom/src
      • __tests__
        • ReactDOMUseId-test.js
      • server
        • ReactDOMServerFormatConfig.js
    • react-reconciler/src
      • ReactFiberHooks.new.js
      • ReactFiberHooks.old.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/react-dom/src/__tests__/ReactDOMUseId-test.js‎

Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMUseId-test.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('useId', () => {
9393
}
9494

9595
function normalizeTreeIdForTesting(id) {
96-
const result = id.match(/:(R|r)(.*):(([0-9]*):)?/);
96+
const result = id.match(/:(R|r)([a-z0-9]*)(H([0-9]*))?:/);
9797
if (result === undefined) {
9898
throw new Error('Invalid id format');
9999
}
@@ -342,7 +342,7 @@ describe('useId', () => {
342342
<div
343343
id="container"
344344
>
345-
:R0:, :R0:1:, :R0:2:
345+
:R0:, :R0H1:, :R0H2:
346346
<!-- -->
347347
</div>
348348
`);
Collapse file

‎packages/react-dom/src/server/ReactDOMServerFormatConfig.js‎

Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactDOMServerFormatConfig.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,16 @@ export function makeId(
242242
): string {
243243
const idPrefix = responseState.idPrefix;
244244

245-
let id = ':' + idPrefix + 'R' + treeId + ':';
245+
let id = ':' + idPrefix + 'R' + treeId;
246246

247247
// Unless this is the first id at this level, append a number at the end
248248
// that represents the position of this useId hook among all the useId
249249
// hooks for this fiber.
250250
if (localId > 0) {
251-
id += localId.toString(32) + ':';
251+
id += 'H' + localId.toString(32);
252252
}
253253

254-
return id;
254+
return id + ':';
255255
}
256256

257257
function encodeHTMLTextNode(text: string): string {
Collapse file

‎packages/react-reconciler/src/ReactFiberHooks.new.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.new.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,15 +2072,17 @@ function mountId(): string {
20722072
const treeId = getTreeId();
20732073

20742074
// Use a captial R prefix for server-generated ids.
2075-
id = ':' + identifierPrefix + 'R' + treeId + ':';
2075+
id = ':' + identifierPrefix + 'R' + treeId;
20762076

20772077
// Unless this is the first id at this level, append a number at the end
20782078
// that represents the position of this useId hook among all the useId
20792079
// hooks for this fiber.
20802080
const localId = localIdCounter++;
20812081
if (localId > 0) {
2082-
id += localId.toString(32) + ':';
2082+
id += 'H' + localId.toString(32);
20832083
}
2084+
2085+
id += ':';
20842086
} else {
20852087
// Use a lowercase r prefix for client-generated ids.
20862088
const globalClientId = globalClientIdCounter++;
Collapse file

‎packages/react-reconciler/src/ReactFiberHooks.old.js‎

Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.old.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,15 +2072,17 @@ function mountId(): string {
20722072
const treeId = getTreeId();
20732073

20742074
// Use a captial R prefix for server-generated ids.
2075-
id = ':' + identifierPrefix + 'R' + treeId + ':';
2075+
id = ':' + identifierPrefix + 'R' + treeId;
20762076

20772077
// Unless this is the first id at this level, append a number at the end
20782078
// that represents the position of this useId hook among all the useId
20792079
// hooks for this fiber.
20802080
const localId = localIdCounter++;
20812081
if (localId > 0) {
2082-
id += localId.toString(32) + ':';
2082+
id += 'H' + localId.toString(32);
20832083
}
2084+
2085+
id += ':';
20842086
} else {
20852087
// Use a lowercase r prefix for client-generated ids.
20862088
const globalClientId = globalClientIdCounter++;

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.