remix
remix copied to clipboard
Uncaught DOMException when in an environment without access to sessionStorage
What version of Remix are you using?
1.6.3
Steps to Reproduce
-
Establish an environment where the application does not have access to sessionStorage, such as using a Remix app in a child iframe with a different origin from the parent while the user is using Chrome in Incognito mode with third party cookies blocked.
-
Visit any route within the Remix app and receive
Uncaught DOMException: Failed to read the 'sessionStorage' property from 'Window': Access is denied for this document.
Expected Behavior
I would expect the app to load, even without access to sessionStorage. Functionality provided by a component dependent on sessionStorage (ScrollRestoraion) may not function correctly, but the application should not throw an unhandled exception.
Placing access to sessionStorage inside a try/catch block appears to allow the application to continue to function. See
remix/packages/react/scroll-restoration.tsx
lines 11-14.
I attempted not using the ScrollRestoration component, but the exception still occurs.
Actual Behavior
Visiting any route in the above environment causes an Uncaught DOMException to be thrown and the application fails to render.
I'm getting this error as well.
I'm also receiving this error. It seems to only happen to me when using netlify dev. If I use the remix server it works fine. To reproduce:
- Run netlify dev
- Create a page with an iframe
- Refresh page
- Add in another iframe to the same page
- Refresh Page and you should see the sessionStorage is undefined error.
We're having the same issue at https://github.com/webstudio-is . This happens when a Remix website is in an iframe with a domain different from the main document, and "Block third-party cookies" is enabled at chrome://settings/cookies
.
Since Remix 1.10.0, the <ScrollRestoration /> component is the one from React Router.
Its implementation changed a bit, and the only calls to sessionStorage are within the component, removing the component like OP tried should work fine.
@machour is correct and this should no longer be an issue once you remove the component