Skip to content

Commit aa407c3

Browse files
authored
Add note about phx-mounted limitation to ignore_attributes docs (#3967)
* Add note about phx-mounted limitation to ignore_attributes docs Relates to #3943
1 parent 3d3734c commit aa407c3

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

guides/client/bindings.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,10 @@ can be used. For example, to animate an element on mount:
345345
<div phx-mounted={JS.transition("animate-ping", time: 500)}>
346346
```
347347

348-
If `phx-mounted` is used on the initial page render, it will be invoked only
349-
after the initial WebSocket connection is established.
348+
If `phx-mounted` is used on the initial page render, it will run at the earliest
349+
opportunity. For elements outside of a LiveView, this is as soon as `liveSocket.connect()`
350+
is executed. For elements inside of a LiveView, this is only after the initial socket
351+
connection is established and the LiveView is mounted.
350352

351353
To react to elements being removed from the DOM, the `phx-remove` binding
352354
may be specified, which can contain a `Phoenix.LiveView.JS` command to execute.

lib/phoenix_live_view/js.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,13 @@ defmodule Phoenix.LiveView.JS do
909909
</dialog>
910910
```
911911
912+
> #### A note on the behavior of phx-mounted {: .info}
913+
>
914+
> The `phx-mounted` binding executes when the LiveView is mounted.
915+
> This means that you cannot use `ignore_attributes/1` to retain attributes
916+
> that are set on the client during the disconnected render.
917+
> `JS.ignore_attributes/0` will only ever ignore future changes from the server.
918+
912919
## Options
913920
914921
* `:to` - An optional DOM selector to select the target element.

0 commit comments

Comments
 (0)