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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
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 number | Diff line number | Diff line change |
|---|
@@ -93,7 +93,7 @@ describe('useId', () => { |
93 | 93 | } |
94 | 94 |
|
95 | 95 | 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]*))?:/); |
97 | 97 | if (result === undefined) { |
98 | 98 | throw new Error('Invalid id format'); |
99 | 99 | } |
@@ -342,7 +342,7 @@ describe('useId', () => { |
342 | 342 | <div |
343 | 343 | id="container" |
344 | 344 | > |
345 | | - :R0:, :R0:1:, :R0:2: |
| 345 | + :R0:, :R0H1:, :R0H2: |
346 | 346 | <!-- --> |
347 | 347 | </div> |
348 | 348 | `); |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-dom/src/server/ReactDOMServerFormatConfig.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -242,16 +242,16 @@ export function makeId( |
242 | 242 | ): string { |
243 | 243 | const idPrefix = responseState.idPrefix; |
244 | 244 |
|
245 | | - let id = ':' + idPrefix + 'R' + treeId + ':'; |
| 245 | + let id = ':' + idPrefix + 'R' + treeId; |
246 | 246 |
|
247 | 247 | // Unless this is the first id at this level, append a number at the end |
248 | 248 | // that represents the position of this useId hook among all the useId |
249 | 249 | // hooks for this fiber. |
250 | 250 | if (localId > 0) { |
251 | | - id += localId.toString(32) + ':'; |
| 251 | + id += 'H' + localId.toString(32); |
252 | 252 | } |
253 | 253 |
|
254 | | - return id; |
| 254 | + return id + ':'; |
255 | 255 | } |
256 | 256 |
|
257 | 257 | function encodeHTMLTextNode(text: string): string { |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.new.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2072,15 +2072,17 @@ function mountId(): string { |
2072 | 2072 | const treeId = getTreeId(); |
2073 | 2073 |
|
2074 | 2074 | // Use a captial R prefix for server-generated ids. |
2075 | | - id = ':' + identifierPrefix + 'R' + treeId + ':'; |
| 2075 | + id = ':' + identifierPrefix + 'R' + treeId; |
2076 | 2076 |
|
2077 | 2077 | // Unless this is the first id at this level, append a number at the end |
2078 | 2078 | // that represents the position of this useId hook among all the useId |
2079 | 2079 | // hooks for this fiber. |
2080 | 2080 | const localId = localIdCounter++; |
2081 | 2081 | if (localId > 0) { |
2082 | | - id += localId.toString(32) + ':'; |
| 2082 | + id += 'H' + localId.toString(32); |
2083 | 2083 | } |
| 2084 | + |
| 2085 | + id += ':'; |
2084 | 2086 | } else { |
2085 | 2087 | // Use a lowercase r prefix for client-generated ids. |
2086 | 2088 | const globalClientId = globalClientIdCounter++; |
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.old.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2072,15 +2072,17 @@ function mountId(): string { |
2072 | 2072 | const treeId = getTreeId(); |
2073 | 2073 |
|
2074 | 2074 | // Use a captial R prefix for server-generated ids. |
2075 | | - id = ':' + identifierPrefix + 'R' + treeId + ':'; |
| 2075 | + id = ':' + identifierPrefix + 'R' + treeId; |
2076 | 2076 |
|
2077 | 2077 | // Unless this is the first id at this level, append a number at the end |
2078 | 2078 | // that represents the position of this useId hook among all the useId |
2079 | 2079 | // hooks for this fiber. |
2080 | 2080 | const localId = localIdCounter++; |
2081 | 2081 | if (localId > 0) { |
2082 | | - id += localId.toString(32) + ':'; |
| 2082 | + id += 'H' + localId.toString(32); |
2083 | 2083 | } |
| 2084 | + |
| 2085 | + id += ':'; |
2084 | 2086 | } else { |
2085 | 2087 | // Use a lowercase r prefix for client-generated ids. |
2086 | 2088 | const globalClientId = globalClientIdCounter++; |
|