tduccuong

tduccuong

Flash messages don't disappear after phx.gen.auth injected code

I created a new app from scratch using mix phx.new <app> --live , then successfully added the auth layer using mix phx.gen.auth.

After I log in or log out, the flash message does not disappear nor can I click the small X button of the message to clear it. Attached is the picture after I logged in:

I did not do any customization. Just out of the box a LiveView app creation with authentication added. Here are the deps in mix.exs file:

defp deps do
    [
      {:bcrypt_elixir, "~> 3.0"},
      {:phoenix, "~> 1.7.9"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.10"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 3.3"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_view, "~> 0.20.1"},
      {:floki, ">= 0.30.0", only: :test},
      {:phoenix_live_dashboard, "~> 0.8.2"},
      {:esbuild, "~> 0.7", runtime: Mix.env() == :dev},
      {:tailwind, "~> 0.2.0", runtime: Mix.env() == :dev},
      {:swoosh, "~> 1.3"},
      {:finch, "~> 0.13"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 1.0"},
      {:gettext, "~> 0.20"},
      {:jason, "~> 1.2"},
      {:dns_cluster, "~> 0.1.1"},
      {:plug_cowboy, "~> 2.5"}
    ]
  end

Can someone please help? Thanks a lot!

Marked As Solved

beepbeepbopbop

beepbeepbopbop

I think there’s an issue with flash/1 in core_components.ex that was introduced by an update in 1.7.7..1.7.8. Specifically this part:

attr :id, :string, default: nil, doc: "the optional id of flash container"
attr :flash, :map, default: %{}, doc: "the map of flash messages to display"
attr :title, :string, default: nil
attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup"
slot :inner_block, doc: "the optional inner block that renders the flash message"

def flash(assigns) do assigns = assign_new(assigns, :id, fn -> "flash-#{assigns.kind}" end)

The assign_new callback never be invoked as :id would be nil due to the attr macro specifying the default: nil. This would mean that it’s effectively given an empty string as its id attribute and breaks the closing behaviour.

One thing you can do to fix this problem in core_components.ex is to update the attr definition for :id by removing default: nil.

Also Liked

ken-kost

ken-kost

Yea, think it’s meant that way. Somebody asked this I just found, and the answer was the same I was preparing. :slight_smile:

bartonhammond

bartonhammond

No change whatever. That’s from clicking the x on the flash

josevalim

josevalim

Creator of Elixir

This is the correct answer. Remove the default. :slight_smile: it was fixed in main and we shall have a new release soon. :slight_smile:

Last Post!

tjb_dev

tjb_dev

This thread is exactly what I needed! Thanks!

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement