You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* phoenix 1.7.14 (Hex package) (mix)
locked at 1.7.14 (phoenix) c7859bc5
ok
Phoenix LiveView version (mix deps):
* phoenix_live_view 1.0.0-rc.7 (Hex package) (mix)
locked at 1.0.0-rc.7 (phoenix_live_view) b82a4575
ok
Operating system: MacOS Sonoma 14.4.1
Browsers you attempted to reproduce this bug on (the more the merrier): It's a problem with tests
Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes (well, it should, didn't test, but you will get it)
Actual behavior
I have a LiveView like this:
defmoduleTwelvexWeb.StocksLivedodefmount(params,_session,socket)do{:ok,socket,temporary_assigns: [time_series: AsyncResult.loading()]}end# ...defpapply_action(socket,:time_series,params)doassign_async(socket,:time_series,fn->{:ok,%{time_series: get_time_series(params["symbol"])}}end)end# ...defrender(assigns)do~H""" <%!-- ... --%> <.async_result :let={time_series} assign={@time_series}> <:loading> Loading time series </:loading> <:failed> Failed to load time series </:failed> <.chart id="time-series-chart" series={time_series} /> </.async_result> <%!-- ... --%>"""endend
Then a test for it, like this:
test"loads the time series chart asynchronously",%{conn,conn}do{:ok,live,html}=live(conn,~p"/time_series?symbol=AAPL")asserthtml=~"Loading time series"html=render_async(live)refutehtml=~"Loading time series"# ...end
And this test gets flaky, failing randomly in the refute html =~ "Loading time series". During my investigations I figured the flakiness went away when I added a pid |> Process.info() |> dbg() inside the function I pass assign_async(:time_series, <here>). Then I realized the same assign was being set by temporary_assigns too.
My guess is that the error happens when the temporary_assigns logic runs right after assign_async task finishes but before the render. Not even sure if that's fixable on LiveView side, but at least worth mentioning in the docs.
Expected behavior
I would expect to not have problems with assign_async and temporary_assigns being combined.
The text was updated successfully, but these errors were encountered:
I think I've run into the same (or similar) issue, where I have a start_async that, if it finishes too soon, causes the loading state to be rendered even though the state has already updated. In my case this is without temporary assigns. Inside of a live component if that makes a difference. I don't have a small reproduction; I just added a Process.sleep for now, which is less than ideal.
Environment
Actual behavior
I have a LiveView like this:
Then a test for it, like this:
And this test gets flaky, failing randomly in the
refute html =~ "Loading time series"
. During my investigations I figured the flakiness went away when I added apid |> Process.info() |> dbg()
inside the function I passassign_async(:time_series, <here>)
. Then I realized the same assign was being set bytemporary_assigns
too.My guess is that the error happens when the
temporary_assigns
logic runs right afterassign_async
task finishes but before therender
. Not even sure if that's fixable on LiveView side, but at least worth mentioning in the docs.Expected behavior
I would expect to not have problems with
assign_async
andtemporary_assigns
being combined.The text was updated successfully, but these errors were encountered: