T
TanStack6mo ago
other-emerald

How could the beforeunload event best be handled when a blockenFn is supplied?

I stumbled upon https://github.com/TanStack/router/issues/3761 and I commented what I found out about this issue and it seems to not be a straight forward as it initially seems. Is Discord maybe the better place to discuss how this should be handled?
GitHub
Navigation always blocked with enableBeforeUnload true, even if ret...
Which project does this relate to? Router Describe the bug if enableBeforeUnload is set to true for a blocker it's always blocking browser navigation. Tested in Chrome Your Example Website or A...
6 Replies
national-gold
national-gold6mo ago
I think we cannot have beforeUnload be conditionally applied it needs to be registered at the browser regardless of any dynamic criteria
other-emerald
other-emeraldOP6mo ago
What do you mean by that? Isn't the current implementation already calling preventdefault only conditionally?
national-gold
national-gold6mo ago
I vaguely remember this but maybe I am incorrect here
other-emerald
other-emeraldOP6mo ago
At least currently reactively toggling enableBeforeUnload does indeed not seem to work But I don't think it should be generally impossible to only conditionally block beforeUnload as I've seen that get done with a diy approach before
national-gold
national-gold6mo ago
well then experiment some more in router and report back if it can be fixed please
other-emerald
other-emeraldOP6mo ago
Will do

Did you find this page helpful?