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
Browsers you attempted to reproduce this bug on (the more the merrier): Firefox
Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes
Actual behavior
When navigating across LiveViews in different live sessions with push_navigate, live flashes aren't being set and hence aren't being displayed on the redirected LiveView.
I take it that one isn't supposed to use push_navigate to navigate between LiveViews of different sessions anyways, since doing so yields the browser error unauthorized live_redirect. Falling back to page request as well as the server warning navigate event to [...] failed because you are redirecting across live_sessions. A full page reload will be performed instead. Furthermore, I can easily get the expected behaviour by replacing push_navigate with redirect. ...
Expected behavior
... However, since this fallback behaviour exists for this situation, I think live flashes should work properly as well, since otherwise it can be hard to figure out why they aren't being displayed. I.e. live flashes should be displayed even when using push_navigate across different live sessions.
Reproducing the bug
Here is a single-file application showing the bug: A -> B: Using push_navigate within a live session => Flash is shown B -> C: Using redirect across two live sessions => Flash is shown C -> A: Using push_navigate across two live sessions => Flash is not shown
# main.exs# Run with: elixir main.exsApplication.put_env(:sample,Example.Endpoint,http: [ip: {127,0,0,1},port: 5001],server: true,live_view: [signing_salt: "aaaaaaaa"],secret_key_base: String.duplicate("a",64))Mix.install([{:plug_cowboy,"~> 2.5"},{:jason,"~> 1.0"},{:phoenix,"~> 1.7"},{:phoenix_live_view,github: "phoenixframework/phoenix_live_view",branch: "main",override: true}])defmoduleExample.CoreComponentsdo# default core components for live flashesusePhoenix.ComponentaliasPhoenix.LiveView.JSattr:id,:string,doc: "the optional id of flash container"attr:flash,:map,default: %{},doc: "the map of flash messages to display"attr:title,:string,default: nilattr:kind,:atom,values: [:info,:error],doc: "used for styling and flash lookup"attr:rest,:global,doc: "the arbitrary HTML attributes to add to the flash container"slot:inner_block,doc: "the optional inner block that renders the flash message"defflash(assigns)doassigns=assign_new(assigns,:id,fn->"flash-#{assigns.kind}"end)~H"""<div:if={msg=render_slot(@inner_block)||Phoenix.Flash.get(@flash,@kind)}id={@id}role="alert"class={["fixed top-2 right-2 mr-2 w-80 sm:w-96 z-50 rounded-lg p-3 ring-1",@kind==:info&&"bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900",@kind==:error&&"bg-rose-50 text-rose-900 shadow-md ring-rose-500 fill-rose-900"]}{@rest}><p:if={@title}class="flex items-center gap-1.5 text-sm font-semibold leading-6">{@title}</p><pclass="mt-2 text-sm leading-5">{msg}</p></div>"""endattr:flash,:map,required: true,doc: "the map of flash messages"attr:id,:string,default: "flash-group",doc: "the optional id of flash container"defflash_group(assigns)do~H"""<divid={@id}><.flashkind={:info}title="Success!"flash={@flash}/><.flashkind={:error}title="Error!"flash={@flash}/></div>"""endenddefmoduleExample.LayoutsdousePhoenix.LiveViewdefrender("app.html",assigns)do~H"""<scriptsrc="/assets/phoenix/phoenix.js"></script><scriptsrc="/assets/phoenix_live_view/phoenix_live_view.js"></script><scriptsrc="https://cdn.tailwindcss.com"></script><script> let liveSocket = new window.LiveView.LiveSocket("/live", window.Phoenix.Socket) liveSocket.connect()</script><style> * {font-size: 1.1em;}</style><Example.CoreComponents.flash_groupflash={@flash}/>{@inner_content}"""endenddefmoduleExample.ALivedousePhoenix.LiveView,layout: {Example.Layouts,:app}defrender(assigns)do~H"""<h1>A</h1><buttonphx-click="go">To B</button>"""enddefhandle_event("go",_unsigned_params,socket)do{:noreply,socket|>put_flash(:info,"Flash from A")|>push_navigate(to: "/b")}endenddefmoduleExample.BLivedousePhoenix.LiveView,layout: {Example.Layouts,:app}defrender(assigns)do~H"""<h1>B</h1><buttonphx-click="go">To C</button>"""enddefhandle_event("go",_unsigned_params,socket)do{:noreply,socket|>put_flash(:info,"Flash from B")|>redirect(to: "/c")}endenddefmoduleExample.CLivedousePhoenix.LiveView,layout: {Example.Layouts,:app}defrender(assigns)do~H"""<h1>C</h1><buttonphx-click="go">To A</button>"""enddefhandle_event("go",_unsigned_params,socket)do{:noreply,socket|>put_flash(:info,"Flash from C")|>push_navigate(to: "/a")}endenddefmoduleExample.RouterdousePhoenix.Router,helpers: falseimportPlug.ConnimportPhoenix.ControllerimportPhoenix.LiveView.Routerpipeline:browserdoplug(:accepts,["html"])plug(:fetch_session)plug(:fetch_live_flash)endscope"/",Exampledopipe_through(:browser)live_session:a_b_sessiondolive("/a",ALive,:index)live("/b",BLive,:index)endlive_session:c_sessiondolive("/c",CLive,:index)endendenddefmoduleExample.EndpointdousePhoenix.Endpoint,otp_app: :sample@session_options[store: :cookie,key: "_example_key",signing_salt: "De3iCH6m",same_site: "Lax"]socket("/live",Phoenix.LiveView.Socket)plug(Plug.Static,from: {:phoenix,"priv/static"},at: "/assets/phoenix")plug(Plug.Static,from: {:phoenix_live_view,"priv/static"},at: "/assets/phoenix_live_view")plug(Plug.Session,@session_options)plug(Example.Router)end{:ok,_}=Supervisor.start_link([Example.Endpoint],strategy: :one_for_one)Process.sleep(:infinity)
The text was updated successfully, but these errors were encountered:
Environment
Actual behavior
When navigating across LiveViews in different live sessions with
push_navigate
, live flashes aren't being set and hence aren't being displayed on the redirected LiveView.I take it that one isn't supposed to use
push_navigate
to navigate between LiveViews of different sessions anyways, since doing so yields the browser errorunauthorized live_redirect. Falling back to page request
as well as the server warningnavigate event to [...] failed because you are redirecting across live_sessions. A full page reload will be performed instead
. Furthermore, I can easily get the expected behaviour by replacingpush_navigate
withredirect
. ...Expected behavior
... However, since this fallback behaviour exists for this situation, I think live flashes should work properly as well, since otherwise it can be hard to figure out why they aren't being displayed. I.e. live flashes should be displayed even when using
push_navigate
across different live sessions.Reproducing the bug
Here is a single-file application showing the bug:
A -> B
: Usingpush_navigate
within a live session => Flash is shownB -> C
: Usingredirect
across two live sessions => Flash is shownC -> A
: Usingpush_navigate
across two live sessions => Flash is not shownThe text was updated successfully, but these errors were encountered: