I have upgraded to 1.7 live view 0.18, I’m getting this odd behavior with put_flash, and suddenly this:
{:noreply,
socket
|> put_flash(:info, "Event created successfully")
|> push_redirect(to: "/events/#{event.slug}/edit")}
Does not put any flash, by the other hand if I don’t do the redirect, it works.
Also in some Live Components, I have changed the push_redirect to push_navigate, in some cases works, in others don’t. I have realized this because I have some integration tests that failed, but I have not 100% coverage and I assume that my app now is completely broken by this API change
The put_flash/3docs include the following notes that seem relevant:
Note: While you can use put_flash/3 inside a Phoenix.LiveComponent, components have their own @flash assigns. The @flash assign in a component is only copied to its parent LiveView if the component calls push_navigate/2 or push_patch/2.
Note: You must also place the Phoenix.LiveView.Router.fetch_live_flash/2 plug in your browser’s pipeline in place of fetch_flash for LiveView flash messages be supported, for example:
import Phoenix.LiveView.Router
pipeline :browser do
...
plug :fetch_live_flash
end
Can you provide a minimal app that reproduces the issue and do a bug report? For example, does it happen if you build a new Phoenix app and run mix phx.gen.live?
FWIW, I did give it a try in a new Phoenix app and I could not reproduce it but it did give me an idea about what could be wrong. When you submit your modal, are you by any chance navigating twice? Check your logs, see HANDLE PARAMS appears twice.
Like regular flash, LiveView flash clears out on page navigation. So if you are doing a double navigation, it will disappear. Feel free to share the code to your modal too!
upload_progress that affects a progress bar correctly updates at the same time. At that moment - actually before the assign happens, the logger reports
iex> [info] JOINED lvu:1 in 1ms
Parameters: %{"token" => "SFMyNTY.g2gDaAJhBXQAAAADZAADY2lkYQFkAANwaWRYZAAUdGVzdEBERVNLVE9QLUNVTDBEMzUAAAOLAAAAAGQLVkhkAANyZWZoAm0AAAAUcGh4LUYwdXZXLVJnWUp6XzlBa0NtAAAAATFuBgAoSwjWhgFiAAFRgA.RhZfTCO-aK-d_eKoSgMyPbIlzkG6PMWHt-8T1zdMRYQ"}
(I’m guessing, it comes from a <.live_file_input)
A side note, could be distantly related, for some reason I have to do send_update when I need to update uploaded_files to []). A regular assign(socket, uploaded_files: []) does not update the child modal that contains a live component. It surely is passed down to the live component as a property upload_progress={@upload_progress} and it surely differs from a list containing at least one item.