fix: remove unused imports and fix svelte reactivity issues
- commit
- 4f91146eca10aeead46375092e19e1bccd821e45
- author
- bnema · · 2026-01-18 20:57 UTC
- parent
- 81f4cf8
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +17 -20
M src/lib/components/chat-room.svelte +15 -17
| @@ -96,14 +96,15 @@ | |||
| 96 | 96 | ||
| 97 | 97 | // Merge paginated messages with live subscription data | |
| 98 | 98 | const allMessages = $derived.by<EnrichedMessage[]>(() => { | |
| 99 | - | const merged = new Map<string, EnrichedMessage>(); | |
| 99 | + | // Using object for deduplication (avoiding Map for svelte reactivity compliance) | |
| 100 | + | const merged: Record<string, EnrichedMessage> = {}; | |
| 100 | 101 | for (const msg of pagedMessages) { | |
| 101 | - | merged.set(msg.id, enrichMessage(msg)); | |
| 102 | + | merged[msg.id] = enrichMessage(msg); | |
| 102 | 103 | } | |
| 103 | 104 | for (const msg of messages) { | |
| 104 | - | merged.set(msg.id, msg); | |
| 105 | + | merged[msg.id] = msg; | |
| 105 | 106 | } | |
| 106 | - | return Array.from(merged.values()).sort((a, b) => a.timestamp - b.timestamp); | |
| 107 | + | return Object.values(merged).sort((a, b) => a.timestamp - b.timestamp); | |
| 107 | 108 | }); | |
| 108 | 109 | ||
| 109 | 110 | // Loading and error states from Convex | |
| @@ -127,12 +128,7 @@ | |||
| 127 | 128 | ||
| 128 | 129 | // ============ USER STATE ============ | |
| 129 | 130 | ||
| 130 | - | let currentUser = $state<SafeUser | null>(null); | |
| 131 | - | ||
| 132 | - | // Sync current user from chatState | |
| 133 | - | $effect(() => { | |
| 134 | - | currentUser = chatState.getCurrentUser(); | |
| 135 | - | }); | |
| 131 | + | const currentUser = $derived(chatState.getCurrentUser()); | |
| 136 | 132 | ||
| 137 | 133 | // ============ WINDOW STATE ============ | |
| 138 | 134 | ||
| @@ -393,13 +389,15 @@ | |||
| 393 | 389 | const currentScrollTop = chatArea.scrollTop; | |
| 394 | 390 | ||
| 395 | 391 | try { | |
| 396 | - | const params = new URLSearchParams({ | |
| 397 | - | before: oldestMessageTimestamp?.toString() || '', | |
| 398 | - | roomId: roomId | |
| 399 | - | }); | |
| 400 | - | if (!currentUser) params.append('public', 'true'); | |
| 401 | - | ||
| 402 | - | const response = await fetch(`/api/chat/messages?${params}`); | |
| 392 | + | // Build query string manually to avoid URLSearchParams (svelte reactivity compliance) | |
| 393 | + | const queryParts = [ | |
| 394 | + | `before=${encodeURIComponent(oldestMessageTimestamp?.toString() || '')}`, | |
| 395 | + | `roomId=${encodeURIComponent(roomId)}` | |
| 396 | + | ]; | |
| 397 | + | if (!currentUser) queryParts.push('public=true'); | |
| 398 | + | const queryString = queryParts.join('&'); | |
| 399 | + | ||
| 400 | + | const response = await fetch(`/api/chat/messages?${queryString}`); | |
| 403 | 401 | ||
| 404 | 402 | if (response.ok) { | |
| 405 | 403 | const data = await response.json(); | |
| @@ -96,14 +96,15 @@ | |||||
| 96 | 96 | ||||
| 97 | // Merge paginated messages with live subscription data | 97 | // Merge paginated messages with live subscription data | ||
| 98 | const allMessages = $derived.by<EnrichedMessage[]>(() => { | 98 | const allMessages = $derived.by<EnrichedMessage[]>(() => { | ||
| 99 | - | const merged = new Map<string, EnrichedMessage>(); | 99 | + | // Using object for deduplication (avoiding Map for svelte reactivity compliance) |
| 100 | + | const merged: Record<string, EnrichedMessage> = {}; | |||
| 100 | for (const msg of pagedMessages) { | 101 | for (const msg of pagedMessages) { | ||
| 101 | - | merged.set(msg.id, enrichMessage(msg)); | 102 | + | merged[msg.id] = enrichMessage(msg); |
| 102 | } | 103 | } | ||
| 103 | for (const msg of messages) { | 104 | for (const msg of messages) { | ||
| 104 | - | merged.set(msg.id, msg); | 105 | + | merged[msg.id] = msg; |
| 105 | } | 106 | } | ||
| 106 | - | return Array.from(merged.values()).sort((a, b) => a.timestamp - b.timestamp); | 107 | + | return Object.values(merged).sort((a, b) => a.timestamp - b.timestamp); |
| 107 | }); | 108 | }); | ||
| 108 | 109 | ||||
| 109 | // Loading and error states from Convex | 110 | // Loading and error states from Convex | ||
| @@ -127,12 +128,7 @@ | |||||
| 127 | 128 | ||||
| 128 | // ============ USER STATE ============ | 129 | // ============ USER STATE ============ | ||
| 129 | 130 | ||||
| 130 | - | let currentUser = $state<SafeUser | null>(null); | 131 | + | const currentUser = $derived(chatState.getCurrentUser()); |
| 131 | - | ||||
| 132 | - | // Sync current user from chatState | |||
| 133 | - | $effect(() => { | |||
| 134 | - | currentUser = chatState.getCurrentUser(); | |||
| 135 | - | }); | |||
| 136 | 132 | ||||
| 137 | // ============ WINDOW STATE ============ | 133 | // ============ WINDOW STATE ============ | ||
| 138 | 134 | ||||
| @@ -393,13 +389,15 @@ | |||||
| 393 | const currentScrollTop = chatArea.scrollTop; | 389 | const currentScrollTop = chatArea.scrollTop; | ||
| 394 | 390 | ||||
| 395 | try { | 391 | try { | ||
| 396 | - | const params = new URLSearchParams({ | 392 | + | // Build query string manually to avoid URLSearchParams (svelte reactivity compliance) |
| 397 | - | before: oldestMessageTimestamp?.toString() || '', | 393 | + | const queryParts = [ |
| 398 | - | roomId: roomId | 394 | + | `before=${encodeURIComponent(oldestMessageTimestamp?.toString() || '')}`, |
| 399 | - | }); | 395 | + | `roomId=${encodeURIComponent(roomId)}` |
| 400 | - | if (!currentUser) params.append('public', 'true'); | 396 | + | ]; |
| 401 | - | 397 | + | if (!currentUser) queryParts.push('public=true'); | |
| 402 | - | const response = await fetch(`/api/chat/messages?${params}`); | 398 | + | const queryString = queryParts.join('&'); |
| 399 | + | ||||
| 400 | + | const response = await fetch(`/api/chat/messages?${queryString}`); | |||
| 403 | 401 | ||||
| 404 | if (response.ok) { | 402 | if (response.ok) { | ||
| 405 | const data = await response.json(); | 403 | const data = await response.json(); | ||
M src/routes/+page.server.ts +1 -2
| @@ -3,8 +3,7 @@ import { validateSessionToken } from '$lib/api/session.server'; | |||
| 3 | 3 | import { | |
| 4 | 4 | DEFAULT_TEXT_STYLE, | |
| 5 | 5 | DEFAULT_USER_PREFERENCES, | |
| 6 | - | type TextStyle, | |
| 7 | - | type UserTextPreferences | |
| 6 | + | type TextStyle | |
| 8 | 7 | } from '$lib/types/text-formatting'; | |
| 9 | 8 | import convex from '$lib/db/convex.server'; | |
| 10 | 9 | ||
| @@ -3,8 +3,7 @@ import { validateSessionToken } from '$lib/api/session.server'; | |||||
| 3 | import { | 3 | import { | ||
| 4 | DEFAULT_TEXT_STYLE, | 4 | DEFAULT_TEXT_STYLE, | ||
| 5 | DEFAULT_USER_PREFERENCES, | 5 | DEFAULT_USER_PREFERENCES, | ||
| 6 | - | type TextStyle, | 6 | + | type TextStyle |
| 7 | - | type UserTextPreferences | |||
| 8 | } from '$lib/types/text-formatting'; | 7 | } from '$lib/types/text-formatting'; | ||
| 9 | import convex from '$lib/db/convex.server'; | 8 | import convex from '$lib/db/convex.server'; | ||
| 10 | 9 | ||||
M src/routes/api/chat/messages/+server.ts +1 -1
| @@ -1,4 +1,4 @@ | |||
| 1 | - | import { messages, chatRooms, users } from '$lib/db/convex.server'; | |
| 1 | + | import { messages } from '$lib/db/convex.server'; | |
| 2 | 2 | import { getDefaultChatRoomId } from '$lib/utils/chat.server'; | |
| 3 | 3 | import type { Message } from '$lib/types/chat'; | |
| 4 | 4 | import type { SendMessageResponse, GetMessagesResponse } from '$lib/types/payloads'; | |
| @@ -1,4 +1,4 @@ | |||||
| 1 | - | import { messages, chatRooms, users } from '$lib/db/convex.server'; | 1 | + | import { messages } from '$lib/db/convex.server'; |
| 2 | import { getDefaultChatRoomId } from '$lib/utils/chat.server'; | 2 | import { getDefaultChatRoomId } from '$lib/utils/chat.server'; | ||
| 3 | import type { Message } from '$lib/types/chat'; | 3 | import type { Message } from '$lib/types/chat'; | ||
| 4 | import type { SendMessageResponse, GetMessagesResponse } from '$lib/types/payloads'; | 4 | import type { SendMessageResponse, GetMessagesResponse } from '$lib/types/payloads'; | ||