Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 Guard the use of window object during Gatsby build
Used advice in this issue: gatsbyjs/gatsby#309
- Loading branch information
Showing
5 changed files
with
28 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Loadable from "@loadable/component" | ||
export const loadableSketch = Loadable(() => import('react-p5')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import localStorageMemory from 'localstorage-memory' | ||
import { getDefault } from './defaults' | ||
|
||
export const get = key => localStorage.getItem(key) || getDefault(key) || '' | ||
export const set = (key, value) => localStorage.setItem(key, value) | ||
// Used to handle lack of window object in Gatsby build | ||
const windowGlobal = typeof window !== 'undefined' && window | ||
const storage = windowGlobal ? | ||
windowGlobal.localStorage : | ||
localStorageMemory | ||
; | ||
export const get = key => storage.getItem(key) || getDefault(key) || '' | ||
export const set = (key, value) => storage.setItem(key, value) |