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

no toast when using push_navigate #36

Closed
rmand97 opened this issue Jan 21, 2025 · 5 comments
Closed

no toast when using push_navigate #36

rmand97 opened this issue Jan 21, 2025 · 5 comments

Comments

@rmand97
Copy link

rmand97 commented Jan 21, 2025

description
When using send_toast and thereafter using push_navigate in a liveview, there is no toast on the page navigated to.
In the router the two pages are in the same live_session.

I have created a small repo to replicate the bug. Try using the buttons to navigate between the pages.
it uses the latest version from master.

repo
https://github.com/rmand97/livetoast_navigation_bug

expected behavior
Toasts appears on page that is navigated to

@FranzVDB
Copy link

🙏

@PJUllrich
Copy link

might be a red herring but this here might be related: phoenixframework/phoenix_live_view#3612 especially this comment:

I mean the sticky navbar LV contains a live component, it need to call send_update(cid, assigns) to update the live component when navigating to another article LV.

phoenixframework/phoenix_live_view#3612 (comment)

@srcrip
Copy link
Owner

srcrip commented Jan 31, 2025

Interesting. I'm just getting back from paternity leave today so I will try to replicate in your repo.

@srcrip
Copy link
Owner

srcrip commented Feb 5, 2025

@rmand97 the issue is your using send_toast when you need to be using put_toast. The idea is that send_toast is like calling send, it's an asynchronous event going to the LiveComponent. put_toast is synchronous and takes the socket and returns the socket. So change your code to something like:

  def handle_event("nav", _unsigned_params, socket) do
    {:noreply,
     socket
     |> LiveToast.put_toast(:info, "navigated from page two")
     |> push_navigate(to: ~p"/")}
  end

And it'll work. Thank you!

@srcrip srcrip closed this as completed Feb 5, 2025
@rmand97
Copy link
Author

rmand97 commented Feb 7, 2025

@srcrip thanks!

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

4 participants