Skip to content

Commit 9a6b90c

Browse files
fix(compass-connections): fixes CPU hikes because of bad useEffect dependency (#5740)
1 parent 6f5c3de commit 9a6b90c

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/compass-connections/src/components/legacy-connections-modal.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,19 @@ const footerStyles = css({
4545

4646
const useLegacyModel = () => {
4747
const connectionStorage = useConnectionStorageContext();
48-
const getLegacyConnectionsImpl =
49-
connectionStorage.getLegacyConnections?.bind(connectionStorage);
50-
if (!getLegacyConnectionsImpl) {
48+
if (typeof connectionStorage.getLegacyConnections !== 'function') {
5149
throw new Error(
5250
'LegacyConnections migrations require provided ConnectionStorage to implement getLegacyConnections'
5351
);
5452
}
5553

54+
const getLegacyConnectionsImpl = useCallback(
55+
async (options?: { signal: AbortSignal | undefined }) => {
56+
return await connectionStorage.getLegacyConnections?.(options);
57+
},
58+
[connectionStorage]
59+
);
60+
5661
const [connections, setConnections] = useState<{ name: string }[]>([]);
5762

5863
const [isModalHiddenByUser, setIsModalHiddenByUser] = usePersistedState(
@@ -61,9 +66,11 @@ const useLegacyModel = () => {
6166
);
6267

6368
useEffect(() => {
64-
void getLegacyConnectionsImpl().then((connections) =>
65-
setConnections(connections)
66-
);
69+
void getLegacyConnectionsImpl().then((connections) => {
70+
if (connections) {
71+
setConnections(connections);
72+
}
73+
});
6774
}, [getLegacyConnectionsImpl]);
6875

6976
return {

0 commit comments

Comments
 (0)