Skip to content

Commit 9eede0c

Browse files
committed
fix build and react 19
1 parent fd709a2 commit 9eede0c

File tree

4 files changed

+68
-70
lines changed

4 files changed

+68
-70
lines changed

packages/@react-aria/autocomplete/src/useAutocomplete.ts

+28-22
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,39 @@ export function useAutocomplete(props: AriaAutocompleteOptions, state: Autocompl
6464
let collectionId = useId();
6565
let timeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
6666
let delayNextActiveDescendant = useRef(false);
67-
let callbackRef = useEffectEvent((collectionNode) => {
68-
// When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
69-
// of the letter you just typed. If we recieve another UPDATE_ACTIVEDESCENDANT call then we clear the queued update
70-
let updateActiveDescendant = (e) => {
71-
let {detail} = e;
72-
clearTimeout(timeout.current);
73-
e.stopPropagation();
74-
75-
if (detail?.id != null) {
76-
if (delayNextActiveDescendant.current) {
77-
timeout.current = setTimeout(() => {
78-
state.setFocusedNodeId(detail.id);
79-
}, 500);
80-
} else {
67+
let lastCollectionNode = useRef<HTMLElement>(null);
68+
69+
let updateActiveDescendant = useCallback((e) => {
70+
let {detail} = e;
71+
clearTimeout(timeout.current);
72+
e.stopPropagation();
73+
if (detail?.id != null) {
74+
if (delayNextActiveDescendant.current) {
75+
timeout.current = setTimeout(() => {
8176
state.setFocusedNodeId(detail.id);
82-
}
77+
}, 500);
8378
} else {
84-
state.setFocusedNodeId(null);
79+
state.setFocusedNodeId(detail.id);
8580
}
81+
} else {
82+
state.setFocusedNodeId(null);
83+
}
8684

87-
delayNextActiveDescendant.current = false;
88-
};
89-
90-
collectionNode?.addEventListener(UPDATE_ACTIVEDESCENDANT, updateActiveDescendant);
85+
delayNextActiveDescendant.current = false;
86+
}, [state]);
9187

92-
// TODO: ideally would clean up the event listeners but since this is callback ref it will return null for collectionNode
93-
// on cleanup and the collectionRef will also be null at that point...
88+
let callbackRef = useEffectEvent((collectionNode: HTMLElement | null) => {
89+
// When typing forward, we want to delay the setting of active descendant to not interrupt the native screen reader announcement
90+
// of the letter you just typed. If we recieve another UPDATE_ACTIVEDESCENDANT call then we clear the queued update
91+
// We track lastCollectionNode to do proper cleanup since callbackRefs just pass null when unmounting. This also handles
92+
// React 19's extra call of the callback ref in strict mode
93+
if (collectionNode != null) {
94+
lastCollectionNode.current?.removeEventListener(UPDATE_ACTIVEDESCENDANT, updateActiveDescendant);
95+
lastCollectionNode.current = collectionNode;
96+
collectionNode.addEventListener(UPDATE_ACTIVEDESCENDANT, updateActiveDescendant);
97+
} else {
98+
lastCollectionNode.current?.removeEventListener(UPDATE_ACTIVEDESCENDANT, updateActiveDescendant);
99+
}
94100
});
95101
// Make sure to memo so that React doesn't keep registering a new event listeners on every rerender of the wrapped collection,
96102
// especially since callback refs's node parameter is null when they cleanup so we can't even clean up properly

packages/dev/docs/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
"highlight.js": "9.18.1",
3232
"markdown-to-jsx": "^6.11.0",
3333
"quicklink": "^2.3.0",
34-
"react": "^18.2.0",
35-
"react-dom": "^18.2.0",
34+
"react": "19.0.0-rc-91061073-20241121",
35+
"react-dom": "19.0.0-rc-91061073-20241121",
3636
"react-lowlight": "^2.0.0"
3737
},
3838
"alias": {

packages/react-aria-components/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"dependencies": {
4040
"@internationalized/date": "^3.6.0",
4141
"@internationalized/string": "^3.2.5",
42-
"@react-aria/autocomplete": "3.0.0-alpha.35",
42+
"@react-aria/autocomplete": "3.0.0-alpha.36",
4343
"@react-aria/collections": "3.0.0-alpha.6",
4444
"@react-aria/color": "^3.0.2",
4545
"@react-aria/disclosure": "^3.0.0",

yarn.lock

+37-45
Original file line numberDiff line numberDiff line change
@@ -5859,26 +5859,6 @@ __metadata:
58595859
languageName: unknown
58605860
linkType: soft
58615861

5862-
"@react-aria/autocomplete@npm:3.0.0-alpha.35":
5863-
version: 3.0.0-alpha.35
5864-
resolution: "@react-aria/autocomplete@npm:3.0.0-alpha.35"
5865-
dependencies:
5866-
"@react-aria/combobox": "npm:^3.10.5"
5867-
"@react-aria/listbox": "npm:^3.13.5"
5868-
"@react-aria/searchfield": "npm:^3.7.10"
5869-
"@react-aria/utils": "npm:^3.25.3"
5870-
"@react-stately/combobox": "npm:^3.10.0"
5871-
"@react-types/autocomplete": "npm:3.0.0-alpha.26"
5872-
"@react-types/button": "npm:^3.10.0"
5873-
"@react-types/shared": "npm:^3.25.0"
5874-
"@swc/helpers": "npm:^0.5.0"
5875-
peerDependencies:
5876-
react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0
5877-
react-dom: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0
5878-
checksum: 10c0/7dcbc8648b5c29afb58c982340951cb660e6c3556f22afcb06ccb9e0c4a33de7a1b2a4cea8899ee9024b45ded8c7325c40050537cef54f7cc324fa35782e6c28
5879-
languageName: node
5880-
linkType: hard
5881-
58825862
"@react-aria/autocomplete@npm:3.0.0-alpha.36, @react-aria/autocomplete@workspace:packages/@react-aria/autocomplete":
58835863
version: 0.0.0-use.local
58845864
resolution: "@react-aria/autocomplete@workspace:packages/@react-aria/autocomplete"
@@ -6010,7 +5990,7 @@ __metadata:
60105990
languageName: unknown
60115991
linkType: soft
60125992

6013-
"@react-aria/combobox@npm:^3.10.5, @react-aria/combobox@npm:^3.11.0, @react-aria/combobox@workspace:packages/@react-aria/combobox":
5993+
"@react-aria/combobox@npm:^3.11.0, @react-aria/combobox@workspace:packages/@react-aria/combobox":
60145994
version: 0.0.0-use.local
60155995
resolution: "@react-aria/combobox@workspace:packages/@react-aria/combobox"
60165996
dependencies:
@@ -6262,7 +6242,7 @@ __metadata:
62626242
languageName: unknown
62636243
linkType: soft
62646244

6265-
"@react-aria/listbox@npm:^3.13.5, @react-aria/listbox@npm:^3.13.6, @react-aria/listbox@workspace:packages/@react-aria/listbox":
6245+
"@react-aria/listbox@npm:^3.13.6, @react-aria/listbox@workspace:packages/@react-aria/listbox":
62666246
version: 0.0.0-use.local
62676247
resolution: "@react-aria/listbox@workspace:packages/@react-aria/listbox"
62686248
dependencies:
@@ -6418,7 +6398,7 @@ __metadata:
64186398
languageName: unknown
64196399
linkType: soft
64206400

6421-
"@react-aria/searchfield@npm:^3.7.10, @react-aria/searchfield@npm:^3.7.11, @react-aria/searchfield@workspace:packages/@react-aria/searchfield":
6401+
"@react-aria/searchfield@npm:^3.7.11, @react-aria/searchfield@workspace:packages/@react-aria/searchfield":
64226402
version: 0.0.0-use.local
64236403
resolution: "@react-aria/searchfield@workspace:packages/@react-aria/searchfield"
64246404
dependencies:
@@ -6751,7 +6731,7 @@ __metadata:
67516731
languageName: unknown
67526732
linkType: soft
67536733

6754-
"@react-aria/utils@npm:^3.14.2, @react-aria/utils@npm:^3.25.3, @react-aria/utils@npm:^3.26.0, @react-aria/utils@npm:^3.8.0, @react-aria/utils@workspace:packages/@react-aria/utils":
6734+
"@react-aria/utils@npm:^3.14.2, @react-aria/utils@npm:^3.26.0, @react-aria/utils@npm:^3.8.0, @react-aria/utils@workspace:packages/@react-aria/utils":
67556735
version: 0.0.0-use.local
67566736
resolution: "@react-aria/utils@workspace:packages/@react-aria/utils"
67576737
dependencies:
@@ -7334,8 +7314,8 @@ __metadata:
73347314
highlight.js: "npm:9.18.1"
73357315
markdown-to-jsx: "npm:^6.11.0"
73367316
quicklink: "npm:^2.3.0"
7337-
react: "npm:^18.2.0"
7338-
react-dom: "npm:^18.2.0"
7317+
react: "npm:19.0.0-rc-91061073-20241121"
7318+
react-dom: "npm:19.0.0-rc-91061073-20241121"
73397319
react-lowlight: "npm:^2.0.0"
73407320
languageName: unknown
73417321
linkType: soft
@@ -8411,7 +8391,7 @@ __metadata:
84118391
languageName: unknown
84128392
linkType: soft
84138393

8414-
"@react-stately/combobox@npm:^3.10.0, @react-stately/combobox@npm:^3.10.1, @react-stately/combobox@workspace:packages/@react-stately/combobox":
8394+
"@react-stately/combobox@npm:^3.10.1, @react-stately/combobox@workspace:packages/@react-stately/combobox":
84158395
version: 0.0.0-use.local
84168396
resolution: "@react-stately/combobox@workspace:packages/@react-stately/combobox"
84178397
dependencies:
@@ -8797,19 +8777,6 @@ __metadata:
87978777
languageName: unknown
87988778
linkType: soft
87998779

8800-
"@react-types/autocomplete@npm:3.0.0-alpha.26":
8801-
version: 3.0.0-alpha.26
8802-
resolution: "@react-types/autocomplete@npm:3.0.0-alpha.26"
8803-
dependencies:
8804-
"@react-types/combobox": "npm:^3.13.0"
8805-
"@react-types/searchfield": "npm:^3.5.9"
8806-
"@react-types/shared": "npm:^3.25.0"
8807-
peerDependencies:
8808-
react: ^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0
8809-
checksum: 10c0/750c88653720a5207a07c76ec829c83f58d44ad71ccddcd953983db5cb8e3db491507959a2f608ffc3d4be49ea7dc610d91c7909a088910d3316b6223d0cd442
8810-
languageName: node
8811-
linkType: hard
8812-
88138780
"@react-types/autocomplete@npm:3.0.0-alpha.27, @react-types/autocomplete@workspace:packages/@react-types/autocomplete":
88148781
version: 0.0.0-use.local
88158782
resolution: "@react-types/autocomplete@workspace:packages/@react-types/autocomplete"
@@ -8853,7 +8820,7 @@ __metadata:
88538820
languageName: unknown
88548821
linkType: soft
88558822

8856-
"@react-types/button@npm:^3.10.0, @react-types/button@npm:^3.10.1, @react-types/button@workspace:packages/@react-types/button":
8823+
"@react-types/button@npm:^3.10.1, @react-types/button@workspace:packages/@react-types/button":
88578824
version: 0.0.0-use.local
88588825
resolution: "@react-types/button@workspace:packages/@react-types/button"
88598826
dependencies:
@@ -8917,7 +8884,7 @@ __metadata:
89178884
languageName: unknown
89188885
linkType: soft
89198886

8920-
"@react-types/combobox@npm:^3.13.0, @react-types/combobox@npm:^3.13.1, @react-types/combobox@workspace:packages/@react-types/combobox":
8887+
"@react-types/combobox@npm:^3.13.1, @react-types/combobox@workspace:packages/@react-types/combobox":
89218888
version: 0.0.0-use.local
89228889
resolution: "@react-types/combobox@workspace:packages/@react-types/combobox"
89238890
dependencies:
@@ -9136,7 +9103,7 @@ __metadata:
91369103
languageName: unknown
91379104
linkType: soft
91389105

9139-
"@react-types/searchfield@npm:^3.5.10, @react-types/searchfield@npm:^3.5.9, @react-types/searchfield@workspace:packages/@react-types/searchfield":
9106+
"@react-types/searchfield@npm:^3.5.10, @react-types/searchfield@workspace:packages/@react-types/searchfield":
91409107
version: 0.0.0-use.local
91419108
resolution: "@react-types/searchfield@workspace:packages/@react-types/searchfield"
91429109
dependencies:
@@ -9167,7 +9134,7 @@ __metadata:
91679134
languageName: unknown
91689135
linkType: soft
91699136

9170-
"@react-types/shared@npm:^3.1.0, @react-types/shared@npm:^3.16.0, @react-types/shared@npm:^3.25.0, @react-types/shared@npm:^3.26.0, @react-types/shared@workspace:packages/@react-types/shared":
9137+
"@react-types/shared@npm:^3.1.0, @react-types/shared@npm:^3.16.0, @react-types/shared@npm:^3.26.0, @react-types/shared@workspace:packages/@react-types/shared":
91719138
version: 0.0.0-use.local
91729139
resolution: "@react-types/shared@workspace:packages/@react-types/shared"
91739140
peerDependencies:
@@ -29148,7 +29115,7 @@ __metadata:
2914829115
dependencies:
2914929116
"@internationalized/date": "npm:^3.6.0"
2915029117
"@internationalized/string": "npm:^3.2.5"
29151-
"@react-aria/autocomplete": "npm:3.0.0-alpha.35"
29118+
"@react-aria/autocomplete": "npm:3.0.0-alpha.36"
2915229119
"@react-aria/collections": "npm:3.0.0-alpha.6"
2915329120
"@react-aria/color": "npm:^3.0.2"
2915429121
"@react-aria/disclosure": "npm:^3.0.0"
@@ -29294,6 +29261,17 @@ __metadata:
2929429261
languageName: node
2929529262
linkType: hard
2929629263

29264+
"react-dom@npm:19.0.0-rc-91061073-20241121":
29265+
version: 19.0.0-rc-91061073-20241121
29266+
resolution: "react-dom@npm:19.0.0-rc-91061073-20241121"
29267+
dependencies:
29268+
scheduler: "npm:0.25.0-rc-91061073-20241121"
29269+
peerDependencies:
29270+
react: 19.0.0-rc-91061073-20241121
29271+
checksum: 10c0/a358b5e906b02850c9655b8fc3fffca2edd6f86dd903b31a15f3a3d708296ad77911f14b370c592dba5992a9cf6775682d515fbf30552f8e45b296e56ff797ed
29272+
languageName: node
29273+
linkType: hard
29274+
2929729275
"react-dom@npm:^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0, react-dom@npm:^18.0.0 || ^19.0.0, react-dom@npm:^18.2.0":
2929829276
version: 18.3.1
2929929277
resolution: "react-dom@npm:18.3.1"
@@ -29667,6 +29645,13 @@ __metadata:
2966729645
languageName: node
2966829646
linkType: hard
2966929647

29648+
"react@npm:19.0.0-rc-91061073-20241121":
29649+
version: 19.0.0-rc-91061073-20241121
29650+
resolution: "react@npm:19.0.0-rc-91061073-20241121"
29651+
checksum: 10c0/eae0dddc092a91a89f9d975eaf4211af123f3aafac99200da66b082efec0020ed57ad35e31140823faacdcdd1e27322708e7601da5baf8ab16e3206ff3afe642
29652+
languageName: node
29653+
linkType: hard
29654+
2967029655
"react@npm:^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0, react@npm:^18.0.0 || ^19.0.0, react@npm:^18.2.0":
2967129656
version: 18.3.1
2967229657
resolution: "react@npm:18.3.1"
@@ -30828,6 +30813,13 @@ __metadata:
3082830813
languageName: node
3082930814
linkType: hard
3083030815

30816+
"scheduler@npm:0.25.0-rc-91061073-20241121":
30817+
version: 0.25.0-rc-91061073-20241121
30818+
resolution: "scheduler@npm:0.25.0-rc-91061073-20241121"
30819+
checksum: 10c0/f1ade45be0d76c92810c0ecb464c31781e78629085e9648c750b8d300e9a50c062960cc7e35006193d26add679942d54707b3dc24d674f505a488c1dce71d792
30820+
languageName: node
30821+
linkType: hard
30822+
3083130823
"scheduler@npm:^0.23.2":
3083230824
version: 0.23.2
3083330825
resolution: "scheduler@npm:0.23.2"

0 commit comments

Comments
 (0)