elm / virtual-dom

The foundation of HTML and SVG in Elm.
https://package.elm-lang.org/packages/elm/virtual-dom/latest
BSD 3-Clause "New" or "Revised" License
209 stars 80 forks source link

Browser.Navigation.pushUrl to come after DOM update #153

Open dbdbdb opened 5 years ago

dbdbdb commented 5 years ago

In a single page application when a link is clicked you get a call to

onUrlChange : Url -> msg

and the message is sent to

update : msg -> model -> ( model, Cmd msg )

In the update you typically return a Browser.Navigation.pushUrl command.

If you have a filled in password input field on the page then the pushUrl command (when executed) triggers a save password dialog in the browser. I only want the browser to save the password when the user submit the password, not when he/she clicks a link to leave the page that has the password on it.

One need to clear the password in the DOM before the Browser.Navigation.pushUrl command is executed. Returning a new model with the password being an empty string does not work since the pushUrl command is executed before the model is rendered into the dom.

I've solved it by using a port and doing all the history manipulation there. It's however fairly complicated even then to get the ordering of DOM updates and history updates in sync.

This is similar to the cases in issue #108, but not exactly the same.