Skip to content

[Bug]: ScrollRestoration incompatible with createBrowserRouter(..., { window }) #9656

Closed
@CGamesPlay

Description

@CGamesPlay

What version of React Router are you using?

6.4.3

Steps to Reproduce

The ScrollRestoration component relies explicitly on the ambient window and document objects, but a router can be configured with a custom window, which means that the ambient one is unsuitable.

Mount an <iframe src> where the src has the same Origin as the global window, then mount a <ScrollRestoration /> inside of this iframe (you can mount the entire app inside the iframe; it doesn't matter).

Expected Behavior

When the iframe navigates, the scroll within the iframe is restored.

Actual Behavior

The parent window has it's scroll saved/restored by the ScrollRestoration, despite the component being mounted in a different window.

Note that this code changed recently with #9573 however the new implementation still relies on the ambient document, so even specifying an ID inside of the iframe would not resolve the issue.

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