-
Notifications
You must be signed in to change notification settings - Fork 667
Closed
Description
This is a problem with elm 0.19.0.
SSCCE
import Browser
import Html exposing (Html)
import Task
import Time exposing (Posix, Zone)
type Model
= Loading
| HasZone Zone
type Msg
= NewZone Zone
| Tick Posix
main =
Browser.element
{ init = init
, update = update
, subscriptions = subscriptions
, view = view
}
init : () -> ( Model, Cmd Msg )
init _ =
( Loading, Task.perform NewZone Time.here )
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case Debug.log "update in response to" msg of
NewZone zone ->
( HasZone zone, Cmd.none )
Tick _ ->
( model, Cmd.none )
subscriptions : Model -> Sub Msg
subscriptions model =
case Debug.log "subscriptions for" model of
Loading ->
Sub.none
HasZone _ ->
Time.every 1000 Tick
view : Model -> Html Msg
view model =
Debug.log "view for" model
|> always (Html.text "Nothing to see here, please look at the console.")
Ellie by @adeschamps showing the same problem: https://ellie-app.com/38yPbFdvv6qa1
Expected behaviour
In the browser's console the messages from Debug.log
should appear in this order:
- view for Loading
- subscriptions for Loading
- update in response to NewZone
- subscriptions for HasZone
- view for HasZone
- update for Tick
- subscriptions for Tick
- view for Tick
with the last three steps repeated every second.
Actual behaviour
In the browser's console the following messages appear:
- view for Loading
- subscriptions for Loading
- update in response to NewZone
- subscriptions for HasZone
- view for HasZone
Analysis
- Core problem: older subscriptions overwrite newer subscriptions.
- Happens if: the command returned from the
init
function alters the model in such a way that the subscriptions change. - Guess on the problem location:
_Platform_dispatchEffects
. In thefor-in
loop is no ordering between subscriptions and commands.
More detailed breakdown
Expected
- Call to
init
getting the first model - Setting subscriptions based on the first model
- Executing the command returned from
init
- Call to
update
getting a new model - Setting subscriptions based on the new model
- Executing the returned command
- etc. …
Actual
- Call to
init
getting the first model - Executing the command returned from
init
- Call to
update
getting a new model - Setting subscriptions based on the new model
- Setting subscriptions based on the first model
This bug was first reported in #1762 by @jatinderjit.
laurentpayot, hpate-omicron and schneiderfelipeharrysarson, barumrho, jhillyerd, ashishsc, JunKikuchi and 19 morelaurentpayot
Metadata
Metadata
Assignees
Labels
No labels