Skip to content

Commit

Permalink
correct key behavior (gatsbyjs#3483)
Browse files Browse the repository at this point in the history
* correct key behavior

* remove trailing slash logic

* remove adding new variable
  • Loading branch information
calcsam authored and jastack committed Jan 24, 2018
1 parent f95f249 commit 3fbba4e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/gatsby-react-router-scroll/src/StateStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class SessionStorage {
const stateKey = this.getStateKey(location, key)

try {
const value = sessionStorage.getItem(stateKey)
const value = window.sessionStorage.getItem(stateKey)
return JSON.parse(value)
} catch (e) {
console.warn(
Expand All @@ -30,7 +30,7 @@ export default class SessionStorage {
const storedValue = JSON.stringify(value)

try {
sessionStorage.setItem(stateKey, storedValue)
window.sessionStorage.setItem(stateKey, storedValue)
} catch (e) {
if (window && window[GATSBY_ROUTER_SCROLL_STATE]) {
window[GATSBY_ROUTER_SCROLL_STATE][stateKey] = JSON.parse(storedValue)
Expand All @@ -46,8 +46,7 @@ export default class SessionStorage {
}

getStateKey(location, key) {
const locationKey = location.key
const stateKeyBase = `${STATE_KEY_PREFIX}${locationKey}`
const stateKeyBase = `${STATE_KEY_PREFIX}${location.pathname}`
return key === null || typeof key === `undefined`
? stateKeyBase
: `${stateKeyBase}|${key}`
Expand Down

0 comments on commit 3fbba4e

Please sign in to comment.