@@ -57,8 +57,9 @@ export type ResponseState = {
5757 placeholderPrefix : PrecomputedChunk ,
5858 segmentPrefix : PrecomputedChunk ,
5959 boundaryPrefix : string ,
60- opaqueIdentifierPrefix : PrecomputedChunk ,
60+ opaqueIdentifierPrefix : string ,
6161 nextSuspenseID : number ,
62+ nextOpaqueID : number ,
6263 sentCompleteSegmentFunction : boolean ,
6364 sentCompleteBoundaryFunction : boolean ,
6465 sentClientRenderFunction : boolean ,
@@ -72,8 +73,9 @@ export function createResponseState(
7273 placeholderPrefix : stringToPrecomputedChunk ( identifierPrefix + 'P:' ) ,
7374 segmentPrefix : stringToPrecomputedChunk ( identifierPrefix + 'S:' ) ,
7475 boundaryPrefix : identifierPrefix + 'B:' ,
75- opaqueIdentifierPrefix : stringToPrecomputedChunk ( identifierPrefix + 'R:' ) ,
76+ opaqueIdentifierPrefix : identifierPrefix + 'R:' ,
7677 nextSuspenseID : 0 ,
78+ nextOpaqueID : 0 ,
7779 sentCompleteSegmentFunction : false ,
7880 sentCompleteBoundaryFunction : false ,
7981 sentClientRenderFunction : false ,
@@ -172,6 +174,22 @@ export function createSuspenseBoundaryID(
172174 return { formattedID : null } ;
173175}
174176
177+ export type OpaqueIDType = string ;
178+
179+ export function makeServerID (
180+ responseState : null | ResponseState ,
181+ ) : OpaqueIDType {
182+ invariant (
183+ responseState !== null ,
184+ 'Invalid hook call. Hooks can only be called inside of the body of a function component.' ,
185+ ) ;
186+ // TODO: This is not deterministic since it's created during render.
187+ return (
188+ responseState . opaqueIdentifierPrefix +
189+ ( responseState . nextOpaqueID ++ ) . toString ( 36 )
190+ ) ;
191+ }
192+
175193function encodeHTMLTextNode ( text : string ) : string {
176194 return escapeTextForBrowser ( text ) ;
177195}
0 commit comments