Skip to content

Commit 40a5e9b

Browse files
committed
fix(pusher-web): remove effect cleanup that caused unnecessary resubscriptions on each render
1 parent b9e8c22 commit 40a5e9b

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

packages/pluggableWidgets/pusher-web/src/hooks/usePusherSubscribe.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ export function usePusherSubscribe(subscription?: SubscriptionConfig): void {
1212

1313
useEffect(() => {
1414
const controller = new AbortController();
15-
let instance: PusherListener | null = null;
15+
let listenerInstance: PusherListener | null = null;
1616

1717
createPusherListener(controller.signal).then(result => {
1818
if (controller.signal.aborted) {
1919
result?.destroy();
2020
return;
2121
}
22-
instance = result;
23-
setListener(result);
22+
listenerInstance = result;
23+
24+
setListener(listenerInstance);
2425
});
2526

2627
return () => {
2728
controller.abort();
28-
instance?.destroy();
29+
listenerInstance?.destroy();
2930
setListener(null);
3031
};
3132
}, []);
@@ -34,14 +35,11 @@ export function usePusherSubscribe(subscription?: SubscriptionConfig): void {
3435
if (!listener) {
3536
return;
3637
}
38+
3739
if (!subscription) {
3840
listener.unsubscribe();
39-
return;
41+
} else {
42+
listener.subscribe(subscription);
4043
}
41-
42-
listener.subscribe(subscription);
43-
return () => {
44-
listener.unsubscribe();
45-
};
4644
}, [listener, subscription]);
4745
}

0 commit comments

Comments
 (0)