Skip to content

Commit 5400523

Browse files
woobottleclaude
andcommitted
fix(Dialog): replace useId with React 17-compatible id counter
The library's peer range is react >=17 but useId is React 18+. The dialog surface renders only behind the client-only mounted gate, so a per-instance counter id is safe (no SSR output to hydrate-mismatch). Also restore alphabetical ordering of the Dialog export in the components barrel. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0d40d09 commit 5400523

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/components/Dialog/Dialog.web.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import React, {
99
useContext,
1010
useEffect,
11-
useId,
1211
useMemo,
1312
useRef,
1413
useState,
@@ -30,6 +29,11 @@ import {cssifyWebStyles} from '../../core/utils/cssifyWebStyles';
3029

3130
const dialogStyles = getDialogStyles();
3231

32+
// Per-instance id source. `useId` would be cleaner but is React 18+, while the
33+
// library's peer range is `react >=17`. The dialog surface only renders behind
34+
// the client-only `mounted` gate, so there is no SSR output to mismatch on.
35+
let dialogIdCounter = 0;
36+
3337
function DialogBase({
3438
open,
3539
onClose,
@@ -41,8 +45,13 @@ function DialogBase({
4145
style,
4246
testID,
4347
}: DialogWebProps) {
44-
const titleId = useId();
45-
const descriptionId = useId();
48+
const [{titleId, descriptionId}] = useState(() => {
49+
dialogIdCounter += 1;
50+
return {
51+
titleId: `wb-dialog-title-${dialogIdCounter}`,
52+
descriptionId: `wb-dialog-desc-${dialogIdCounter}`,
53+
};
54+
});
4655

4756
const [hasTitle, setHasTitle] = useState(false);
4857
const [hasDescription, setHasDescription] = useState(false);

src/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export * from './Badge';
33
export * from './Box';
44
export * from './Button';
55
export * from './Card';
6-
export * from './Dialog';
76
export * from './Chip';
7+
export * from './Dialog';
88
export * from './Divider';
99
export * from './Eyebrow';
1010
export * from './Fab';

0 commit comments

Comments
 (0)