Skip to content

Commit 752f591

Browse files
committed
switch to S from F for Server Component ids
1 parent 2c0a9bc commit 752f591

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,9 @@ describe('ReactFlight', () => {
513513
});
514514

515515
describe('Hooks', () => {
516-
function DivWithId() {
516+
function DivWithId({children}) {
517517
const id = React.useId();
518-
return <div prop={id} />;
518+
return <div prop={id}>{children}</div>;
519519
}
520520

521521
it('should support useId', () => {
@@ -534,8 +534,8 @@ describe('ReactFlight', () => {
534534
});
535535
expect(ReactNoop).toMatchRenderedOutput(
536536
<>
537-
<div prop=":F1:" />
538-
<div prop=":F2:" />
537+
<div prop=":S1:" />
538+
<div prop=":S2:" />
539539
</>,
540540
);
541541
});
@@ -558,8 +558,8 @@ describe('ReactFlight', () => {
558558
});
559559
expect(ReactNoop).toMatchRenderedOutput(
560560
<>
561-
<div prop=":fooF1:" />
562-
<div prop=":fooF2:" />
561+
<div prop=":fooS1:" />
562+
<div prop=":fooS2:" />
563563
</>,
564564
);
565565
});

packages/react-server/src/ReactFlightHooks.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ export function getCurrentCache() {
105105

106106
function useId(): string {
107107
if (currentRequest === null) {
108-
throw new Error('useId can only be used while React is rendering.');
108+
throw new Error('useId can only be used while React is rendering');
109109
}
110110
const prefix = currentRequest.identifierPrefix
111111
? currentRequest.identifierPrefix
112112
: '';
113113
const id = currentRequest.identifierCount++;
114-
return ':' + prefix + 'F' + id.toString(32) + ':';
114+
// use 'S' for Flight components to distinguish from 'R' and 'r' in Fizz/Client
115+
return ':' + prefix + 'S' + id.toString(32) + ':';
115116
}

scripts/error-codes/codes.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,5 +416,6 @@
416416
"428": "useServerContext is only supported while rendering.",
417417
"429": "ServerContext: %s already defined",
418418
"430": "ServerContext can only have a value prop and children. Found: %s",
419-
"431": "React elements are not allowed in ServerContext"
419+
"431": "React elements are not allowed in ServerContext",
420+
"432": "useId can only be used while React is rendering"
420421
}

0 commit comments

Comments
 (0)