From d57d68116ee8e5af583ef0bb1f87cf3f40d2b845 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Thu, 20 Feb 2025 17:21:18 -0500
Subject: Let Svelte's `$derived` handling figure out update ordering for the
 channels list.

This fixes a bug. To reproduce:

1. Open the client and log in.
2. Create a new channel using the `create channel` UI.

The expected result - and the behaviour after this commit - is that the newly-created channel will be shown in the sidebar immediately. The buggy behaviour is that it was not, but would appear in the sidebar once the client is reloaded. The channel would also not appear for other clients until they reloaded.

I'm not actually completely sure of _why_ this fixes the bug, but it does.
---
 ui/routes/(app)/+layout.svelte | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

(limited to 'ui/routes/(app)/+layout.svelte')

diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte
index cbfef54..3752bef 100644
--- a/ui/routes/(app)/+layout.svelte
+++ b/ui/routes/(app)/+layout.svelte
@@ -19,14 +19,8 @@
   let loading = $state(true);
   let channel = $derived($page.params.channel);
 
-  let rawChannels;
-  channelsList.subscribe((val) => {
-    rawChannels = val.channels;
-  });
-  let rawMessages;
-  messages.subscribe((val) => {
-    rawMessages = val;
-  });
+  let rawChannels = $derived($channelsList.channels);
+  let rawMessages = $derived($messages);
 
   let enrichedChannels = $derived.by(() => {
     const channels = rawChannels;
-- 
cgit v1.2.3

