Skip to content

calculate children_cids in Phoenix.LiveView.Debug - #4358

Open
SteffenDE wants to merge 1 commit into
mainfrom
sd-children-cids
Open

calculate children_cids in Phoenix.LiveView.Debug#4358
SteffenDE wants to merge 1 commit into
mainfrom
sd-children-cids

Conversation

@SteffenDE

Copy link
Copy Markdown
Member

Relates to #4357.
Relates to #4356.

@SteffenDE

Copy link
Copy Markdown
Member Author

Feedback from Codex

  - [P2] Avoid deriving children from stale parent links — /Users/steffen/oss/phoenix_live_view/lib/phoenix_live_view/channel.ex:435-435
    When a component stops rendering a nested child, that child can remain in components until the client sends cids_destroyed, and no new pending entry is emitted to clear its old :parent_cid. Grouping all components by this cached value makes Debug.live_components/1 report removed
    children under the old parent, for example after toggling a <.live_component :if={@show}> off inside a parent component.

I think this is acceptable.

@SteffenDE
SteffenDE requested a review from josevalim August 7, 2026 10:02

socket =
put_in(socket.private.children_cids, children_cids)
socket

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a simpler approach is to store it in socket.private.parent_cid instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Basically I wanted to avoid changing the {cid, id, new?, new_assigns} tuples by storing it somewhere else. Either permanently in the socket, as part of new?, or so forth.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see an obviously better way. We only have the child socket later in render_pending_components. This line you commented on is the parent socket.

We could make it

{cid, id, %{new?: new?, parent_cid: parent_cid}, new_assigns}

but I don't think it's much better and we have an extra map. If we're not happy with this, we can also keep things as is. So far nobody complained that children_cids can be incomplete 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think both approaches will be somewhat equivalent by the end of the day. There is the additional traversal in the other one but we may be fine. Your call!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants