Skip to content
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

Subscription bug in the latest core libraries #1128

Open
miki-c opened this issue Apr 13, 2022 · 1 comment
Open

Subscription bug in the latest core libraries #1128

miki-c opened this issue Apr 13, 2022 · 1 comment

Comments

@miki-c
Copy link

miki-c commented Apr 13, 2022

I am making a multi-page form, and I want the user to be able to move back and forth between the pages. Moreover, when the user moves back to a previous page, I want the form to be automatically re-filled with whatever the user had written before (during this session).

To achieve this, I am relying on the localStorage of the browser:

  • whenever the user is typing, the input is saved on the localStorage
  • when a page is initialized, the existing data is retrieved from the localStorage

To retrieve the data, Elm sends a request to the browser (by using a command during page initialization). Then, Elm waits for a response from the browser (by using a subscription).

I have observed the following behaviour:

  • if the user lands on the page directly (i.e., by clicking a link or typing the URL manually), the subscription works correctly
  • if the user lands on the page by navigating back to it (i.e., by pressing the BACK button of the browser), the subscription does not work

After much debugging, I finally realized this bug only occurs when using the most recent Elm core libraries. Downgrading to older core libraries seems to fix the bug.
To demonstrate this, I created a very basic project, which you can find here: https://github.com/miki-c/elm-bug

Here you will find two elm.json files: one with the older core libraries, and the other with the more recent libraries. The bug will show up when running the app with the recent elm.json file, but not when running it with the old elm.json file. You can find more instructions in the README of the project.


FAQ:

1. Which libraries are causing the bug exactly?


I don't know. I cannot run precise experiments by manually changing their version one by one, because the libraries are all interdependent, and manually editing elm.json throws an error. You can compare the two different elm.json files in the project to find which libraries have been updated. Though, I have a feeling it's one of these:

  • elm/core: 1.0.0 -> 1.0.5
  • elm/http: 1.0.0 -> 2.0.0
  • elm/browser: 1.0.0 -> 1.0.1


2. What is breaking exactly?
By printing some logs, I discovered that the request is successfully sent by Elm and received by the browser. Then, the response is successfully sent by the browser, but it is not received by Elm. It is as if the subscription was not listening at all.

@github-actions
Copy link

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

Finally, please be patient with the core team. They are trying their best with limited resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant