elm-hot icon indicating copy to clipboard operation
elm-hot copied to clipboard

the location of the Browser.Navigation.Key in the model has changed

Open atomkirk opened this issue 4 years ago • 1 comments

I don't understand what this error means:

[elm-hot] Hot-swapping Main not possible: the location of the Browser.Navigation.Key in the model has changed.

would you mind helping me understand how to fix?

atomkirk avatar May 29 '21 16:05 atomkirk

I realise this might be late, but I just had this problem and decided to make my findings visible to anyone facing this issue later.

If you make sure not to copy your navKey to a different place in your model, this should work.

I had this in my top-level module:

type Model
    = Error String
    | Loading Url Nav.Key
    | Running Url Nav.Key App.Model

So when switching between Loading & Running states, I needed to copy the navKey from one place to another. For some reason this stops elm-hot from being able to apply changes.

To fix this, you can make sure the navKey is stored in one place and never changes:

In my example above, this is how this could be achieved:

type alias Model =
    { navKey : Nav.Key
    , url : Url
    , state : State
    }

type State
    = Error String
    | Loading
    | Running App.Model

I hope this helps.

mkaszas avatar Jul 01 '21 12:07 mkaszas