browser
browser copied to clipboard
Navigation.back generates two `UrlChange` events
STR:
- Clone https://github.com/glasserc/elm-navigation-back
-
npm run debug
- Navigate to http://localhost:8080/
- Open up the Elm debugging console and/or the browser debugging console
- Click on some links:
/home
,/profile
,/reviews/the-century-of-the-self
- Click on the "back" button
Expected behavior:
A single UrlChanged message should appear with /profile
as the URL
Actual behavior:
Two UrlChanged messages are produced: first /reviews/the-century-of-the-self
and then /profile
I guess this is because of this call to key()
: https://github.com/elm/browser/blob/1d28cd625b3ce07be6dfad51660bea6de2c905f2/src/Elm/Kernel/Browser.js#L192-L195
Because the history API is asynchronous, the immediate call to key()
will just send a message for the current page URL.
I tried to reproduce using your repo (to see if my current bug is related), but I wasn't able to. Both the browser back button, and the one you included in the view, work correctly for me (Chrome v 81).
Can someone else try to reproduce? That way, we can know if it's still an issue, or if this can be closed.
I was just able to reproduce this issue on Chrome 84 as well as Firefox nightly (82.0a1 (2020-08-31)). Since the underlying code hasn't changed, I don't see any reason why this issue would no longer be present.
To make it easier to visualize the events and verify that the issue still exists, I added code to the reproduction case that keeps a history of all UrlChanged messages and displays them.