Skip to content

Commit

Permalink
Use valid CSS selectors in useId format
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Jan 6, 2025
1 parent defffdb commit 389e0cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ export function makeId(
): string {
const idPrefix = resumableState.idPrefix;

let id = ':' + idPrefix + 'R' + treeId;
let id = '\u00AB' + idPrefix + 'R' + treeId;

// Unless this is the first id at this level, append a number at the end
// that represents the position of this useId hook among all the useId
Expand All @@ -829,7 +829,7 @@ export function makeId(
id += 'H' + localId.toString(32);
}

return id + ':';
return id + '\u00BB';
}

function encodeHTMLTextNode(text: string): string {
Expand Down
11 changes: 8 additions & 3 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3527,7 +3527,7 @@ function mountId(): string {
const treeId = getTreeId();

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

// Unless this is the first id at this level, append a number at the end
// that represents the position of this useId hook among all the useId
Expand All @@ -3537,11 +3537,16 @@ function mountId(): string {
id += 'H' + localId.toString(32);
}

id += ':';
id += '\u00BB';
} else {
// Use a lowercase r prefix for client-generated ids.
const globalClientId = globalClientIdCounter++;
id = ':' + identifierPrefix + 'r' + globalClientId.toString(32) + ':';
id =
'\u00AB' +
identifierPrefix +
'r' +
globalClientId.toString(32) +
'\u00BB';
}

hook.memoizedState = id;
Expand Down

0 comments on commit 389e0cf

Please sign in to comment.