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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>The problem here is not so much optimization of <em>software performance</em> (though of course that matters) but rather optimization of <em>developer performance</em>. That is: not turning your codebase into a spaghetti disaster. We are all programmers on here and we all know what this feels like, so I don’t need to justify this further.</p>
<p>The question the OP actually <em>asked</em> is a question of resource management by components. How can a component allocate a resource (in this case PubSub, but it could be literally anything) and then release it when the component is unmounted. Ideally declaratively and idiomatically within LiveView.</p>
<p>What I have explained (hopefully clearly, but maybe not idk) is that it is not possible to solve this properly in LiveView because components (including the root LV, which is also a component) do not have an <code>unmount</code> callback. It has been proposed several times but so far no dice.</p>
<p>I want to be very clear: there is nothing wrong with your or <a class="mention" href="/u/krasenyp" rel="nofollow">@krasenyp</a> 's suggestion to filter events on the receiving end. This is a legitimate technique, and that’s what I was getting at with the Slack bit at the end. There are times when you can and should do this.</p>
<p>However, the filtering trick <strong>does not solve the problem in the OP</strong>. The inability to manage resources will come back to haunt you either way. There is a reason most frameworks have some sort of <code>unmount</code>. React post-Hooks came up with something even better (the <code>useEffect</code> continuation/slicing trick) which I also described, and which is also described in much more detail in one of those articles I linked.</p>
<p>I will try to give one last example. Say you have a LiveView at <code>/products</code>, like the OP, and it receives events. Now say you have another <em>completely unrelated</em> page in your app, like <code>/settings</code>. You make use of the live navigation feature to allow users to navigate between pages over the socket (as the OP did).</p>
<p>A user:</p>
<ul>
<li>Loads <code>/products/1</code> and mounts a <code>Product</code> LiveView</li>
<li>Subscribes to the <code>"product_updates"</code> PubSub channel</li>
<li>Clicks on a link to <code>/settings</code> which mounts the <code>Settings</code> LV in the same process</li>
</ul>
<p>The <code>Settings</code> LiveView now receives product updates.</p>
<p>Put aside all performance concerns here and just trust your experience. Can you honestly say that you think this sounds like a good idea? Can you honestly say that down the road, when your app has 100 pages, a bunch random events bouncing around unpredictably between all of them won’t cause confusion or bugs?</p>
<p>It is not premature optimization to design systems properly from the start, and <em>this is not an edge case.</em> There is no easy way to paper over this with some hack, because it will always come back. It will come back with components, it will come back with other types of resources, and so on.</p>
<p>The OP asked for an elegant solution and I don’t believe there is one. If they had asked about React (or really any other app framework) I could have just handed them the <code>useEffect()</code> example and that would be it.</p>
<p>If anyone else has an actual solution that I haven’t thought of please post it. Filtering, while entirely valid, does not solve this problem.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380577" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-380577" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380577"
                     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="380578" data-post-id="380578">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="garrison" data-post="12" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>If anyone else has an actual solution that I haven’t thought of please post it. Filtering, while entirely valid, does not solve this problem.</p>
</blockquote>
</aside>
<p>If the problem you’re referring to is not one software performance, then I don’t think there is one, unless maybe the hard problem of naming. As <a class="mention" href="/u/krasenyp" rel="nofollow">@krasenyp</a> already said above, the scenario as stated by OP  is a common problem and this solution does in fact work. Whether it’s the “best” solution, or even good is a much, well, harder problem. So if your question “Can you honestly say that you think this sounds like a good idea?” is genuine, then yes, I can. If it’s rhetorical, I can just ask you the inverse one, which is why we should avoid rhetorical questions.</p>
<aside class="quote no-group" data-username="garrison" data-post="12" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>It is not premature optimization to design systems properly from the start,</p>
</blockquote>
</aside>
<p>I quite frankly don’t think this is a meaningful statement. If “premature optimization” has any meaning at all, it is precisely that “from the start” you don’t know what the “proper” design for the system will be in the future, and so you need to attempt to constrain your design to the problems that are known. Like anything else of significance, this is not necessarily clear or easy, and indeed I do think it falls under a broad interpretation of the problem of naming (i.e. that names directly reflect the design and can only be as “good” as the design itself).</p>
<p><strong>edit</strong></p>
<p>From what you’ve written elsewhere I would guess your real gripe is with the design of LiveView itself in view of its ability (or lack of it) to elegantly handle the problems most web apps eventually face more than it is with the “filtering strategy” for handling PubSub messages. And in that regard I’m actually pretty sympathetic to your view. Just think it’s a bit off topic in this thread where LV is not on trial and really is not very related to this problem, since any system with processes needing to ingest data from some set of PubSub channels would face a similar problem.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380578" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-380578" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380578"
                     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="380583" data-post-id="380583">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If you are writing genuinely exploratory code then it is indeed much harder to structure everything correctly the first time.</p>
<p>However, if you are working with established patterns you can absolutely lean on past experiences. Both your own, and those of others. In <a href="https://react.dev/reference/react/useEffect#connecting-to-an-external-system" rel="noopener nofollow ugc">the first section of the useEffect docs</a> React gives a proper example of how to manage a resource. Clearly this is not an obscure problem but an extremely common one with known solutions.</p>
<p>Please re-read the OP. You will see that it <em>very clearly describes</em> this <em>exact problem</em>.</p>
<p>Again: if there is something I have overlooked, I would very much like to hear about it. But as far as I can tell it is not possible to manage a resource in LiveView <em>at all</em>.</p>
<p>“Allocate the resource and then never free it” <strong>is not a solution to this problem</strong>. Freeing the resource by terminating the LiveView process is <em>also</em> not a solution to this problem, as I have now demonstrated three separate times.</p>
<p>This does not mean I take any issue with either of you suggesting the filtering trick. It’s relevant! It just doesn’t solve the problem.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380583" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-380583" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380583"
                     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="380584" data-post-id="380584">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="tfwright" data-post="13" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/48/20299_2.png" class="avatar"> tfwright:</div>
<blockquote>
<p>From what you’ve written elsewhere I would guess your real gripe is with the design of LiveView itself in view of its ability (or lack of it) to elegantly handle the problems most web apps eventually face</p>
</blockquote>
</aside>
<p>I have gripes with everything. LiveView is fine.</p>
<p>In this case, the low-hanging-fruit solution would be to add an <code>unmount</code> callback to LiveViews and LiveComponents. Note that I did not advocate for this in my first reply (which was days ago), but I have since thought about it more and I think clearly an <code>unmount</code> is just fundamentally necessary.</p>
<p>I strongly disagree that this is off-topic.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380584" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-380584" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380584"
                     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 #14"></div>
  </section>
</div>
    <div class="postbit" id="380588" data-post-id="380588">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="garrison" data-post="12" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<ul>
<li>Clicks on a link to <code>/settings</code> which mounts the <code>Settings</code> LV in the same process</li>
</ul>
<p>The <code>Settings</code> LiveView now receives product updates.</p>
</blockquote>
</aside>
<p>Navigating between LiveViews starts a new process. Any subscription a previous LV had are gone as part of the BEAM process model.</p>
<p>The only kind of navigation within the same process is live patch (which is probably the wrong design choice for navigating between different product pages).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380588" data-batch-url="/posts/batch_likers">
                        3
                      </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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-380588" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380588"
                     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 #15"></div>
  </section>
</div>
    <div class="postbit" id="380590" data-post-id="380590">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="garrison" data-post="15" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>I strongly disagree that this is off-topic.</p>
</blockquote>
</aside>
<p>OK, yeah maybe that’s too strong given LV is in the OP, but I do think a general discussion about what features LV doesn’t have or should have is at best tangential to actually answer the question which is about how to use the tools it does have.</p>
<p>An added complication is that I think this is an XY problem because with the filtering strategy you don’t care about the lifecycle at all because the subscription no longer needs to be managed. When the product page live view is running, it’s receiving product events. The handler will sort out what to do with them (if anything). Still not sure about your complaints with that suggestion.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380590" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-380590" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380590"
                     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="380591" data-post-id="380591">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Oh, does it? My bad, I thought it remounted in the same process, but you’re probably right. Fortunately that example is not load-bearing because this problem is still exhibited everywhere else. I was just trying to find something that was irrefutable even in the simplest possible case.</p>
<aside class="quote no-group" data-username="rhcarvalho" data-post="16" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/rhcarvalho/48/32243_2.png" class="avatar"> rhcarvalho:</div>
<blockquote>
<p>The only kind of navigation within the same process is live patch (which is probably the wrong design choice for navigating between different product pages)</p>
</blockquote>
</aside>
<p>And yet:</p>
<aside class="quote no-group quote-modified" data-username="longnightElixir" data-post="1" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/longnightelixir/48/32051_2.png" class="avatar"> longnightElixir:</div>
<blockquote>
<p>Users navigate between <code>/product/product_a_id</code> and <code> /product/product_b_id</code> , and more ;<br>
these routers are in the same liveview</p>
</blockquote>
</aside>
<p>But really, I disagree that this is a bad idea. Actually doing everything within one LiveView is a great idea. There is no reason to reload all of the parts of the page that are shared between products (discarding all state in the process). The whole point of LiveView is that it’s supposed to be richer than a regular HTML page!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380591" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-380591" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380591"
                     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="380593" data-post-id="380593">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="tfwright" data-post="17" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/48/20299_2.png" class="avatar"> tfwright:</div>
<blockquote>
<p>An added complication is that I think this is an XY problem because with the filtering strategy you don’t care about the lifecycle at all because the subscription no longer needs to be managed.</p>
</blockquote>
</aside>
<p>You’re right, but the problem is that <em>you</em> think it’s an XY problem and <em>I</em> happen to think the OP’s approach is actually correct.</p>
<aside class="quote no-group" data-username="tfwright" data-post="17" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/48/20299_2.png" class="avatar"> tfwright:</div>
<blockquote>
<p>Still not sure about your complaints with that suggestion.</p>
</blockquote>
</aside>
<p>Again, there’s nothing <em>wrong</em> with doing the filtering thing. It’s just that the question from the OP, “how do I manage resources”, is going to come back anyway. Honestly, I tried pretty hard to explain it, but maybe there is no substitute for suffering through this yourself. I have been through that many times, where I thought others were just over-complicating things until I actually felt enough pain to understand the justification.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380593" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-380593" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380593"
                     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="380597" data-post-id="380597">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="garrison" data-post="19" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/g/3bc359/48.png" class="avatar"> garrison:</div>
<blockquote>
<p>Honestly, I tried pretty hard to explain it, but maybe there is no substitute for suffering through this yourself.</p>
</blockquote>
</aside>
<p>Except I am not the only one in this thread pointing out that it doesn’t necessarily involve any “suffering” at all. It works fine, except in the hypothetical scenarios you introduced. I guess I just don’t find them convincing. Whatever approach you take to designing your topics, there are going to be places where they need to be filtered, unless you decide to have a topic for every single client’s use case. So it’s really just about finding the balance between the number of topics that need subscriptions, and the number of events that will be pushed to each topic, based on <em>known use cases.</em> The issue of managing resources may or may not come back, but not because of OPs problem.</p>
<p>But even this is off topic at this point, because it’s since been pointed out that the real XY problem is that a new LV process <em>should</em> be mounting for each product anyway, so I’ll leave it there.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380597" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-380597" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380597"
                     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="380601" data-post-id="380601">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="tfwright" data-post="20" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/48/20299_2.png" class="avatar"> tfwright:</div>
<blockquote>
<p>Whatever approach you take to designing your topics, there are going to be places where they need to be filtered</p>
</blockquote>
</aside>
<p>I can only agree with you on this claim so many times lol. A further point in your favor here: due to consistency problems with PubSub, you are going to have to filter the messages anyway! This does not, however, contradict my points in any way.</p>
<aside class="quote no-group" data-username="tfwright" data-post="20" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/48/20299_2.png" class="avatar"> tfwright:</div>
<blockquote>
<p>So it’s really just about finding the balance between the number of topics that need subscriptions</p>
</blockquote>
</aside>
<p>Yes! And unless the number of topics happens to be <em>exactly one</em>, an uncommon case, we have invented the OP’s question from first principles.</p>
<aside class="quote no-group" data-username="tfwright" data-post="20" data-topic="73715">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/48/20299_2.png" class="avatar"> tfwright:</div>
<blockquote>
<p>But even this is off topic at this point, because it’s since been pointed out that the real XY problem is that a new LV process <em>should</em> be mounting for each product anyway</p>
</blockquote>
</aside>
<p>Okay, imagine you have literally any other component on the page. A search bar, a sidebar with filters, literally anything at all. You click on another product and the state of every other control on the page gets reset. This is a common annoyance of web applications.</p>
<p>LiveView is useful specifically because it <em>can</em> handle this, in Elixir, with no client rendering. That is the value proposition!</p>
<p>What is frustrating to me here is that the OP has the right idea, and is doing the right thing, and all of you are telling them “you’re holding it wrong”. They are not!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="380601" 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/are-there-elegant-ways-to-sub-unsub-when-user-navigated-between-routers-in-same-liveview/73715/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-380601" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="380601"
                     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/73715/load_more?page=3">Load more posts (12 remaining)</a>
</div></template></turbo-stream>