@flamingo-stack/openframe-frontend-core 0.0.521 → 0.0.522-snapshot.20260807100640
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/{chunk-6Q55DOM2.cjs → chunk-43QX3P4G.cjs} +3 -3
- package/dist/{chunk-6Q55DOM2.cjs.map → chunk-43QX3P4G.cjs.map} +1 -1
- package/dist/{chunk-R63KHYFN.js → chunk-7EYNWY2N.js} +2 -2
- package/dist/{chunk-Y3ES77KJ.js → chunk-7LSK5YFW.js} +2 -2
- package/dist/{chunk-XYVJKPUW.cjs → chunk-7RIYOJLG.cjs} +26 -26
- package/dist/{chunk-XYVJKPUW.cjs.map → chunk-7RIYOJLG.cjs.map} +1 -1
- package/dist/{chunk-ATN5CTEP.js → chunk-7ZIGB34Y.js} +6 -6
- package/dist/{chunk-NP62VGRO.js → chunk-ANKQQTAI.js} +4 -4
- package/dist/{chunk-VFYIFHJ3.js → chunk-BPBMHS4U.js} +2 -2
- package/dist/{chunk-WK5Z2Z5T.cjs → chunk-D3PPR2WR.cjs} +14 -14
- package/dist/{chunk-WK5Z2Z5T.cjs.map → chunk-D3PPR2WR.cjs.map} +1 -1
- package/dist/{chunk-5NQTT7D5.js → chunk-FP6HEAQC.js} +5 -5
- package/dist/{chunk-BSJAHSOO.cjs → chunk-H5TAFA4H.cjs} +4 -4
- package/dist/{chunk-BSJAHSOO.cjs.map → chunk-H5TAFA4H.cjs.map} +1 -1
- package/dist/{chunk-AAM6IP3G.cjs → chunk-HPGBHELQ.cjs} +7 -7
- package/dist/{chunk-AAM6IP3G.cjs.map → chunk-HPGBHELQ.cjs.map} +1 -1
- package/dist/{chunk-YJ4VCBRT.js → chunk-ICWQQQTR.js} +2 -2
- package/dist/{chunk-KSV7S3XR.cjs → chunk-J2OPY22M.cjs} +87 -87
- package/dist/{chunk-KSV7S3XR.cjs.map → chunk-J2OPY22M.cjs.map} +1 -1
- package/dist/{chunk-YPT3CBFR.cjs → chunk-JGYVXVN6.cjs} +61 -61
- package/dist/{chunk-YPT3CBFR.cjs.map → chunk-JGYVXVN6.cjs.map} +1 -1
- package/dist/{chunk-BFGMIDQN.cjs → chunk-JKUYXCG2.cjs} +9 -9
- package/dist/{chunk-BFGMIDQN.cjs.map → chunk-JKUYXCG2.cjs.map} +1 -1
- package/dist/{chunk-67R53SBT.cjs → chunk-KBE7SNFZ.cjs} +5 -5
- package/dist/{chunk-67R53SBT.cjs.map → chunk-KBE7SNFZ.cjs.map} +1 -1
- package/dist/{chunk-TXO7WK2L.js → chunk-L4DKYRHG.js} +2 -2
- package/dist/{chunk-KKQX7YWX.cjs → chunk-LJCBSJFU.cjs} +26 -26
- package/dist/{chunk-KKQX7YWX.cjs.map → chunk-LJCBSJFU.cjs.map} +1 -1
- package/dist/{chunk-GGHXEEYL.js → chunk-M45XIHZY.js} +2 -2
- package/dist/{chunk-TFUSHMTY.js → chunk-NBANPQ3N.js} +2 -2
- package/dist/{chunk-FHSZYVS5.js → chunk-NMZ33YWL.js} +4 -4
- package/dist/{chunk-FBK7CPXN.cjs → chunk-OGXZCZSA.cjs} +31 -31
- package/dist/{chunk-FBK7CPXN.cjs.map → chunk-OGXZCZSA.cjs.map} +1 -1
- package/dist/{chunk-7QEBK5ZY.js → chunk-OPU5BLBT.js} +2 -2
- package/dist/{chunk-RDGUBROF.cjs → chunk-PZVYYDFL.cjs} +37 -37
- package/dist/{chunk-RDGUBROF.cjs.map → chunk-PZVYYDFL.cjs.map} +1 -1
- package/dist/{chunk-AIVZKRDL.js → chunk-QBLLF7VS.js} +2 -2
- package/dist/{chunk-SX7V35WT.cjs → chunk-VYRP7JOD.cjs} +34 -8
- package/dist/chunk-VYRP7JOD.cjs.map +1 -0
- package/dist/{chunk-6AQKSCZ5.js → chunk-YJLQQGLH.js} +138 -112
- package/dist/{chunk-6AQKSCZ5.js.map → chunk-YJLQQGLH.js.map} +1 -1
- package/dist/{chunk-GAU637M2.cjs → chunk-ZIIIYUZ5.cjs} +11 -11
- package/dist/{chunk-GAU637M2.cjs.map → chunk-ZIIIYUZ5.cjs.map} +1 -1
- package/dist/components/case-studies/index.cjs +8 -8
- package/dist/components/case-studies/index.js +2 -2
- package/dist/components/chat/hooks/use-jetstream-dialog-subscription.d.ts +7 -1
- package/dist/components/chat/hooks/use-jetstream-dialog-subscription.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +4 -2
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +3 -1
- package/dist/components/chat/types/api.types.d.ts +22 -4
- package/dist/components/chat/types/api.types.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +3 -3
- package/dist/components/contact/index.js +2 -2
- package/dist/components/docs/index.cjs +5 -5
- package/dist/components/docs/index.js +4 -4
- package/dist/components/embeds/index.cjs +3 -3
- package/dist/components/embeds/index.js +2 -2
- package/dist/components/faq/index.cjs +3 -3
- package/dist/components/faq/index.js +2 -2
- package/dist/components/features/index.cjs +2 -2
- package/dist/components/features/index.js +1 -1
- package/dist/components/help-center-pages/index.cjs +22 -22
- package/dist/components/help-center-pages/index.js +13 -13
- package/dist/components/index.cjs +134 -132
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +13 -11
- package/dist/components/index.js.map +1 -1
- package/dist/components/meeting-scheduler/index.cjs +34 -34
- package/dist/components/meeting-scheduler/index.js +3 -3
- package/dist/components/navigation/index.cjs +2 -2
- package/dist/components/navigation/index.js +1 -1
- package/dist/components/onboarding-guides/index.cjs +5 -5
- package/dist/components/onboarding-guides/index.js +4 -4
- package/dist/components/related-content/index.cjs +3 -3
- package/dist/components/related-content/index.js +2 -2
- package/dist/components/tickets/index.cjs +6 -6
- package/dist/components/tickets/index.js +5 -5
- package/dist/components/ui/index.cjs +4 -2
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +3 -1
- package/dist/components/ui/tab-navigation.d.ts.map +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -1
- package/package.json +1 -1
- package/src/components/chat/hooks/.use-jetstream-dialog-subscription.md +11 -4
- package/src/components/chat/hooks/use-jetstream-dialog-subscription.ts +71 -6
- package/src/components/chat/types/api.types.ts +22 -4
- package/src/components/chat/utils/__tests__/history-merge.test.ts +99 -0
- package/src/components/ui/__tests__/tab-navigation.test.tsx +33 -1
- package/src/components/ui/tab-navigation.tsx +25 -8
- package/dist/chunk-SX7V35WT.cjs.map +0 -1
- /package/dist/{chunk-R63KHYFN.js.map → chunk-7EYNWY2N.js.map} +0 -0
- /package/dist/{chunk-Y3ES77KJ.js.map → chunk-7LSK5YFW.js.map} +0 -0
- /package/dist/{chunk-ATN5CTEP.js.map → chunk-7ZIGB34Y.js.map} +0 -0
- /package/dist/{chunk-NP62VGRO.js.map → chunk-ANKQQTAI.js.map} +0 -0
- /package/dist/{chunk-VFYIFHJ3.js.map → chunk-BPBMHS4U.js.map} +0 -0
- /package/dist/{chunk-5NQTT7D5.js.map → chunk-FP6HEAQC.js.map} +0 -0
- /package/dist/{chunk-YJ4VCBRT.js.map → chunk-ICWQQQTR.js.map} +0 -0
- /package/dist/{chunk-TXO7WK2L.js.map → chunk-L4DKYRHG.js.map} +0 -0
- /package/dist/{chunk-GGHXEEYL.js.map → chunk-M45XIHZY.js.map} +0 -0
- /package/dist/{chunk-TFUSHMTY.js.map → chunk-NBANPQ3N.js.map} +0 -0
- /package/dist/{chunk-FHSZYVS5.js.map → chunk-NMZ33YWL.js.map} +0 -0
- /package/dist/{chunk-7QEBK5ZY.js.map → chunk-OPU5BLBT.js.map} +0 -0
- /package/dist/{chunk-AIVZKRDL.js.map → chunk-QBLLF7VS.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useEffect, useRef, useState } from 'react'
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
4
4
|
import {
|
|
5
5
|
acquireClient as acquireSharedClient,
|
|
6
6
|
releaseClient as releaseSharedClient,
|
|
@@ -20,7 +20,24 @@ const DEFAULT_STREAM_NAME = 'CHAT_CHUNKS'
|
|
|
20
20
|
* absence worth resyncing for. Alt-tabbing must not churn the consumer; a
|
|
21
21
|
* window that sat in the tray must not come back showing a stale conversation.
|
|
22
22
|
*/
|
|
23
|
-
const RESYNC_AFTER_HIDDEN_MS = 10_000
|
|
23
|
+
export const RESYNC_AFTER_HIDDEN_MS = 10_000
|
|
24
|
+
/**
|
|
25
|
+
* How long resync requests are gathered before one is acted on.
|
|
26
|
+
*
|
|
27
|
+
* A single reveal can be reported twice: the page sees `visibilitychange`, and
|
|
28
|
+
* a host that knows the window was away reports it too (`resyncSignal`),
|
|
29
|
+
* neither able to tell whether the other noticed. Both land within a frame or
|
|
30
|
+
* two of each other, being driven by the same OS event, and acting on both
|
|
31
|
+
* rebuilds the consumer and refetches history twice for one reveal.
|
|
32
|
+
*
|
|
33
|
+
* Gathered on the TRAILING edge, so a request is deferred and never dropped.
|
|
34
|
+
* Two reports of one reveal collapse into one rebuild; two genuinely different
|
|
35
|
+
* signals — a notification reply landing just before the user opens the window
|
|
36
|
+
* — also collapse into one, which is correct, because a single refetch after
|
|
37
|
+
* the last of them covers both. The cost is a second of latency on a path whose
|
|
38
|
+
* next step is a network round trip.
|
|
39
|
+
*/
|
|
40
|
+
const RESYNC_COALESCE_MS = 1_000
|
|
24
41
|
/**
|
|
25
42
|
* Floor between two reported recoveries. Every recovery costs the caller a
|
|
26
43
|
* history refetch, and a consumer that cannot hold its sequence — gap, reset,
|
|
@@ -60,6 +77,7 @@ export function useJetStreamDialogSubscription({
|
|
|
60
77
|
clientConfig = {},
|
|
61
78
|
reconnectionBackoff,
|
|
62
79
|
inactiveThresholdMs,
|
|
80
|
+
resyncSignal = 0,
|
|
63
81
|
}: UseJetStreamDialogSubscriptionOptions): UseJetStreamDialogSubscriptionReturn {
|
|
64
82
|
const [isConnected, setIsConnected] = useState(false)
|
|
65
83
|
const [isSubscribed, setIsSubscribed] = useState(false)
|
|
@@ -73,6 +91,8 @@ export function useJetStreamDialogSubscription({
|
|
|
73
91
|
const [currentStreamSeq, setCurrentStreamSeq] = useState<number | null>(null)
|
|
74
92
|
|
|
75
93
|
const lastRecoveryReportRef = useRef(0)
|
|
94
|
+
const resyncTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
95
|
+
const lastResyncSignalRef = useRef(resyncSignal)
|
|
76
96
|
const clientRef = useRef<NatsClient | null>(null)
|
|
77
97
|
const subscriptionRef = useRef<JetStreamSubscriptionHandle | null>(null)
|
|
78
98
|
const highestStreamSeqRef = useRef<number | null>(null)
|
|
@@ -245,7 +265,26 @@ export function useJetStreamDialogSubscription({
|
|
|
245
265
|
// ignoring optStartSeq).
|
|
246
266
|
useEffect(() => {
|
|
247
267
|
highestStreamSeqRef.current = null
|
|
268
|
+
// A host's signal counts per dialog (it can carry a per-conversation term),
|
|
269
|
+
// so the baseline has to move with the dialog or a switch to one with a
|
|
270
|
+
// LOWER count would swallow every later resync for it.
|
|
271
|
+
lastResyncSignalRef.current = resyncSignal
|
|
248
272
|
setCurrentStreamSeq(null)
|
|
273
|
+
// A resync gathered for the previous dialog must not land on this one: the
|
|
274
|
+
// counter says nothing about which conversation it meant, so callers would
|
|
275
|
+
// refetch the wrong one. The dialog change supersedes it — the new dialog
|
|
276
|
+
// loads its own history regardless. As cleanup, so it covers unmount too,
|
|
277
|
+
// which is the same rule.
|
|
278
|
+
return () => {
|
|
279
|
+
if (resyncTimerRef.current !== null) {
|
|
280
|
+
clearTimeout(resyncTimerRef.current)
|
|
281
|
+
resyncTimerRef.current = null
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// `resyncSignal` is read as the new baseline, not depended on: reacting to
|
|
285
|
+
// it here would reset the baseline on the very change meant to trigger a
|
|
286
|
+
// resync, and the effect below owns that.
|
|
287
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
249
288
|
}, [dialogId])
|
|
250
289
|
|
|
251
290
|
// Coming back into view after a real absence is treated exactly like a
|
|
@@ -256,8 +295,20 @@ export function useJetStreamDialogSubscription({
|
|
|
256
295
|
// report that: the tail simply stays quiet, and the conversation on screen
|
|
257
296
|
// stays frozen at whatever was there when the window went away (the user's
|
|
258
297
|
// manual fix is a page refresh, which is exactly the history refetch this
|
|
259
|
-
// triggers).
|
|
260
|
-
//
|
|
298
|
+
// triggers). Rebuilds the consumer from the last sequence seen AND tells
|
|
299
|
+
// callers to refetch history.
|
|
300
|
+
//
|
|
301
|
+
// Every source funnels through here (see `RESYNC_COALESCE_MS`). Restarting
|
|
302
|
+
// the timer rather than dropping is what makes that safe: a request is only
|
|
303
|
+
// ever folded into the one that follows it, never discarded.
|
|
304
|
+
const requestResync = useCallback(() => {
|
|
305
|
+
if (resyncTimerRef.current !== null) clearTimeout(resyncTimerRef.current)
|
|
306
|
+
resyncTimerRef.current = setTimeout(() => {
|
|
307
|
+
resyncTimerRef.current = null
|
|
308
|
+
setReconnectionCount((c) => c + 1)
|
|
309
|
+
}, RESYNC_COALESCE_MS)
|
|
310
|
+
}, [])
|
|
311
|
+
|
|
261
312
|
useEffect(() => {
|
|
262
313
|
if (!enabled) return
|
|
263
314
|
let hiddenSince = document.visibilityState === 'hidden' ? Date.now() : 0
|
|
@@ -270,13 +321,27 @@ export function useJetStreamDialogSubscription({
|
|
|
270
321
|
const awayMs = hiddenSince === 0 ? 0 : Date.now() - hiddenSince
|
|
271
322
|
hiddenSince = 0
|
|
272
323
|
if (awayMs >= RESYNC_AFTER_HIDDEN_MS) {
|
|
273
|
-
|
|
324
|
+
requestResync()
|
|
274
325
|
}
|
|
275
326
|
}
|
|
276
327
|
|
|
277
328
|
document.addEventListener('visibilitychange', onVisibilityChange)
|
|
278
329
|
return () => document.removeEventListener('visibilitychange', onVisibilityChange)
|
|
279
|
-
}, [enabled])
|
|
330
|
+
}, [enabled, requestResync])
|
|
331
|
+
|
|
332
|
+
useEffect(() => {
|
|
333
|
+
// Held, not consumed, while disabled: it fires once on enable instead.
|
|
334
|
+
// A host reports a signal against the conversation, not against this hook's
|
|
335
|
+
// readiness, so one arriving while the caller is still assembling the
|
|
336
|
+
// subscription describes a gap in the history the caller is fetching right
|
|
337
|
+
// now. Dropping it would leave that fetch's result stale with nothing left
|
|
338
|
+
// to say so.
|
|
339
|
+
if (!enabled) return
|
|
340
|
+
// The mount value is a baseline, not a signal.
|
|
341
|
+
if (resyncSignal <= lastResyncSignalRef.current) return
|
|
342
|
+
lastResyncSignalRef.current = resyncSignal
|
|
343
|
+
requestResync()
|
|
344
|
+
}, [enabled, resyncSignal, requestResync])
|
|
280
345
|
|
|
281
346
|
// Subscription lifecycle: (re)create the ephemeral JetStream consumer whenever
|
|
282
347
|
// we transition into a connected state for a dialog, and whenever the dialog
|
|
@@ -131,6 +131,22 @@ export interface UseJetStreamDialogSubscriptionOptions {
|
|
|
131
131
|
/** Consumer inactivity threshold in ms before NATS auto-cleans it. Defaults to the
|
|
132
132
|
* client's, and applies only to the first consumer — recreations use nats.ws's. */
|
|
133
133
|
inactiveThresholdMs?: number
|
|
134
|
+
/**
|
|
135
|
+
* A counter the host bumps when it knows, from outside the page, that the tail
|
|
136
|
+
* may have missed something.
|
|
137
|
+
*
|
|
138
|
+
* The hook's own detector is `visibilitychange`, which a browser tab reports
|
|
139
|
+
* honestly and an embedding shell may not — and which says nothing at all
|
|
140
|
+
* about a write made on the page's behalf while it was away. A host holding
|
|
141
|
+
* either kind of knowledge bumps this instead of hoping the page noticed.
|
|
142
|
+
*
|
|
143
|
+
* Treated exactly like a reconnect: the consumer is rebuilt from the highest
|
|
144
|
+
* sequence already seen, and `reconnectionCount` moves so callers refetch
|
|
145
|
+
* persisted history. Any increase counts; the value itself means nothing, and
|
|
146
|
+
* an increase arriving alongside a `visibilitychange` costs one rebuild, not
|
|
147
|
+
* two.
|
|
148
|
+
*/
|
|
149
|
+
resyncSignal?: number
|
|
134
150
|
}
|
|
135
151
|
|
|
136
152
|
export interface UseJetStreamDialogSubscriptionReturn {
|
|
@@ -138,10 +154,12 @@ export interface UseJetStreamDialogSubscriptionReturn {
|
|
|
138
154
|
isSubscribed: boolean
|
|
139
155
|
/**
|
|
140
156
|
* Incremented each time the live tail is re-established: a NATS reconnect, a
|
|
141
|
-
* JetStream ordered-consumer recreation,
|
|
142
|
-
* being hidden long enough to have missed something
|
|
143
|
-
*
|
|
144
|
-
* history has to be
|
|
157
|
+
* JetStream ordered-consumer recreation, the page returning to view after
|
|
158
|
+
* being hidden long enough to have missed something, or a host reporting the
|
|
159
|
+
* same via `resyncSignal`. All of them mean the same thing to the caller —
|
|
160
|
+
* the tail may have skipped messages, so persisted history has to be
|
|
161
|
+
* refetched. One absence counts once even when two sources report it.
|
|
162
|
+
* Starts at 0.
|
|
145
163
|
*/
|
|
146
164
|
reconnectionCount: number
|
|
147
165
|
/** Highest JetStream stream sequence observed so far (null before first delivery). */
|
|
@@ -930,3 +930,102 @@ describe('mid-stream refetch (turn partially persisted)', () => {
|
|
|
930
930
|
expect(ids(merged)).toEqual([U0.id, A0.id, PERSISTED_PARTIAL.id, unrelatedLive.id])
|
|
931
931
|
})
|
|
932
932
|
})
|
|
933
|
+
|
|
934
|
+
describe('ordering of surviving realtime messages', () => {
|
|
935
|
+
// The merge concatenates: all persisted history, then every realtime message
|
|
936
|
+
// the coverage rules kept, each side in its own order. These pin that
|
|
937
|
+
// contract, which nothing asserted before — the suite tested only WHICH
|
|
938
|
+
// messages survive, never where they land — and which an attempt to
|
|
939
|
+
// chronologically interleave the two sides repeatedly broke.
|
|
940
|
+
const H_U0: TestMessage = { ...U0, streamSeq: 5 }
|
|
941
|
+
const H_A0: TestMessage = { ...A0, streamSeq: 10 }
|
|
942
|
+
/**
|
|
943
|
+
* Sent from a notification while the window was away, and persisted. NO
|
|
944
|
+
* `streamSeq`: the backend does not stamp user MESSAGE_REQUEST rows, which is
|
|
945
|
+
* the missing signal that makes interleaving guesswork.
|
|
946
|
+
*/
|
|
947
|
+
const AWAY_U: TestMessage = {
|
|
948
|
+
id: 'bbbb0001',
|
|
949
|
+
role: 'user',
|
|
950
|
+
content: 'replied from a notification',
|
|
951
|
+
timestamp: t(3000),
|
|
952
|
+
}
|
|
953
|
+
/** Mingo's answer to it. Assistant rows DO carry a sequence. */
|
|
954
|
+
const AWAY_A: TestMessage = {
|
|
955
|
+
id: 'bbbb0002',
|
|
956
|
+
role: 'assistant',
|
|
957
|
+
content: txt('answered while the window was away'),
|
|
958
|
+
timestamp: t(3100),
|
|
959
|
+
streamSeq: 80,
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
it('appends surviving realtime messages after all persisted history', () => {
|
|
963
|
+
// A technician direct message the snapshot has not caught up with. Its own
|
|
964
|
+
// role's persisted max (H_U0, seq 5) is below it, so coverage keeps it.
|
|
965
|
+
const unpersistedDirect: TestMessage = {
|
|
966
|
+
id: 'direct-1500-old',
|
|
967
|
+
role: 'user',
|
|
968
|
+
content: 'a direct message history has not persisted yet',
|
|
969
|
+
timestamp: t(1500),
|
|
970
|
+
streamSeq: 40,
|
|
971
|
+
}
|
|
972
|
+
const merged = mergeHistoryWithRealtime({
|
|
973
|
+
processedHistory: [H_U0, H_A0, AWAY_U, AWAY_A],
|
|
974
|
+
existingMessages: [H_U0, H_A0, unpersistedDirect],
|
|
975
|
+
streamingMessageId: null,
|
|
976
|
+
historyFetchedAt: 9000,
|
|
977
|
+
historyMaxStreamSeq: 80,
|
|
978
|
+
realtimeSeenStreamSeq: 40,
|
|
979
|
+
})
|
|
980
|
+
|
|
981
|
+
expect(ids(merged)).toEqual([H_U0.id, H_A0.id, AWAY_U.id, AWAY_A.id, unpersistedDirect.id])
|
|
982
|
+
})
|
|
983
|
+
|
|
984
|
+
it('keeps survivors in store order, sequence or no sequence', () => {
|
|
985
|
+
// The guard against reordering the two kinds against each other: an
|
|
986
|
+
// optimistic bubble carries no sequence and a replayed direct message does,
|
|
987
|
+
// and sorting by sequence would render the user's question below the reply
|
|
988
|
+
// that came after it.
|
|
989
|
+
const optimistic: TestMessage = {
|
|
990
|
+
id: 'optimistic-9400-x',
|
|
991
|
+
role: 'user',
|
|
992
|
+
content: 'just typed, no seq of its own',
|
|
993
|
+
timestamp: t(9400),
|
|
994
|
+
}
|
|
995
|
+
const laterDirect: TestMessage = {
|
|
996
|
+
id: 'direct-9500-x',
|
|
997
|
+
role: 'user',
|
|
998
|
+
content: 'and a direct message after it',
|
|
999
|
+
timestamp: t(9500),
|
|
1000
|
+
streamSeq: 40,
|
|
1001
|
+
}
|
|
1002
|
+
const merged = mergeHistoryWithRealtime({
|
|
1003
|
+
processedHistory: [H_U0, H_A0, AWAY_U, AWAY_A],
|
|
1004
|
+
existingMessages: [H_U0, H_A0, optimistic, laterDirect],
|
|
1005
|
+
streamingMessageId: null,
|
|
1006
|
+
// Before either was minted, so neither can be in the snapshot.
|
|
1007
|
+
historyFetchedAt: 9000,
|
|
1008
|
+
historyMaxStreamSeq: 80,
|
|
1009
|
+
realtimeSeenStreamSeq: 40,
|
|
1010
|
+
})
|
|
1011
|
+
|
|
1012
|
+
expect(ids(merged)).toEqual([H_U0.id, H_A0.id, AWAY_U.id, AWAY_A.id, optimistic.id, laterDirect.id])
|
|
1013
|
+
})
|
|
1014
|
+
|
|
1015
|
+
it('keeps history in snapshot order even when its sequences do not climb', () => {
|
|
1016
|
+
// The snapshot is the server's account of the conversation; the merge is
|
|
1017
|
+
// not entitled to second-guess it from a `streamSeq` that looks out of
|
|
1018
|
+
// order, which is what any sort of the two sides together would do.
|
|
1019
|
+
const outOfOrder: TestMessage = { ...H_A0, id: 'aaaa0009', streamSeq: 3 }
|
|
1020
|
+
const merged = mergeHistoryWithRealtime({
|
|
1021
|
+
processedHistory: [H_U0, outOfOrder, AWAY_U, AWAY_A],
|
|
1022
|
+
existingMessages: [H_U0],
|
|
1023
|
+
streamingMessageId: null,
|
|
1024
|
+
historyFetchedAt: 9000,
|
|
1025
|
+
historyMaxStreamSeq: 80,
|
|
1026
|
+
realtimeSeenStreamSeq: 0,
|
|
1027
|
+
})
|
|
1028
|
+
|
|
1029
|
+
expect(ids(merged)).toEqual([H_U0.id, outOfOrder.id, AWAY_U.id, AWAY_A.id])
|
|
1030
|
+
})
|
|
1031
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, it, expect, beforeAll } from 'vitest'
|
|
1
|
+
import { describe, it, expect, beforeAll, vi } from 'vitest'
|
|
2
2
|
import { render, fireEvent, screen } from '@testing-library/react'
|
|
3
3
|
import { mockReplace, setMockSearchParams } from '../../../../vitest.setup'
|
|
4
4
|
import { TabNavigation, type TabItem } from '../tab-navigation'
|
|
@@ -156,4 +156,36 @@ describe('TabNavigation with urlSync', () => {
|
|
|
156
156
|
expect(nav.active).toBe('general')
|
|
157
157
|
})
|
|
158
158
|
})
|
|
159
|
+
describe('the underline', () => {
|
|
160
|
+
it('is sized in real pixels rather than a scaled 1px bar', () => {
|
|
161
|
+
// Regression guard. The underline used to be `w-px` stretched with
|
|
162
|
+
// `scaleX(width)`, which is only exact when one CSS pixel lands on a whole
|
|
163
|
+
// device pixel. At 125%/150% OS scaling or any browser zoom the base is
|
|
164
|
+
// rasterized to the nearest whole device pixel and `scaleX` multiplies
|
|
165
|
+
// that rounding by the tab's width, so the bar rendered visibly shorter or
|
|
166
|
+
// longer than the tab it underlines — while `offsetWidth` had been right
|
|
167
|
+
// all along. Asserting the STYLE (not the pixels, which jsdom has none of)
|
|
168
|
+
// is what keeps the multiplier from coming back.
|
|
169
|
+
const widthSpy = vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(120)
|
|
170
|
+
const leftSpy = vi.spyOn(HTMLElement.prototype, 'offsetLeft', 'get').mockReturnValue(40)
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
setMockSearchParams(new URLSearchParams('tab=general'))
|
|
174
|
+
const { container } = render(
|
|
175
|
+
<TabNavigation tabs={TABS} urlSync>
|
|
176
|
+
{() => null}
|
|
177
|
+
</TabNavigation>
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
const underline = container.querySelector('[aria-hidden]') as HTMLElement
|
|
181
|
+
expect(underline.style.width).toBe('120px')
|
|
182
|
+
expect(underline.style.transform).toBe('translateX(40px)')
|
|
183
|
+
expect(underline.style.transform).not.toContain('scaleX')
|
|
184
|
+
expect(underline.className).not.toContain('w-px')
|
|
185
|
+
} finally {
|
|
186
|
+
widthSpy.mockRestore()
|
|
187
|
+
leftSpy.mockRestore()
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
})
|
|
159
191
|
})
|
|
@@ -231,12 +231,29 @@ const TabBar = memo(function TabBar({
|
|
|
231
231
|
return { background: c }
|
|
232
232
|
}, [leftFade, rightFade])
|
|
233
233
|
|
|
234
|
-
//
|
|
235
|
-
// transform and opacity
|
|
236
|
-
// animate without laying
|
|
234
|
+
// Real width, moved by `translateX`. This used to be a 1px bar stretched with
|
|
235
|
+
// `scaleX(width)` — transform and opacity being the only properties the
|
|
236
|
+
// compositor can animate without laying out again — but scaling from a ONE
|
|
237
|
+
// PIXEL base turns that pixel into an error multiplier.
|
|
238
|
+
//
|
|
239
|
+
// A CSS pixel only lands on a whole device pixel at integer scale factors. At
|
|
240
|
+
// 125% / 150% OS scaling, a scaled Mac resolution, or any browser zoom, the
|
|
241
|
+
// base is rasterized at the nearest whole device pixel — call it 0.8 or 1.33
|
|
242
|
+
// CSS px — and `scaleX(150)` multiplies that rounding by 150. The underline
|
|
243
|
+
// then renders a fifth short or a third long, per tab, with `measureIndicator`
|
|
244
|
+
// having been perfectly correct all along. It shows up from the SECOND tab
|
|
245
|
+
// change on, because that is when the transition promotes the bar into its own
|
|
246
|
+
// composited layer, where it is rasterized in its own 1×4 coordinate space and
|
|
247
|
+
// only then stretched.
|
|
248
|
+
//
|
|
249
|
+
// Animating `width` costs a layout per frame for this one element — it is
|
|
250
|
+
// `absolute`, so nothing else in the strip is laid out with it, and 200ms of
|
|
251
|
+
// that for a 4px-tall bar is not measurable. Correctness at every zoom level
|
|
252
|
+
// is worth more than keeping one property on the compositor.
|
|
237
253
|
const isPlaced = indicator.width > 0
|
|
238
254
|
const indicatorStyle: React.CSSProperties = {
|
|
239
|
-
|
|
255
|
+
width: `${indicator.width}px`,
|
|
256
|
+
transform: `translateX(${indicator.left}px)`,
|
|
240
257
|
opacity: isPlaced ? 1 : 0,
|
|
241
258
|
}
|
|
242
259
|
const shouldAnimateIndicator = hasPlacedIndicatorRef.current
|
|
@@ -302,13 +319,13 @@ const TabBar = memo(function TabBar({
|
|
|
302
319
|
})}
|
|
303
320
|
|
|
304
321
|
{/* One underline for the whole strip, sliding between tabs. Inside the
|
|
305
|
-
scroll container so it travels with the content
|
|
306
|
-
|
|
322
|
+
scroll container so it travels with the content. Width comes from the
|
|
323
|
+
style below in real pixels — see why it is not a scaled 1px bar. */}
|
|
307
324
|
<div
|
|
308
325
|
aria-hidden
|
|
309
326
|
className={cn(
|
|
310
|
-
"pointer-events-none absolute bottom-0 left-0 h-1
|
|
311
|
-
shouldAnimateIndicator && "transition-[transform,opacity] duration-200 ease-out motion-reduce:transition-none"
|
|
327
|
+
"pointer-events-none absolute bottom-0 left-0 h-1 bg-ods-accent",
|
|
328
|
+
shouldAnimateIndicator && "transition-[transform,width,opacity] duration-200 ease-out motion-reduce:transition-none"
|
|
312
329
|
)}
|
|
313
330
|
style={indicatorStyle}
|
|
314
331
|
/>
|