Skip to content

Commit

Permalink
fix: add null check to message.data (#29)
Browse files Browse the repository at this point in the history
There is a case where I see a `MessageEvent` with an origin, source, and
null data. In this case the origin is not a target origin, but the code
errors out on the null data first before it can throw a "Unrecognized
origin" error.
  • Loading branch information
asanehisa authored Aug 27, 2024
1 parent 209a6b8 commit 36505bb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/internal/hooks/useMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const useListenAndRespondMessage = (
const onWatchEventHandler = useCallback(
({ origin, source, data }: MessageEvent) => {
// Ignore React Dev Tools messages
if (data.source?.startsWith("react-devtools")) {
if (data?.source?.startsWith("react-devtools")) {
return;
}
if (!targetOrigins.includes(origin)) {
Expand Down

0 comments on commit 36505bb

Please sign in to comment.