Skip to content

Commit cb2c582

Browse files
authored
Fix docs: correct push_event behavior on redirect (#4183)
Update the documentation for push_event/3 to correctly reflect that events pushed during a redirect (such as push_navigate/2) are sent to the client before the redirection happens, rather than being discarded.
1 parent 361c44d commit cb2c582

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

lib/phoenix_live_view.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,8 @@ defmodule Phoenix.LiveView do
810810
handling the given `event`. If you need to scope events, then
811811
this must be done by namespacing them.
812812
813-
Events pushed during `push_navigate` are currently discarded,
814-
as the LiveView is immediately dismounted.
813+
Events pushed during `push_navigate` (or any redirect) are sent to the
814+
client before the redirection happens.
815815
816816
## Hook example
817817

lib/phoenix_live_view/utils.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ defmodule Phoenix.LiveView.Utils do
265265
@doc """
266266
Annotates the changes with the event to be pushed.
267267
268-
By default, events are dispatched on the JavaScript side only after
269-
the current patch is invoked. Therefore, if the LiveView
270-
redirects, the events won't be invoked. If the `dispatch: :before` option
271-
is passed, this event will be dispatched before patching the DOM.
268+
By default, events are dispatched on the JavaScript side after
269+
the current patch is invoked. If the LiveView redirects,
270+
any pending events are dispatched before the redirection occurs.
271+
If the `dispatch: :before` option is passed, this event will be
272+
dispatched before patching the DOM.
272273
"""
273274
def push_event(%Socket{} = socket, event, %{} = payload, opts) do
274275
opts = Keyword.validate!(opts, [:dispatch])

0 commit comments

Comments
 (0)