GeezerVison is showing github.com — Add : to beginning and end of every useId (#23360) · react/react@efe4121
File treeExpand file treeCollapse file tree Open diff view settings react-debug-tools/src/__tests__
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -614,7 +614,7 @@ describe('ReactHooksInspectionIntegration', () => { | 614 | 614 | expect(tree[0].id).toEqual(0); | 615 | 615 | expect(tree[0].isStateEditable).toEqual(false); | 616 | 616 | expect(tree[0].name).toEqual('Id'); | 617 | | - expect(String(tree[0].value).startsWith('r:')).toBe(true); | | 617 | + expect(String(tree[0].value).startsWith(':r')).toBe(true); | 618 | 618 |
| 619 | 619 | expect(tree[1]).toEqual({ | 620 | 620 | id: 1, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/__tests__/ReactDOMUseId-test.js +15-11Lines changed: 15 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,7 +93,11 @@ describe('useId', () => { | 93 | 93 | } | 94 | 94 |
| 95 | 95 | function normalizeTreeIdForTesting(id) { | 96 | | - const [serverClientPrefix, base32, hookIndex] = id.split(':'); | | 96 | + const result = id.match(/:(R|r)(.*):(([0-9]*):)?/); | | 97 | + if (result === undefined) { | | 98 | + throw new Error('Invalid id format'); | | 99 | + } | | 100 | + const [, serverClientPrefix, base32, hookIndex] = result; | 97 | 101 | if (serverClientPrefix.endsWith('r')) { | 98 | 102 | // Client ids aren't stable. For testing purposes, strip out the counter. | 99 | 103 | return ( | @@ -278,7 +282,7 @@ describe('useId', () => { | 278 | 282 | // 'R:' prefix, and the first character after that, which may not correspond | 279 | 283 | // to a complete set of 5 bits. | 280 | 284 | // | 281 | | - // Example: R:clalalalalalalala... | | 285 | + // Example: :Rclalalalalalalala...: | 282 | 286 | // | 283 | 287 | // We can use this pattern to test large ids that exceed the bitwise | 284 | 288 | // safe range (32 bits). The algorithm should theoretically support ids | @@ -313,8 +317,8 @@ describe('useId', () => { | 313 | 317 |
| 314 | 318 | // Confirm that every id matches the expected pattern | 315 | 319 | for (let i = 0; i < divs.length; i++) { | 316 | | - // Example: R:clalalalalalalala... | 317 | | - expect(divs[i].id).toMatch(/^R:.(((al)*a?)((la)*l?))*$/); | | 320 | + // Example: :Rclalalalalalalala...: | | 321 | + expect(divs[i].id).toMatch(/^:R.(((al)*a?)((la)*l?))*:$/); | 318 | 322 | } | 319 | 323 | }); | 320 | 324 |
| @@ -338,7 +342,7 @@ describe('useId', () => { | 338 | 342 | <div | 339 | 343 | id="container" | 340 | 344 | > | 341 | | - R:0, R:0:1, R:0:2 | | 345 | + :R0:, :R0:1:, :R0:2: | 342 | 346 | <!-- --> | 343 | 347 | </div> | 344 | 348 | `); | @@ -364,7 +368,7 @@ describe('useId', () => { | 364 | 368 | <div | 365 | 369 | id="container" | 366 | 370 | > | 367 | | - R:0 | | 371 | + :R0: | 368 | 372 | <!-- --> | 369 | 373 | </div> | 370 | 374 | `); | @@ -603,10 +607,10 @@ describe('useId', () => { | 603 | 607 | id="container" | 604 | 608 | > | 605 | 609 | <div> | 606 | | - custom-prefix-R:1 | | 610 | + :custom-prefix-R1: | 607 | 611 | </div> | 608 | 612 | <div> | 609 | | - custom-prefix-R:2 | | 613 | + :custom-prefix-R2: | 610 | 614 | </div> | 611 | 615 | </div> | 612 | 616 | `); | @@ -620,13 +624,13 @@ describe('useId', () => { | 620 | 624 | id="container" | 621 | 625 | > | 622 | 626 | <div> | 623 | | - custom-prefix-R:1 | | 627 | + :custom-prefix-R1: | 624 | 628 | </div> | 625 | 629 | <div> | 626 | | - custom-prefix-R:2 | | 630 | + :custom-prefix-R2: | 627 | 631 | </div> | 628 | 632 | <div> | 629 | | - custom-prefix-r:0 | | 633 | + :custom-prefix-r0: | 630 | 634 | </div> | 631 | 635 | </div> | 632 | 636 | `); | |
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 |
|---|
@@ -130,7 +130,7 @@ export function createResponseState( | 130 | 130 | placeholderPrefix: stringToPrecomputedChunk(idPrefix + 'P:'), | 131 | 131 | segmentPrefix: stringToPrecomputedChunk(idPrefix + 'S:'), | 132 | 132 | boundaryPrefix: idPrefix + 'B:', | 133 | | - idPrefix: idPrefix + 'R:', | | 133 | + idPrefix: idPrefix, | 134 | 134 | nextSuspenseID: 0, | 135 | 135 | sentCompleteSegmentFunction: false, | 136 | 136 | sentCompleteBoundaryFunction: false, | @@ -242,13 +242,13 @@ export function makeId( | 242 | 242 | ): string { | 243 | 243 | const idPrefix = responseState.idPrefix; | 244 | 244 |
| 245 | | - let id = idPrefix + 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 += localId.toString(32) + ':'; | 252 | 252 | } | 253 | 253 |
| 254 | 254 | return id; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.new.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2072,19 +2072,19 @@ 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 += localId.toString(32) + ':'; | 2083 | 2083 | } | 2084 | 2084 | } else { | 2085 | 2085 | // Use a lowercase r prefix for client-generated ids. | 2086 | 2086 | const globalClientId = globalClientIdCounter++; | 2087 | | - id = identifierPrefix + 'r:' + globalClientId.toString(32); | | 2087 | + id = ':' + identifierPrefix + 'r' + globalClientId.toString(32) + ':'; | 2088 | 2088 | } | 2089 | 2089 |
| 2090 | 2090 | hook.memoizedState = id; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberHooks.old.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2072,19 +2072,19 @@ 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 += localId.toString(32) + ':'; | 2083 | 2083 | } | 2084 | 2084 | } else { | 2085 | 2085 | // Use a lowercase r prefix for client-generated ids. | 2086 | 2086 | const globalClientId = globalClientIdCounter++; | 2087 | | - id = identifierPrefix + 'r:' + globalClientId.toString(32); | | 2087 | + id = ':' + identifierPrefix + 'r' + globalClientId.toString(32) + ':'; | 2088 | 2088 | } | 2089 | 2089 |
| 2090 | 2090 | hook.memoizedState = id; | |
|