diff --git a/frontend/src/contexts/broadcast-channel.context.tsx b/frontend/src/contexts/broadcast-channel.context.tsx index 97823e6b..3cdfdf8a 100644 --- a/frontend/src/contexts/broadcast-channel.context.tsx +++ b/frontend/src/contexts/broadcast-channel.context.tsx @@ -82,7 +82,7 @@ export const BroadcastChannelProvider: FC = ({ return; } - subscribersRef.current[payload.event]?.forEach((callback) => + subscribersRef.current[payload.event].forEach((callback) => callback(data), ); }; @@ -100,18 +100,18 @@ export const BroadcastChannelProvider: FC = ({ callback, ) => { subscribersRef.current[event] ??= []; - subscribersRef.current[event]?.push(callback); + subscribersRef.current[event].push(callback); return () => { - const index = subscribersRef.current[event]?.indexOf(callback) ?? -1; + const index = subscribersRef.current[event].indexOf(callback) ?? -1; if (index !== -1) { - subscribersRef.current[event]?.splice(index, 1); + subscribersRef.current[event].splice(index, 1); } }; }; const postMessage: IBroadcastChannelContext["postMessage"] = (payload) => { - channelRef.current?.postMessage({ + channelRef.current.postMessage({ tabId: tabUuid, payload, }); diff --git a/widget/src/providers/BroadcastChannelProvider.tsx b/widget/src/providers/BroadcastChannelProvider.tsx index f542943c..5206f643 100644 --- a/widget/src/providers/BroadcastChannelProvider.tsx +++ b/widget/src/providers/BroadcastChannelProvider.tsx @@ -82,7 +82,7 @@ export const BroadcastChannelProvider: FC = ({ return; } - subscribersRef.current[payload.event]?.forEach((callback) => + subscribersRef.current[payload.event].forEach((callback) => callback(data), ); }; @@ -102,18 +102,18 @@ export const BroadcastChannelProvider: FC = ({ callback, ) => { subscribersRef.current[event] ??= []; - subscribersRef.current[event]?.push(callback); + subscribersRef.current[event].push(callback); return () => { - const index = subscribersRef.current[event]?.indexOf(callback) ?? -1; + const index = subscribersRef.current[event].indexOf(callback) ?? -1; if (index !== -1) { - subscribersRef.current[event]?.splice(index, 1); + subscribersRef.current[event].splice(index, 1); } }; }; const postMessage: IBroadcastChannelContext["postMessage"] = (payload) => { - channelRef.current?.postMessage({ + channelRef.current.postMessage({ tabId: tabUuid, payload, });