Skip to content

Commit

Permalink
Fix for gatsby when "window" is not available during server side rend…
Browse files Browse the repository at this point in the history
…ering.
  • Loading branch information
William Diaz committed Feb 8, 2020
1 parent 310bb1d commit 6ba2f8d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Engine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class Engine extends React.Component<EngineProps, EngineState> {
console.log('context loss observable from Engine: ', eventData);
})

window.addEventListener('resize', this.onResizeWindow)
if(typeof window !== 'undefined') {
window.addEventListener('resize', this.onResizeWindow)
}

this.setState({canRender: true});
}
Expand All @@ -119,7 +121,9 @@ class Engine extends React.Component<EngineProps, EngineState> {
}

componentWillUnmount () {
window.removeEventListener('resize', this.onResizeWindow);
if(typeof window !== 'undefined') {
window.removeEventListener('resize', this.onResizeWindow);
}
}

render () {
Expand Down

0 comments on commit 6ba2f8d

Please sign in to comment.