Skip to content

Commit d279738

Browse files
authored
add a wrapper to make window safe for SSR (#1246)
1 parent 36815e3 commit d279738

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/spectacle/src/hooks/use-broadcast-channel.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { BroadcastChannel as BroadcastChannelPolyfill } from 'broadcast-channel'
44
import { DeckView } from './use-deck-state';
55

66
const noop = () => {};
7-
const BroadcastChannel = window.BroadcastChannel || BroadcastChannelPolyfill;
7+
let safeWindow: any = {};
8+
if (typeof window !== "undefined") {
9+
safeWindow = window;
10+
}
11+
const BroadcastChannel = safeWindow.BroadcastChannel || BroadcastChannelPolyfill;
812

913
type MessageCallback = (message: MessageTypes) => void;
1014

0 commit comments

Comments
 (0)