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

returnValue should be set to a truthy value

Open mgol opened this issue 1 year ago • 1 comments

The Chrome fallback at https://github.com/jacobbuck/react-beforeunload/blob/a271f7a01f9fd5309d9f859f5e805c9c3c8ba28c/src/useBeforeunload.js#L34 sets event.returnValue to an empty string. However, the confirmation dialog should only be shown when the value is truthy despite Chrome not following this part of the API: https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event

While Chrome 119 and newer respects event.preventDefault() in beforeunload handlers, it'd be good to avoid using the API in an incorrect way and just set the value to a truthy one, e.g. 'true'.

mgol avatar Mar 22 '24 11:03 mgol

Good to know Blink/Chrome has fixed their implementation. I'll remove the fallback in a future version now that it's no longer needed.

aliebuck avatar May 31 '24 03:05 aliebuck