<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="352112" data-post-id="352112">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jtormey" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtormey/120/35523_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jtormey
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cmo" data-post="11" data-topic="68518">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmo/48/19618_2.png" class="avatar"> cmo:</div>
<blockquote>
<p>Name spacing the events breaks down at what point? Deeply nested components?</p>
</blockquote>
</aside>
<p>Name spaces can conflict between sibling components. And that aside, this is more about avoiding the indirection of: <code>handle_info/2 -&gt; send_update/2 -&gt; update/2</code>.</p>
<p>The ability to add <code>handle_info/2</code> to any LiveComponent and have it manage its own PubSub subscriptions, no manual routing required, is incredibly convenient.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="352112" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-352112" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="352112"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="352113" data-post-id="352113">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cmo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmo/120/19618_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cmo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="jtormey" data-post="12" data-topic="68518">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtormey/48/35523_2.png" class="avatar"> jtormey:</div>
<blockquote>
<p>The ability to add <code>handle_info/2</code> to any LiveComponent and have it manage its own PubSub subscriptions, no manual routing required, is incredibly convenient.</p>
</blockquote>
</aside>
<p>I get that, but it does come with a cost - extra process plus an extra library with slightly different semantics.  You don’t explain the original problem and what it looks like so I’m really just trying to understand how you got here.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="352113" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-352113" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="352113"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="352124" data-post-id="352124">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jtormey" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtormey/120/35523_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jtormey
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cmo" data-post="13" data-topic="68518">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmo/48/19618_2.png" class="avatar"> cmo:</div>
<blockquote>
<p>I get that, but it does come with a cost - extra process plus an extra library with slightly different semantics. You don’t explain the original problem and what it looks like so I’m really just trying to understand how you got here.</p>
</blockquote>
</aside>
<p>To put those costs in perspective, an extra process isn’t expensive in elixir, and the library is a thin wrapper around <code>Phoenix.LiveComponent</code>, which you would only use if the new semantics prove valuable for you.</p>
<p>The original problem is in the first paragraph of the post if that helps <img src="https://forum.elixirforum.com/images/emoji/apple/slightly_smiling_face.png?v=15" title=":slightly_smiling_face:" class="emoji" alt=":slightly_smiling_face:" loading="lazy" width="20" height="20"></p>
<p>I implemented the example app using both approaches in case you’d like to compare: <a href="https://github.com/jtormey/connected_component_demo/blob/b75fe70c3054313f027f2da280e91c7036b7a87f/lib/app_web/live/connected_live/index.ex" rel="noopener nofollow ugc">Connected</a> vs. <a href="https://github.com/jtormey/connected_component_demo/blob/b75fe70c3054313f027f2da280e91c7036b7a87f/lib/app_web/live/disconnected_live/index.ex" rel="noopener nofollow ugc">Disconnected (vanilla LiveView)</a>. If it’s not worth the cost to you, totally get that, I shared in case anyone else was in search of better abstractions/patterns around LiveView.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="352124" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-352124" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="352124"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="352138" data-post-id="352138">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="gushonorato" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gushonorato/120/36861_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  gushonorato
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="jtormey" data-post="5" data-topic="68518">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtormey/48/35523_2.png" class="avatar"> jtormey:</div>
<blockquote>
<ul>
<li>They also spawn a new process, which is even heavier than my connected component process (it holds the state of the LiveView, instead of just passing along messages).</li>
</ul>
</blockquote>
</aside>
<p>I’m not sure if I agree with that statement because the LiveComponent state will also need to be stored, though not in a lightweight process, but in the parent LiveView. However, I don’t think that’s the main point of the discussion.</p>
<p>I understand that the initial problem you’re trying to solve is the communication between LiveComponents and PubSub. Since the discussion has shifted towards efficiency, I believe it would be beneficial to avoid creating a separate process to accommodate this feature. Instead, a “message broker” within the LiveView itself could handle this task, eliminating the need to spawn additional processes. This approach is more efficient and avoids introducing extra complexity to the LiveComponents.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="352138" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-352138" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="352138"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="352209" data-post-id="352209">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jtormey" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtormey/120/35523_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jtormey
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="gushonorato" data-post="15" data-topic="68518">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/gushonorato/48/36861_2.png" class="avatar"> gushonorato:</div>
<blockquote>
<p>I understand that the initial problem you’re trying to solve is the communication between LiveComponents and PubSub. Since the discussion has shifted towards efficiency, I believe it would be beneficial to avoid creating a separate process to accommodate this feature. Instead, a “message broker” within the LiveView itself could handle this task, eliminating the need to spawn additional processes. This approach is more efficient and avoids introducing extra complexity to the LiveComponents.</p>
</blockquote>
</aside>
<p>I agree, it would be best if the extra process wasn’t necessary. However I wasn’t able to come up with a solution for automatically brokering messages in a single process, there are too many complications and you end up back where we started with manual message routing.</p>
<p>The extra process removes this complexity entirely, when it receives a message you know exactly the component its meant for, then it’s tagged as such and relayed to it. And this is opt-in, you wouldn’t use this for the majority of your components.</p>
<p>If you have specific ideas on implementing a single-process message broker I would love to hear them!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="352209" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-352209" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="352209"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="358406" data-post-id="358406">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mortenlund" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mortenlund
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I would really like a pattern for this as well!<br>
It would be very helpful to have handle_info for live_component as well.<br>
Also having <code>unmount</code> for both live_view and live_component would be extra awesome!</p>
<p>Imagining having a live_component that subscribes to the pubsub on mount, and then be able to unsubscribe on <code>unmount</code><br>
And since the actual Pubsub subscription would be tied to the parent live_view process it would be unsubscribed automatically in case the process dies.</p>
<p>I had an idea to make live_components able to subscribe and receive Pubsub messages directly. But never a clean way to unsubscribe.</p><aside class="quote quote-modified" data-post="11" data-topic="66050">
  <div class="title">
    <div class="quote-controls"></div>
    <img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/7993a0/48.png" class="avatar">
    <div class="quote-title__text-content">
      <a href="https://forum.elixirforum.com/t/liveview-live-component-unmount-callback/66050/11" rel="nofollow">LiveView - Live Component - unmount callback</a> <a class="badge-category__wrapper " href="/c/chat-discussions/proposals-ideas/164" rel="nofollow"><span data-category-id="164" style="--category-badge-color: #cca771; --category-badge-text-color: #FFFFFF; --parent-category-badge-color: #cca771;" data-parent-category-id="165" data-drop-close="true" class="badge-category --style-square --has-parent"><span class="badge-category__name">Proposals: Ideas</span></span></a>
    </div>
  </div>
  <blockquote>
    Well, they can with some slight tricks <img width="20" height="20" src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title="slight_smile" alt="slight_smile" class="emoji"> <img width="20" height="20" src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title="slight_smile" alt="slight_smile" class="emoji"> 
I currently have a special module like this that handles the subscription and acts as a special dispatcher. 
This does not rely on the parent LiveView and the subscription will be cleaned up when the parent LiveView process dies as normal PubSub subscriptions <img width="20" height="20" src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title="slight_smile" alt="slight_smile" class="emoji"> 
defmodule MyLiveComponent.PubSub do
  @moduledoc false

  def subscribe(%Phoenix.LiveView.Socket{assigns: %{myself: myself} = socket, pubsub, topic) do
  …
  </blockquote>
</aside>

<p>The reason why being able to unsubscribe using a <code>unmount</code> callback in the live_component would be if you had a <code>widget</code> implemented as a live_component and the <code>widget</code> was removed from the page in a <code>render</code> and you wanted to unsubscribe from the Pubsub without the parent having to manage the subscriptions and unsubscribe the ones that was owned by the child live_component.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358406" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-358406" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358406"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="358532" data-post-id="358532">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jtormey" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtormey/120/35523_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jtormey
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="mortenlund" data-post="17" data-topic="68518">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/m/7993a0/48.png" class="avatar"> mortenlund:</div>
<blockquote>
<p>Imagining having a live_component that subscribes to the pubsub on mount, and then be able to unsubscribe on <code>unmount</code></p>
</blockquote>
</aside>
<p>In the solution I’ve implemented above, the component unsubscribes from PubSub automatically when it unmounts, as the process that manages it is stopped. So, no need for an <code>unmount</code> callback even <img src="https://forum.elixirforum.com/images/emoji/apple/slightly_smiling_face.png?v=15" title=":slightly_smiling_face:" class="emoji" alt=":slightly_smiling_face:" loading="lazy" width="20" height="20"></p>
<p>(Though I agree that would be nice to have for other reasons too.)</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358532" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-358532" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358532"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="358605" data-post-id="358605">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mortenlund" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mortenlund
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi!</p>
<p>Just looked thoroughly through your implmenetation and I would actually recommend this as a real candidate to the standard library <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"><br>
Much more ergonomic with on_mount and handle_update the way you made it.<br>
And the unmounting was also very nice <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"><br>
Good job!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="358605" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-358605" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="358605"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="359963" data-post-id="359963">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="mortenlund" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  mortenlund
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi again!</p>
<p>Is the event that is triggered on DOM removal supposed to work?<br>
<a href="https://github.com/jtormey/connected_component_demo/blob/b75fe70c3054313f027f2da280e91c7036b7a87f/lib/connected_component.ex#L166" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/jtormey/connected_component_demo/blob/b75fe70c3054313f027f2da280e91c7036b7a87f/lib/connected_component.ex#L166</a></p>
<p>This line specifically says to push a message to the server but using the now removed element as the target.</p>
<p>My current test shows that this gives this error:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">utils.js:7 no component found matching phx-target of 7
</code></pre>
<p>Looking at the JS the binding checks if the component is still available in the DOM before trying to send the event to the server.</p>
<p>Since I really liked your approach I tried to fix it with the following:</p>
<p>I made a change where the <code>connected_detach_event</code> is sent to the parent instead with the <code>cid</code> as value:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">connected_remove =
          Phoenix.LiveView.JS.push(@connected_detach_event, value: %{cid: socket.assigns.myself.cid})
</code></pre>
<p>Updated the hook:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def on_mount(:default, _params, _session, socket) do
      updated_socket =
        socket
        |&gt; attach_hook(
          :connected_handle_info,
          :handle_info,
          &amp;SkyClientWeb.Components.ConnectedLiveComponent.connected_handle_info/2
        )
        |&gt; attach_hook(
          :connected_handle_event,
          :handle_event,
          &amp;SkyClientWeb.Components.ConnectedLiveComponent.connected_handle_event/3
        )

      {:cont, updated_socket}
    end
</code></pre>
<p>And updated the handler</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defp detach_component_process(socket, cid) do
    cid = %Phoenix.LiveComponent.CID{cid: cid}
    send(self(), {@connected_detach, cid})

    if component_pid = Process.get({@connected_process_dict, cid}) do
      send(component_pid, :unmount)
      Process.delete({@connected_process_dict, cid})
    end

    socket
  end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="359963" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-359963" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="359963"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="359988" data-post-id="359988">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jtormey" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jtormey/120/35523_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jtormey
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Good catch! Thank you for implementing a fix for that.</p>
<p>The use of <code>phx-remove</code> itself was kind of a workaround, I went with this option because there is no LiveView-side API for knowing when a LiveComponent unmounts. If that ever changes then there’s opportunity to improve this further.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="359988" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/adding-a-handle-info-callback-to-livecomponents/68518/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-359988" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="359988"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/68518/load_more?page=3">Load more posts (5 remaining)</a>
</div></template></turbo-stream>