Skip to content

[Bug]: ScrollRestoration errors if sessionStorage is blocked #10842

@david-bezero

Description

@david-bezero

What version of React Router are you using?

6.3.0 (but also still present in later versions)

Steps to Reproduce

Open any react-router-dom page which includes <ScrollRestoration /> in a browser which has blocked access to sessionStorage (e.g. running inside a sandboxed cross-origin iframe, or more easy to reproduce: block all cookies in Chrome)

Block all cookies

Expected Behavior

This setItem call should be wrapped in a try/catch so that permissions issues do not reach the console.

Clearly the functionality won't work in this situation, but it should fail gracefully, rather than printing an error to the console.

Actual Behavior

Error in console:

Failed to read the 'sessionStorage' property from 'Window': Access is denied for this document. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions