elm / browser

Create Elm programs that run in browsers!
https://package.elm-lang.org/packages/elm/browser/latest/
BSD 3-Clause "New" or "Revised" License
312 stars 64 forks source link

Navigation.back generates two `UrlChange` events #102

Open glasserc opened 4 years ago

glasserc commented 4 years ago

STR:

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.

AdrianoFerrari commented 4 years ago

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.

glasserc commented 4 years ago

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.