Skip to content

Commit 721d6f4

Browse files
authored
Merge pull request #401 from unlayer/fix/window-undefined
Fix window is not defined on server rendered apps
2 parents 835a7a4 + 4de0883 commit 721d6f4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/EmailEditor.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import pkg from '../package.json';
99
import { Editor, EditorRef, EmailEditorProps } from './types';
1010
import { loadScript } from './loadScript';
1111

12-
window.__unlayer_lastEditorId = window.__unlayer_lastEditorId || 0;
12+
const win = typeof window === 'undefined' ? { __unlayer_lastEditorId: 0 } : window
13+
win.__unlayer_lastEditorId = win.__unlayer_lastEditorId || 0;
1314

1415
export const EmailEditor = React.forwardRef<EditorRef, EmailEditorProps>(
1516
(props, ref) => {
@@ -20,7 +21,7 @@ export const EmailEditor = React.forwardRef<EditorRef, EmailEditorProps>(
2021
const [hasLoadedEmbedScript, setHasLoadedEmbedScript] = useState(false);
2122

2223
const editorId = useMemo(
23-
() => props.editorId || `editor-${++window.__unlayer_lastEditorId}`,
24+
() => props.editorId || `editor-${++win.__unlayer_lastEditorId}`,
2425
[props.editorId]
2526
);
2627

0 commit comments

Comments
 (0)