Skip to content

Commit

Permalink
fix(gatsby-react-router-scroll): hide sessionStorage warnings in prod…
Browse files Browse the repository at this point in the history
…uction (#12593)

Hide sessionStorage warnings in production

## Description

Concerns the plugin `gatsby-react-router-scroll`.

If cookies are disabled, the production version of the website would show console warnings when scrolling.

With this change, those warnings will only be visible in the development version.

## Related Issues

Fixes #12577
  • Loading branch information
aengl authored and pieh committed Mar 15, 2019
1 parent 47eed4c commit 365be0a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
5 changes: 1 addition & 4 deletions packages/gatsby-react-router-scroll/.babelrc
@@ -1,6 +1,3 @@
{
"presets": [
["babel-preset-gatsby-package", { "browser": true }]
],
"plugins": ["dev-expression"]
"presets": [["babel-preset-gatsby-package", { "browser": true }]]
}
2 changes: 0 additions & 2 deletions packages/gatsby-react-router-scroll/.eslintrc.yaml
@@ -1,4 +1,2 @@
env:
browser: true
globals:
__DEV__: false
4 changes: 2 additions & 2 deletions packages/gatsby-react-router-scroll/src/ScrollContainer.js
Expand Up @@ -34,7 +34,7 @@ class ScrollContainer extends React.Component {

// Only keep around the current DOM node in development, as this is only
// for emitting the appropriate warning.
if (__DEV__) {
if (process.env.NODE_ENV !== `production`) {
this.domNode = ReactDOM.findDOMNode(this) // eslint-disable-line react/no-find-dom-node
}
}
Expand All @@ -44,7 +44,7 @@ class ScrollContainer extends React.Component {
prevProps.scrollKey === this.props.scrollKey,
`<ScrollContainer> does not support changing scrollKey.`
)
if (__DEV__) {
if (process.env.NODE_ENV !== `production`) {
const prevDomNode = this.domNode
this.domNode = ReactDOM.findDOMNode(this) // eslint-disable-line react/no-find-dom-node

Expand Down
16 changes: 10 additions & 6 deletions packages/gatsby-react-router-scroll/src/StateStorage.js
Expand Up @@ -9,9 +9,11 @@ export default class SessionStorage {
const value = window.sessionStorage.getItem(stateKey)
return JSON.parse(value)
} catch (e) {
console.warn(
`[gatsby-react-router-scroll] Unable to access sessionStorage; sessionStorage is not available.`
)
if (process.env.NODE_ENV !== `production`) {
console.warn(
`[gatsby-react-router-scroll] Unable to access sessionStorage; sessionStorage is not available.`
)
}

if (
window &&
Expand Down Expand Up @@ -39,9 +41,11 @@ export default class SessionStorage {
window[GATSBY_ROUTER_SCROLL_STATE][stateKey] = JSON.parse(storedValue)
}

console.warn(
`[gatsby-react-router-scroll] Unable to save state in sessionStorage; sessionStorage is not available.`
)
if (process.env.NODE_ENV !== `production`) {
console.warn(
`[gatsby-react-router-scroll] Unable to save state in sessionStorage; sessionStorage is not available.`
)
}
}
}

Expand Down

0 comments on commit 365be0a

Please sign in to comment.