File tree Expand file tree Collapse file tree 4 files changed +89
-1
lines changed
assets/js/phoenix_live_view Expand file tree Collapse file tree 4 files changed +89
-1
lines changed Original file line number Diff line number Diff line change @@ -850,7 +850,7 @@ export default class View {
850850 return
851851 } else if ( resp . reason === "unauthorized" || resp . reason === "stale" ) {
852852 this . log ( "error" , ( ) => [ "unauthorized live_redirect. Falling back to page request" , resp ] )
853- this . onRedirect ( { to : this . root . href } )
853+ this . onRedirect ( { to : this . root . href , flash : this . flash } )
854854 return
855855 }
856856 if ( resp . redirect || resp . live_redirect ) {
Original file line number Diff line number Diff line change 1+ defmodule Phoenix.LiveViewTest.E2E.Issue3686.ALive do
2+ use Phoenix.LiveView
3+
4+ def render ( assigns ) do
5+ ~H"""
6+ < h1 > A</ h1 >
7+ < button phx-click = "go " > To B</ button >
8+
9+ < div id = "flash " >
10+ { inspect ( @ flash ) }
11+ </ div >
12+ """
13+ end
14+
15+ def handle_event ( "go" , _unsigned_params , socket ) do
16+ { :noreply , socket |> put_flash ( :info , "Flash from A" ) |> push_navigate ( to: "/issues/3686/b" ) }
17+ end
18+ end
19+
20+ defmodule Phoenix.LiveViewTest.E2E.Issue3686.BLive do
21+ use Phoenix.LiveView
22+
23+ def render ( assigns ) do
24+ ~H"""
25+ < h1 > B</ h1 >
26+ < button phx-click = "go " > To C</ button >
27+
28+ < div id = "flash " >
29+ { inspect ( @ flash ) }
30+ </ div >
31+ """
32+ end
33+
34+ def handle_event ( "go" , _unsigned_params , socket ) do
35+ { :noreply , socket |> put_flash ( :info , "Flash from B" ) |> redirect ( to: "/issues/3686/c" ) }
36+ end
37+ end
38+
39+ defmodule Phoenix.LiveViewTest.E2E.Issue3686.CLive do
40+ use Phoenix.LiveView
41+
42+ def render ( assigns ) do
43+ ~H"""
44+ < h1 > C</ h1 >
45+ < button phx-click = "go " > To A</ button >
46+
47+ < div id = "flash " >
48+ { inspect ( @ flash ) }
49+ </ div >
50+ """
51+ end
52+
53+ def handle_event ( "go" , _unsigned_params , socket ) do
54+ { :noreply , socket |> put_flash ( :info , "Flash from C" ) |> push_navigate ( to: "/issues/3686/a" ) }
55+ end
56+ end
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ defmodule Phoenix.LiveViewTest.E2E.Router do
114114 pipeline :browser do
115115 plug :accepts , [ "html" ]
116116 plug :fetch_session
117+ plug :fetch_live_flash
117118 plug :protect_from_forgery
118119 plug :put_root_layout , html: { Phoenix.LiveViewTest.E2E.Layout , :root }
119120 end
@@ -163,12 +164,22 @@ defmodule Phoenix.LiveViewTest.E2E.Router do
163164 live "/3656" , Issue3656Live
164165 live "/3658" , Issue3658Live
165166 live "/3684" , Issue3684Live
167+ live "/3686/a" , Issue3686.ALive
168+ live "/3686/b" , Issue3686.BLive
166169 live "/3709" , Issue3709Live
167170 live "/3709/:id" , Issue3709Live
168171 live "/3719" , Issue3719Live
169172 end
170173 end
171174
175+ live_session :other , layout: { Phoenix.LiveViewTest.E2E.Layout , :live } do
176+ scope "/issues" , Phoenix.LiveViewTest.E2E do
177+ pipe_through ( :browser )
178+
179+ live "/3686/c" , Issue3686.CLive
180+ end
181+ end
182+
172183 live_session :navigation , layout: { Phoenix.LiveViewTest.E2E.Navigation.Layout , :live } do
173184 scope "/navigation" do
174185 pipe_through ( :browser )
Original file line number Diff line number Diff line change 1+ const { test, expect} = require ( "../../test-fixtures" )
2+ const { syncLV} = require ( "../../utils" )
3+
4+ // https://github.com/phoenixframework/phoenix_live_view/issues/3686
5+ test ( "flash is copied across fallback redirect" , async ( { page} ) => {
6+ await page . goto ( "/issues/3686/a" )
7+ await syncLV ( page )
8+ await expect ( page . locator ( "#flash" ) ) . toHaveText ( "%{}" )
9+
10+ await page . getByRole ( "button" , { name : "To B" } ) . click ( )
11+ await syncLV ( page )
12+ await expect ( page . locator ( "#flash" ) ) . toContainText ( "Flash from A" )
13+
14+ await page . getByRole ( "button" , { name : "To C" } ) . click ( )
15+ await syncLV ( page )
16+ await expect ( page . locator ( "#flash" ) ) . toContainText ( "Flash from B" )
17+
18+ await page . getByRole ( "button" , { name : "To A" } ) . click ( )
19+ await syncLV ( page )
20+ await expect ( page . locator ( "#flash" ) ) . toContainText ( "Flash from C" )
21+ } )
You can’t perform that action at this time.
0 commit comments