New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of port declarations influences behaviour #896

Open
zwilias opened this Issue Aug 10, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@zwilias
Member

zwilias commented Aug 10, 2017

SSCCE

https://ellie-app.com/3YKLTxbsg7na1/1

TL;DR

  • in JS, a subscription which calls send
  • in Elm, an update which modifies the model to enable a subscription and triggers that outgoing port
  • send is called before the subscription handler is scheduled, hence dropping the message.

Problem statement

Setting state to enable a subcription and triggering an outgoing port which synchronously calls back into Elm at the same time leads to this response being missed. This can easily come up when using a subscription-structure like advocated by elm-spa-example.

This is surprising since the user has already configured their model so that a subscription should be enabled, and how/when those subscriptions actually go into effect is an implementation detail the user shouldn't need to worry about.

Possible fix

Ensuring that subscription handlers are scheduled before commands are scheduled seems like a fix; I'm not sure if there are potential adverse effects to doing so.

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Aug 10, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Aug 10, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@zwilias

This comment has been minimized.

Show comment
Hide comment
@zwilias

zwilias Aug 10, 2017

Member

Note that - and this is the truly unexpected part - flipping the order in which the ports are declared fixes this issue, since this directly corresponds to the order in the managers object.

https://ellie-app.com/3YKLTxbsg7na1/2 (only difference with /1 is flipping the order of ports)

Subs first means subscriptions will be processed first

port toElm : (String -> msg) -> Sub msg
port toJS : String -> Cmd msg

Subs last means subs will be processed last.

port toJS : String -> Cmd msg
port toElm : (String -> msg) -> Sub msg

The order in which ports are declared really should not impact behaviour.

Member

zwilias commented Aug 10, 2017

Note that - and this is the truly unexpected part - flipping the order in which the ports are declared fixes this issue, since this directly corresponds to the order in the managers object.

https://ellie-app.com/3YKLTxbsg7na1/2 (only difference with /1 is flipping the order of ports)

Subs first means subscriptions will be processed first

port toElm : (String -> msg) -> Sub msg
port toJS : String -> Cmd msg

Subs last means subs will be processed last.

port toJS : String -> Cmd msg
port toElm : (String -> msg) -> Sub msg

The order in which ports are declared really should not impact behaviour.

@zwilias zwilias changed the title from Synchronous ports may lead to missed values to Order of port declarations influences behaviour Aug 10, 2017

@evancz evancz added the problem label Aug 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment