From b59bede3fcec6995f1d5876a520af8badc4bb7fb Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Thu, 24 Oct 2024 14:17:40 -0400 Subject: [PATCH] Fix undefined LiveComponent statics reference. When we share a statics from a LiveComponent with matching fingerprint, we must ensure we don't share statics for a component that has been marked for deletion by the client, since the component may be removed by the client and the diff about to be sent will contain a reference to the now undefined statics. Continue down the tree to find other shared statics, or fallback to generating own statics --- lib/phoenix_live_view/diff.ex | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/phoenix_live_view/diff.ex b/lib/phoenix_live_view/diff.ex index 49906e3ef4..d124bc4f20 100644 --- a/lib/phoenix_live_view/diff.ex +++ b/lib/phoenix_live_view/diff.ex @@ -871,7 +871,11 @@ defmodule Phoenix.LiveView.Diff do case :maps.next(iterator) do {_, cid, iterator} -> case old_cids do - %{^cid => {_, _, _, _, {^print, _} = tree}} -> + # if a component is marked for deletion, we cannot share its statics since it may be removed + %{^cid => {_, _, _, %{@marked_for_deletion => true}, {^print, _} = _tree}} -> + find_same_component_print(print, iterator, old_cids, new_cids, attempts - 1) + + %{^cid => {_, _, _, _private, {^print, _} = tree}} -> {-cid, tree} %{} ->