Skip to content

Commit

Permalink
Use valid CSS selectors in useId format (#32001)
Browse files Browse the repository at this point in the history
For the `useId` algorithm we used colon `:` before and after.
#23360

This avoids collisions in general by using an unusual characters. It
also avoids collisions when concatenated with some other ID.
Unfortunately, `:` is not a valid character in `view-transition-name`.

This PR swaps the format from:

```
:r123:
```

To the unicode:

```
«r123»
```

Which is valid CSS selectors. This also allows them being used for
`querySelector()` which we didn't really find a legit use for but seems
ok-ish.

That way you can get a view-transition-name that you can manually
reference. E.g. to generate styles:

```js
const id = useId();
return <>
  <style>{`
    ::view-transition-group(${id}) { ... }
    ::view-transition-old(${id}) { ... }
    ::view-transition-new(${id}) { ... }
  `}</style>
  <ViewTransition name={id}>...</ViewTransition>
</>;
```

DiffTrain build for [2e4db33](2e4db33)
  • Loading branch information
sebmarkbage committed Feb 25, 2025
1 parent d5a15a6 commit 5849887
Show file tree
Hide file tree
Showing 36 changed files with 178 additions and 146 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22e39ea72e9d10f6634ea580aaba49c2e759ef0e
403d4fb852384b820a8fe405413891d8c74bbf5d
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22e39ea72e9d10f6634ea580aaba49c2e759ef0e
403d4fb852384b820a8fe405413891d8c74bbf5d
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.1.0-www-classic-22e39ea7-20250225";
exports.version = "19.1.0-www-classic-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.1.0-www-modern-22e39ea7-20250225";
exports.version = "19.1.0-www-modern-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-classic-22e39ea7-20250225";
exports.version = "19.1.0-www-classic-2e4db334-20250225";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-modern-22e39ea7-20250225";
exports.version = "19.1.0-www-modern-2e4db334-20250225";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-classic-22e39ea7-20250225";
exports.version = "19.1.0-www-classic-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.1.0-www-modern-22e39ea7-20250225";
exports.version = "19.1.0-www-modern-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
12 changes: 8 additions & 4 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4591,7 +4591,11 @@ __DEV__ &&
identifierPrefix = workInProgressRoot.identifierPrefix,
globalClientId = globalClientIdCounter++;
identifierPrefix =
":" + identifierPrefix + "r" + globalClientId.toString(32) + ":";
"\u00ab" +
identifierPrefix +
"r" +
globalClientId.toString(32) +
"\u00bb";
return (hook.memoizedState = identifierPrefix);
}
function mountRefresh() {
Expand Down Expand Up @@ -17312,10 +17316,10 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.1.0-www-classic-22e39ea7-20250225",
version: "19.1.0-www-classic-2e4db334-20250225",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-classic-22e39ea7-20250225"
reconcilerVersion: "19.1.0-www-classic-2e4db334-20250225"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -17349,7 +17353,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.1.0-www-classic-22e39ea7-20250225";
exports.version = "19.1.0-www-classic-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
12 changes: 8 additions & 4 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -4497,7 +4497,11 @@ __DEV__ &&
identifierPrefix = workInProgressRoot.identifierPrefix,
globalClientId = globalClientIdCounter++;
identifierPrefix =
":" + identifierPrefix + "r" + globalClientId.toString(32) + ":";
"\u00ab" +
identifierPrefix +
"r" +
globalClientId.toString(32) +
"\u00bb";
return (hook.memoizedState = identifierPrefix);
}
function mountRefresh() {
Expand Down Expand Up @@ -17084,10 +17088,10 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.1.0-www-modern-22e39ea7-20250225",
version: "19.1.0-www-modern-2e4db334-20250225",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-modern-22e39ea7-20250225"
reconcilerVersion: "19.1.0-www-modern-2e4db334-20250225"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -17121,7 +17125,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.1.0-www-modern-22e39ea7-20250225";
exports.version = "19.1.0-www-modern-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
12 changes: 8 additions & 4 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3350,7 +3350,11 @@ var HooksDispatcherOnMount = {
identifierPrefix = workInProgressRoot.identifierPrefix,
globalClientId = globalClientIdCounter++;
identifierPrefix =
":" + identifierPrefix + "r" + globalClientId.toString(32) + ":";
"\u00ab" +
identifierPrefix +
"r" +
globalClientId.toString(32) +
"\u00bb";
return (hook.memoizedState = identifierPrefix);
},
useHostTransitionStatus: useHostTransitionStatus,
Expand Down Expand Up @@ -11257,10 +11261,10 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1550 = {
bundleType: 0,
version: "19.1.0-www-classic-22e39ea7-20250225",
version: "19.1.0-www-classic-2e4db334-20250225",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-classic-22e39ea7-20250225"
reconcilerVersion: "19.1.0-www-classic-2e4db334-20250225"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1551 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -11286,4 +11290,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.1.0-www-classic-22e39ea7-20250225";
exports.version = "19.1.0-www-classic-2e4db334-20250225";
12 changes: 8 additions & 4 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -3207,7 +3207,11 @@ var HooksDispatcherOnMount = {
identifierPrefix = workInProgressRoot.identifierPrefix,
globalClientId = globalClientIdCounter++;
identifierPrefix =
":" + identifierPrefix + "r" + globalClientId.toString(32) + ":";
"\u00ab" +
identifierPrefix +
"r" +
globalClientId.toString(32) +
"\u00bb";
return (hook.memoizedState = identifierPrefix);
},
useHostTransitionStatus: useHostTransitionStatus,
Expand Down Expand Up @@ -10972,10 +10976,10 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1523 = {
bundleType: 0,
version: "19.1.0-www-modern-22e39ea7-20250225",
version: "19.1.0-www-modern-2e4db334-20250225",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-modern-22e39ea7-20250225"
reconcilerVersion: "19.1.0-www-modern-2e4db334-20250225"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1524 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -11001,4 +11005,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.1.0-www-modern-22e39ea7-20250225";
exports.version = "19.1.0-www-modern-2e4db334-20250225";
16 changes: 8 additions & 8 deletions compiled/facebook-www/ReactDOM-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6603,14 +6603,14 @@ __DEV__ &&
identifierPrefix = workInProgressRoot.identifierPrefix;
if (isHydrating) {
var treeId = getTreeId();
identifierPrefix = ":" + identifierPrefix + "R" + treeId;
identifierPrefix = "\u00ab" + identifierPrefix + "R" + treeId;
treeId = localIdCounter++;
0 < treeId && (identifierPrefix += "H" + treeId.toString(32));
identifierPrefix += ":";
identifierPrefix += "\u00bb";
} else
(treeId = globalClientIdCounter++),
(identifierPrefix =
":" + identifierPrefix + "r" + treeId.toString(32) + ":");
"\u00ab" + identifierPrefix + "r" + treeId.toString(32) + "\u00bb");
return (hook.memoizedState = identifierPrefix);
}
function mountRefresh() {
Expand Down Expand Up @@ -28505,11 +28505,11 @@ __DEV__ &&
return_targetInst = null;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.1.0-www-classic-22e39ea7-20250225" !== isomorphicReactPackageVersion)
if ("19.1.0-www-classic-2e4db334-20250225" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.1.0-www-classic-22e39ea7-20250225\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.1.0-www-classic-2e4db334-20250225\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -28552,10 +28552,10 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.1.0-www-classic-22e39ea7-20250225",
version: "19.1.0-www-classic-2e4db334-20250225",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-classic-22e39ea7-20250225"
reconcilerVersion: "19.1.0-www-classic-2e4db334-20250225"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -29153,7 +29153,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.1.0-www-classic-22e39ea7-20250225";
exports.version = "19.1.0-www-classic-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
16 changes: 8 additions & 8 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -6490,14 +6490,14 @@ __DEV__ &&
identifierPrefix = workInProgressRoot.identifierPrefix;
if (isHydrating) {
var treeId = getTreeId();
identifierPrefix = ":" + identifierPrefix + "R" + treeId;
identifierPrefix = "\u00ab" + identifierPrefix + "R" + treeId;
treeId = localIdCounter++;
0 < treeId && (identifierPrefix += "H" + treeId.toString(32));
identifierPrefix += ":";
identifierPrefix += "\u00bb";
} else
(treeId = globalClientIdCounter++),
(identifierPrefix =
":" + identifierPrefix + "r" + treeId.toString(32) + ":");
"\u00ab" + identifierPrefix + "r" + treeId.toString(32) + "\u00bb");
return (hook.memoizedState = identifierPrefix);
}
function mountRefresh() {
Expand Down Expand Up @@ -28291,11 +28291,11 @@ __DEV__ &&
return_targetInst = null;
(function () {
var isomorphicReactPackageVersion = React.version;
if ("19.1.0-www-modern-22e39ea7-20250225" !== isomorphicReactPackageVersion)
if ("19.1.0-www-modern-2e4db334-20250225" !== isomorphicReactPackageVersion)
throw Error(
'Incompatible React versions: The "react" and "react-dom" packages must have the exact same version. Instead got:\n - react: ' +
(isomorphicReactPackageVersion +
"\n - react-dom: 19.1.0-www-modern-22e39ea7-20250225\nLearn more: https://react.dev/warnings/version-mismatch")
"\n - react-dom: 19.1.0-www-modern-2e4db334-20250225\nLearn more: https://react.dev/warnings/version-mismatch")
);
})();
("function" === typeof Map &&
Expand Down Expand Up @@ -28338,10 +28338,10 @@ __DEV__ &&
!(function () {
var internals = {
bundleType: 1,
version: "19.1.0-www-modern-22e39ea7-20250225",
version: "19.1.0-www-modern-2e4db334-20250225",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-modern-22e39ea7-20250225"
reconcilerVersion: "19.1.0-www-modern-2e4db334-20250225"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -28939,7 +28939,7 @@ __DEV__ &&
exports.useFormStatus = function () {
return resolveDispatcher().useHostTransitionStatus();
};
exports.version = "19.1.0-www-modern-22e39ea7-20250225";
exports.version = "19.1.0-www-modern-2e4db334-20250225";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
16 changes: 8 additions & 8 deletions compiled/facebook-www/ReactDOM-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4334,14 +4334,14 @@ var HooksDispatcherOnMount = {
identifierPrefix = workInProgressRoot.identifierPrefix;
if (isHydrating) {
var treeId = getTreeId();
identifierPrefix = ":" + identifierPrefix + "R" + treeId;
identifierPrefix = "\u00ab" + identifierPrefix + "R" + treeId;
treeId = localIdCounter++;
0 < treeId && (identifierPrefix += "H" + treeId.toString(32));
identifierPrefix += ":";
identifierPrefix += "\u00bb";
} else
(treeId = globalClientIdCounter++),
(identifierPrefix =
":" + identifierPrefix + "r" + treeId.toString(32) + ":");
"\u00ab" + identifierPrefix + "r" + treeId.toString(32) + "\u00bb");
return (hook.memoizedState = identifierPrefix);
},
useHostTransitionStatus: useHostTransitionStatus,
Expand Down Expand Up @@ -18425,14 +18425,14 @@ function getCrossOriginStringAs(as, input) {
}
var isomorphicReactPackageVersion$jscomp$inline_1854 = React.version;
if (
"19.1.0-www-classic-22e39ea7-20250225" !==
"19.1.0-www-classic-2e4db334-20250225" !==
isomorphicReactPackageVersion$jscomp$inline_1854
)
throw Error(
formatProdErrorMessage(
527,
isomorphicReactPackageVersion$jscomp$inline_1854,
"19.1.0-www-classic-22e39ea7-20250225"
"19.1.0-www-classic-2e4db334-20250225"
)
);
Internals.findDOMNode = function (componentOrElement) {
Expand All @@ -18450,10 +18450,10 @@ Internals.Events = [
];
var internals$jscomp$inline_2414 = {
bundleType: 0,
version: "19.1.0-www-classic-22e39ea7-20250225",
version: "19.1.0-www-classic-2e4db334-20250225",
rendererPackageName: "react-dom",
currentDispatcherRef: ReactSharedInternals,
reconcilerVersion: "19.1.0-www-classic-22e39ea7-20250225"
reconcilerVersion: "19.1.0-www-classic-2e4db334-20250225"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_2415 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down Expand Up @@ -18817,4 +18817,4 @@ exports.useFormState = function (action, initialState, permalink) {
exports.useFormStatus = function () {
return ReactSharedInternals.H.useHostTransitionStatus();
};
exports.version = "19.1.0-www-classic-22e39ea7-20250225";
exports.version = "19.1.0-www-classic-2e4db334-20250225";
Loading

0 comments on commit 5849887

Please sign in to comment.