josefrichter
Is there a way to have a flash message disappear (fade out) after a few seconds, please? Can’t find anything in docs nor on internets. Feels like this could be easy in LiveView, maybe I’m just missing the obvious. Thank you.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #ai
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sfusato
You can achieve that with something like this:
Send a message to
selfwhen you useput_flashThen, in
handle_info:baldwindavid
That will remove the flash immediately, right? I use some css to accomplish fading out though it is for a different case than flash messages.
josefrichter
It appears to me, that the process that put the flash message is dead after it e.g. creates a record. Maybe the send needs to go to different process?
sfusato
That’s true. If you program the sending to a
pid, thenpush_redirectfrom the live component, the live view will be shut down and a new one created in its place, thus the old process won’t exist anymore. Changing topush_patchshould work.Also, forgot to mention that you also need to make sure the socket is connected before sending the message:
@baldwindavid, it will just be removed from the DOM. You could chain together 2 events: 1st fade-out the element (add a css class), then remove it altogether. Worth mentioning that animations are best kept for Javascript, rather than Liveview. You could have a hook on the flash message that will remove itself in 5 seconds with animation effects and everything.
josefrichter
Bingo! I’ve combined both of your solutions, and tweaked it a bit. I kept
push_redirectrather thanpush_patchas I was “returning” to index and with push_patch my index of items was not updated.My workaround is that I actually put the
Process.send_afterinto mymountfunction, because that’s where I always get back to – so if there’s any new flash message displayed, it gets cleared after 5s. Not sure it’s super robust solution, but this way I need the clear function in one place only, and it works nicely.And I applied the css animation to nicely fade out the flash, no need for javascript, nor desirable for this simple animation, I think.
GumptionWare
Hey guys. This thread was very helpful. Many thanks. I see many other threads out there asking this question, and this one seems to be the closest to a clean solution.
I wanted to revisit this topic given more recent Phoenix & LiveView releases. Frankly, I am baffled that such a standard UI behavior expectation is still so hard to find a clean solution for in Phoenix/LiveView. If I am missing that solution, please point me to it.
I just created a fresh Phoenix app and ran
mix phx.gen.authto create a typical starting point to see how Flash messages currently behave. (FYI, it looks like my generator runs created a Phoenix 1.7.10 app running LiveView 0.19.5).Alas, it appears that nothing has changed. Out of the box, Flash message behavior remains static. The Flash box appears, and it just stays there–until the user clicks the “x” in the box to dismiss it.
The (partial) Solution So Far
Adapting the advice in this thread history, I have been able to get the Flash box to go away after a specified number of milliseconds. In my example app, I have a (generated) LiveView scaffolding for an Alerts table and its LiveViews, so I have a
MyApp_web/live/alert_live/index.exand aMyApp_web/live/form_component.exthat are involved in making updates to Alert records via LiveView interactions.My list of alerts is driven by this logic in
MyApp_web/live/alert_live/index.ex:Because each CRUD action on an Alert gets us back here, I have added the
Process.send_after(self(), :clear_flash, 3000)in this function as shown above.That
:clear_flashhandle_event function is also inMyApp_web/live/alert_live/index.ex:This works. I’m not (yet) using CSS to create a graceful fade-out; the Flash box disappears abruptly after 3 seconds. It is not slick, but it is a huge improvement.
But How Do We Generalize This?
I haven’t wired this up for all the other places CRUD activities take place (like User Settings, for example). This solution will require repeating this logic in all the places
put_flashis invoked. To say the most, that is very not DRY.I asked my AI intern for suggestions, and that advice included writing JavaScript to create a more generalized solution. That strikes me as antithetical to the LiveView vision–particularly for UI behavior users expect–and behavior that is common to most of the other web frameworks out there.
We need to do better than this. I need a solution that is credible to SaaS users, and our community needs a solution that is credible to UI framework adopters.
I’m not just whining here; I am eager to do the work required to help create, document and publicize a generalized solution.
Thanks in advance for your help.
horizon0708
To keep it dry, maybe have a look at attach_hook/4 in conjunction with on_mount?
To give an example, I have something like this:
And this is mounted to live_session in
router.exNow the logic to hide the flash is in one place.
I do agree that more could be done for flash though!
GumptionWare
This looks promising! I’ll give it a shot and report back.
HUGE thanks!
sezaru
Hey @GumptionWare maybe you will be interested in my library which supports what you want to do and much more: Flashy - A small library to extend LV's flash notifications - #17 by sezaru
GumptionWare
Thank @sezaru!! Our team will check that out tomorrow. It looks pretty complete.