react-router icon indicating copy to clipboard operation
react-router copied to clipboard

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

Open CGamesPlay opened this issue 3 years ago • 0 comments

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.

CGamesPlay avatar Nov 30 '22 09:11 CGamesPlay