Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with useBeforeUnload on iOS Safari #7

Closed
marhaupe opened this issue May 19, 2024 · 6 comments
Closed

Issues with useBeforeUnload on iOS Safari #7

marhaupe opened this issue May 19, 2024 · 6 comments
Labels

Comments

@marhaupe
Copy link

I've been noticing that ElementScrollRestoration does not work on iOS Safari, or at least not reliably. I could pinpoint the issue to useBeforeUnload not being triggered due to window.onbeforeunload not being supported. There have been similar reports for react-router-dom (remix-run/react-router#9463), which have been fixed by switching to listening to window.pagehide (remix-run/react-router#9945). Monkey patching or rather just forking ElementScrollRestoration and adding and using the usePageHide hook fixes these problems for me. If this is a known bug that does not only affect me for some reason, I'd be happy to help out with a pull request.

@kentcdodds
Copy link
Member

I'm fine with switching to a hook like that provided it works for other browsers still. Thanks!

@marhaupe
Copy link
Author

Knowing you're also involved in the react-router / remix projects, would you prefer to push for usePageHide being exported (it currently isn't: https://github.com/remix-run/react-router/blob/7759e8e2912eb69f6dd63b2906490831a2154cfd/packages/react-router-dom/index.tsx#L1919) or would you rather inline the hook?

@kentcdodds
Copy link
Member

We'll see what the team says! https://x.com/kentcdodds/status/1792931607537467871

@kentcdodds
Copy link
Member

Team's not keen on exposing that hook (for good reasons) so I just switched to a simple useEffect in a couple lines.

Copy link

🎉 This issue has been resolved in version 1.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@marhaupe
Copy link
Author

I see, I remember reading a PR comment but I guess the decision wasn't made public. Totally makes sense though, thanks for the quick fix! Appreciate your work a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants