nucleus-core-ts 0.9.169 → 0.9.171
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fe/components/ChatPanel/components/ChatPanel.js +1 -1
- package/dist/fe/components/ChatPanel/hooks/useChat.js +21 -8
- package/dist/fe/components/ChatPanel/theme/index.d.ts +2 -2
- package/dist/fe/components/ChatPanel/theme/index.js +2 -2
- package/dist/index.js +5 -5
- package/dist/src/Client/PubSub/usePubSub.js +219 -209
- package/package.json +1 -1
|
@@ -19,7 +19,8 @@ function previewFor(message) {
|
|
|
19
19
|
export function useChat(props) {
|
|
20
20
|
const { currentUserId, actions, topic = 'chat', wsUrl, wsPath } = props;
|
|
21
21
|
const store = useChatStore();
|
|
22
|
-
const
|
|
22
|
+
const lastSeenEventIdRef = useRef(null);
|
|
23
|
+
const eventsInitializedRef = useRef(false);
|
|
23
24
|
const typingSentAtRef = useRef(0);
|
|
24
25
|
const pubsub = usePubSub({
|
|
25
26
|
userId: currentUserId,
|
|
@@ -244,17 +245,29 @@ export function useChat(props) {
|
|
|
244
245
|
useEffect(()=>{
|
|
245
246
|
loadConversations();
|
|
246
247
|
}, []);
|
|
248
|
+
// The pubsub store PREPENDS events (newest at index 0) and caps the buffer,
|
|
249
|
+
// so index/count tracking is unsafe. Track the last-seen event id instead:
|
|
250
|
+
// collect everything newer than it (newest-first), then replay oldest-first.
|
|
251
|
+
// The initial mount skips the existing backlog — history loads via REST.
|
|
247
252
|
useEffect(()=>{
|
|
248
253
|
const events = pubsub.events;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
+
if (!eventsInitializedRef.current) {
|
|
255
|
+
eventsInitializedRef.current = true;
|
|
256
|
+
lastSeenEventIdRef.current = events[0]?.id ?? null;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const fresh = [];
|
|
260
|
+
for (const event of events){
|
|
261
|
+
if (event.id === lastSeenEventIdRef.current) break;
|
|
262
|
+
fresh.push(event);
|
|
263
|
+
}
|
|
264
|
+
lastSeenEventIdRef.current = events[0]?.id ?? lastSeenEventIdRef.current;
|
|
265
|
+
for(let i = fresh.length - 1; i >= 0; i--){
|
|
266
|
+
const event = fresh[i];
|
|
267
|
+
if (event.topic === topic) handleRealtime(event.data);
|
|
254
268
|
}
|
|
255
|
-
processedRef.current = events.length;
|
|
256
269
|
}, [
|
|
257
|
-
pubsub.events
|
|
270
|
+
pubsub.events[0]?.id
|
|
258
271
|
]);
|
|
259
272
|
return {
|
|
260
273
|
store,
|
|
@@ -21,11 +21,11 @@ export declare const chatPanelTheme: {
|
|
|
21
21
|
readonly badge: "ml-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-emerald-500 px-1.5 text-[11px] font-semibold text-white";
|
|
22
22
|
};
|
|
23
23
|
readonly thread: {
|
|
24
|
-
readonly base: "flex flex-1 flex-col";
|
|
24
|
+
readonly base: "flex min-h-0 flex-1 flex-col";
|
|
25
25
|
readonly header: "flex items-center gap-3 border-b border-zinc-200 px-5 py-3 dark:border-zinc-800";
|
|
26
26
|
readonly headerTitle: "text-sm font-semibold";
|
|
27
27
|
readonly headerSubtitle: "text-xs text-zinc-400";
|
|
28
|
-
readonly messages: "flex flex-1 flex-col gap-2 overflow-y-auto px-5 py-4";
|
|
28
|
+
readonly messages: "flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto px-5 py-4";
|
|
29
29
|
readonly loadMore: "mx-auto mb-2 rounded-full border border-zinc-200 px-3 py-1 text-xs text-zinc-500 transition hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900";
|
|
30
30
|
readonly empty: "flex flex-1 items-center justify-center text-sm text-zinc-400";
|
|
31
31
|
readonly placeholder: "flex flex-1 items-center justify-center px-6 text-center text-sm text-zinc-400";
|
|
@@ -20,11 +20,11 @@ export const chatPanelTheme = {
|
|
|
20
20
|
badge: 'ml-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-emerald-500 px-1.5 text-[11px] font-semibold text-white'
|
|
21
21
|
},
|
|
22
22
|
thread: {
|
|
23
|
-
base: 'flex flex-1 flex-col',
|
|
23
|
+
base: 'flex min-h-0 flex-1 flex-col',
|
|
24
24
|
header: 'flex items-center gap-3 border-b border-zinc-200 px-5 py-3 dark:border-zinc-800',
|
|
25
25
|
headerTitle: 'text-sm font-semibold',
|
|
26
26
|
headerSubtitle: 'text-xs text-zinc-400',
|
|
27
|
-
messages: 'flex flex-1 flex-col gap-2 overflow-y-auto px-5 py-4',
|
|
27
|
+
messages: 'flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto px-5 py-4',
|
|
28
28
|
loadMore: 'mx-auto mb-2 rounded-full border border-zinc-200 px-3 py-1 text-xs text-zinc-500 transition hover:bg-zinc-50 dark:border-zinc-800 dark:hover:bg-zinc-900',
|
|
29
29
|
empty: 'flex flex-1 items-center justify-center text-sm text-zinc-400',
|
|
30
30
|
placeholder: 'flex flex-1 items-center justify-center px-6 text-center text-sm text-zinc-400'
|