Update callback inside LiveView stateful components only triggering after first mount

Just realised that my update() callbacks inside Live Components are only triggered on the first render, not on further renders. According to the docs they should fire every time render is called (am I wrong?).
Does anyone sees the same?

PS: to check triggering on several Live components I just inserted an IO.puts "trigger" inside update() to test.

I guess the answer is that the update() callback is only triggered on its parent update, not the component itself.
Not that clear in docs.

3 Likes

Hmm, the docs on the latest version state that update/2 is called on the initial render as well as parent updates: Phoenix.LiveComponent — Phoenix LiveView v0.15.4

The word “parent” is in there but only for the stateless component. By missing in there for the stateful I though it was on purpose a clear sign that it was triggered by the component itself as the life-cycle is very clear.
Now it’s evident but for a while I really didn’t see it :slight_smile:

PS: I’ve edited my title to reflect a stateful component