gatsbyjs/gatsby · error

[gatsby-react-router-scroll] Unable to save state in session

Error message

[gatsby-react-router-scroll] Unable to save state in sessionStorage; sessionStorage is not available.

What it means

Browser warning from gatsby-react-router-scroll: sessionStorage.setItem threw, so scroll state is saved to an in-memory window object instead and will not survive reloads; printed only outside production.

Source

Thrown at packages/gatsby-react-router-scroll/src/session-storage.ts:46

    }
  }

  save(location: Path, key: string, value: number): void {
    const stateKey = this.getStateKey(location, key)
    const storedValue = JSON.stringify(value)

    try {
      window.sessionStorage.setItem(stateKey, storedValue)
    } catch (e) {
      if (window && window[GATSBY_ROUTER_SCROLL_STATE]) {
        window[GATSBY_ROUTER_SCROLL_STATE][stateKey] = JSON.parse(storedValue)
      } else {
        window[GATSBY_ROUTER_SCROLL_STATE] = {}
        window[GATSBY_ROUTER_SCROLL_STATE][stateKey] = JSON.parse(storedValue)
      }

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

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

View on GitHub (pinned to e85d62f177)

Solutions

  1. Allow site data/storage in browser settings so scroll state persists
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at packages/gatsby-react-router-scroll/src/session-storage.ts:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gatsbyjs/gatsby@e85d62f177 (2026-08-26). Data as JSON: /api/errors/ac443a50483ec4a8. Report an issue: GitHub.