basalt-ui 2.27.1 → 2.28.0
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/CHANGELOG.md +111 -0
- package/MIGRATING.md +172 -12
- package/agent/rules/basalt-batteries.md +1 -1
- package/agent/rules/basalt-mantine.md +1 -1
- package/agent/rules/basalt-tokens.md +2 -2
- package/agent/skills/basalt-design/SKILL.md +1 -1
- package/agent/skills/basalt-design/references/catalogue.md +40 -36
- package/agent/skills/basalt-design/references/recipes.md +47 -0
- package/configs/oxlint-basalt.json +2 -1
- package/configs/oxlint-plugin.js +110 -2
- package/configs/oxlint-plugin.test.ts +99 -4
- package/dist/agent/chat/thread-message.d.ts +1 -160
- package/dist/agent/chat/thread-message.d.ts.map +1 -1
- package/dist/agent/chat/thread-message.js +7 -162
- package/dist/agent/chat/virtualize.d.ts +5 -5
- package/dist/charts/ChartCard.d.ts +5 -2
- package/dist/charts/ChartCard.d.ts.map +1 -1
- package/dist/charts/ChartCard.js +46 -13
- package/dist/charts/Lines.d.ts.map +1 -1
- package/dist/charts/Lines.js +11 -4
- package/dist/charts/Sparkline.d.ts +9 -2
- package/dist/charts/Sparkline.d.ts.map +1 -1
- package/dist/charts/Sparkline.js +104 -41
- package/dist/charts/chart-box.module.css +69 -3
- package/dist/charts/chart-box.module.css.d.ts +5 -0
- package/dist/charts/chart-card.module.css +12 -4
- package/dist/charts/chart-card.module.css.d.ts +1 -0
- package/dist/charts/compile.d.ts.map +1 -1
- package/dist/charts/compile.js +21 -19
- package/dist/charts/labels.d.ts +13 -3
- package/dist/charts/labels.d.ts.map +1 -1
- package/dist/charts/labels.js +131 -20
- package/dist/charts/legend.d.ts.map +1 -1
- package/dist/charts/legend.js +1 -1
- package/dist/charts/ref-label.d.ts +31 -8
- package/dist/charts/ref-label.d.ts.map +1 -1
- package/dist/charts/ref-label.js +40 -9
- package/dist/charts/sparkline.module.css +6 -0
- package/dist/charts/state.d.ts +3 -3
- package/dist/charts/state.d.ts.map +1 -1
- package/dist/charts/state.js +20 -2
- package/dist/cli/shot/capture.d.ts +6 -1
- package/dist/cli/shot/capture.d.ts.map +1 -1
- package/dist/cli/shot/capture.js +18 -5
- package/dist/common/empty-copy.d.ts +16 -0
- package/dist/common/empty-copy.d.ts.map +1 -0
- package/dist/common/empty-copy.js +9 -0
- package/dist/common/virtual-rows.d.ts +196 -0
- package/dist/common/virtual-rows.d.ts.map +1 -0
- package/dist/common/virtual-rows.js +290 -0
- package/dist/controls/controls.module.css +33 -1
- package/dist/controls/controls.module.css.d.ts +2 -0
- package/dist/controls/enum-filter.d.ts.map +1 -1
- package/dist/controls/enum-filter.js +8 -2
- package/dist/controls/filter-pill.d.ts +27 -3
- package/dist/controls/filter-pill.d.ts.map +1 -1
- package/dist/controls/filter-pill.js +15 -4
- package/dist/controls/form-layout.d.ts +9 -3
- package/dist/controls/form-layout.d.ts.map +1 -1
- package/dist/controls/form-layout.js +74 -12
- package/dist/controls/form-layout.module.css +112 -7
- package/dist/controls/form-layout.module.css.d.ts +1 -0
- package/dist/controls/multi-select-filter.d.ts +2 -2
- package/dist/controls/multi-select-filter.d.ts.map +1 -1
- package/dist/controls/multi-select-filter.js +12 -6
- package/dist/controls/range-filter.d.ts +1 -1
- package/dist/controls/range-filter.d.ts.map +1 -1
- package/dist/controls/range-filter.js +8 -2
- package/dist/dashboard/bar-list.d.ts +1 -1
- package/dist/dashboard/bar-list.d.ts.map +1 -1
- package/dist/dashboard/bar-list.js +6 -2
- package/dist/dashboard/bar-list.module.css +0 -2
- package/dist/dashboard/board-nav.d.ts +22 -0
- package/dist/dashboard/board-nav.d.ts.map +1 -0
- package/dist/dashboard/board-nav.js +49 -0
- package/dist/dashboard/board.d.ts +52 -0
- package/dist/dashboard/board.d.ts.map +1 -0
- package/dist/dashboard/board.js +228 -0
- package/dist/dashboard/board.module.css +160 -0
- package/dist/dashboard/board.module.css.d.ts +26 -0
- package/dist/dashboard/empty-state.d.ts +3 -3
- package/dist/dashboard/empty-state.d.ts.map +1 -1
- package/dist/dashboard/empty-state.js +13 -6
- package/dist/dashboard/event-list-model.d.ts +51 -0
- package/dist/dashboard/event-list-model.d.ts.map +1 -0
- package/dist/dashboard/event-list-model.js +72 -0
- package/dist/dashboard/event-list-rows.d.ts +23 -0
- package/dist/dashboard/event-list-rows.d.ts.map +1 -0
- package/dist/dashboard/event-list-rows.js +93 -0
- package/dist/dashboard/event-list-scroll.d.ts +27 -0
- package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
- package/dist/dashboard/event-list-scroll.js +103 -0
- package/dist/dashboard/event-list-skeleton.d.ts +10 -0
- package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
- package/dist/dashboard/event-list-skeleton.js +36 -0
- package/dist/dashboard/event-list.d.ts +65 -0
- package/dist/dashboard/event-list.d.ts.map +1 -0
- package/dist/dashboard/event-list.js +178 -0
- package/dist/dashboard/event-list.module.css +283 -0
- package/dist/dashboard/event-list.module.css.d.ts +33 -0
- package/dist/dashboard/index.d.ts +2 -0
- package/dist/dashboard/index.d.ts.map +1 -1
- package/dist/dashboard/index.js +4 -0
- package/dist/dashboard/meter-parts.d.ts.map +1 -1
- package/dist/dashboard/meter-parts.js +5 -3
- package/dist/dashboard/meter.module.css +2 -1
- package/dist/dashboard/query-state.js +1 -1
- package/dist/dashboard/settings-section.d.ts +4 -1
- package/dist/dashboard/settings-section.d.ts.map +1 -1
- package/dist/dashboard/settings-section.js +1 -1
- package/dist/dashboard/settings-section.module.css +19 -4
- package/dist/dashboard/stat-card-parts.d.ts +5 -1
- package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
- package/dist/dashboard/stat-card-parts.js +8 -3
- package/dist/dashboard/stat-card.d.ts.map +1 -1
- package/dist/dashboard/stat-card.js +26 -7
- package/dist/dashboard/stat-card.module.css +31 -7
- package/dist/dashboard/stat-card.module.css.d.ts +3 -0
- package/dist/dashboard/stat-strip.js +1 -1
- package/dist/dashboard/stat-strip.module.css +4 -1
- package/dist/dashboard/widget-header.d.ts.map +1 -1
- package/dist/dashboard/widget-header.js +15 -2
- package/dist/dashboard/widget-header.module.css +17 -1
- package/dist/guard/index.d.ts.map +1 -1
- package/dist/guard/index.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/shell/app-main.module.css +18 -0
- package/dist/styles.css +46 -8
- package/dist/surfaces.d.ts +2 -2
- package/dist/surfaces.d.ts.map +1 -1
- package/dist/surfaces.js +8 -2
- package/dist/table/cell-kinds.d.ts +44 -0
- package/dist/table/cell-kinds.d.ts.map +1 -0
- package/dist/table/cell-kinds.js +169 -0
- package/dist/table/cell-kinds.module.css +55 -0
- package/dist/table/cell-kinds.module.css.d.ts +15 -0
- package/dist/table/data-table-fold.d.ts +147 -0
- package/dist/table/data-table-fold.d.ts.map +1 -0
- package/dist/table/data-table-fold.js +288 -0
- package/dist/table/data-table-state.d.ts +10 -3
- package/dist/table/data-table-state.d.ts.map +1 -1
- package/dist/table/data-table-state.js +11 -6
- package/dist/table/data-table.d.ts +11 -26
- package/dist/table/data-table.d.ts.map +1 -1
- package/dist/table/data-table.js +354 -254
- package/dist/table/data-table.module.css +210 -3
- package/dist/table/data-table.module.css.d.ts +12 -0
- package/dist/table/table-features.d.ts +34 -4
- package/dist/table/table-features.d.ts.map +1 -1
- package/dist/table/table-features.js +10 -0
- package/dist/theme/card-inset.module.css +35 -0
- package/dist/theme/controls.module.css +32 -0
- package/dist/theme/ctl-theme.d.ts.map +1 -1
- package/dist/theme/ctl-theme.js +5 -0
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/index.js +14 -10
- package/dist/tokens/core.d.ts +1 -0
- package/dist/tokens/core.d.ts.map +1 -1
- package/dist/tokens/core.js +1 -0
- package/dist/tokens/derive.js +1 -1
- package/dist/tokens/palette.d.ts +2 -1
- package/dist/tokens/palette.d.ts.map +1 -1
- package/llms.txt +34 -5
- package/package.json +1 -1
- package/src/agent/chat/thread-message.tsx +10 -403
- package/src/agent/chat/virtualize.ts +5 -5
- package/src/charts/ChartCard.tsx +79 -17
- package/src/charts/Lines.tsx +13 -4
- package/src/charts/Sparkline.tsx +131 -45
- package/src/charts/chart-box.module.css +69 -3
- package/src/charts/chart-box.module.css.d.ts +5 -0
- package/src/charts/chart-card.module.css +12 -4
- package/src/charts/chart-card.module.css.d.ts +1 -0
- package/src/charts/compile.ts +24 -20
- package/src/charts/labels.ts +175 -24
- package/src/charts/legend.tsx +3 -2
- package/src/charts/ref-label.ts +86 -17
- package/src/charts/sparkline.module.css +6 -0
- package/src/charts/state.tsx +36 -7
- package/src/cli/shot/capture.ts +29 -6
- package/src/common/empty-copy.ts +17 -0
- package/src/common/virtual-rows.tsx +682 -0
- package/src/controls/controls.module.css +33 -1
- package/src/controls/controls.module.css.d.ts +2 -0
- package/src/controls/enum-filter.tsx +8 -2
- package/src/controls/filter-pill.tsx +80 -27
- package/src/controls/form-layout.module.css +112 -7
- package/src/controls/form-layout.module.css.d.ts +1 -0
- package/src/controls/form-layout.tsx +115 -22
- package/src/controls/multi-select-filter.tsx +22 -11
- package/src/controls/range-filter.tsx +9 -3
- package/src/dashboard/bar-list.module.css +0 -2
- package/src/dashboard/bar-list.tsx +8 -5
- package/src/dashboard/board-nav.ts +67 -0
- package/src/dashboard/board.module.css +160 -0
- package/src/dashboard/board.module.css.d.ts +26 -0
- package/src/dashboard/board.tsx +394 -0
- package/src/dashboard/empty-state.tsx +16 -9
- package/src/dashboard/event-list-model.ts +113 -0
- package/src/dashboard/event-list-rows.tsx +120 -0
- package/src/dashboard/event-list-scroll.ts +145 -0
- package/src/dashboard/event-list-skeleton.tsx +58 -0
- package/src/dashboard/event-list.module.css +283 -0
- package/src/dashboard/event-list.module.css.d.ts +33 -0
- package/src/dashboard/event-list.tsx +309 -0
- package/src/dashboard/index.ts +2 -0
- package/src/dashboard/meter-parts.tsx +9 -2
- package/src/dashboard/meter.module.css +2 -1
- package/src/dashboard/query-state.tsx +1 -1
- package/src/dashboard/settings-section.module.css +19 -4
- package/src/dashboard/settings-section.tsx +7 -2
- package/src/dashboard/stat-card-parts.tsx +20 -3
- package/src/dashboard/stat-card.module.css +31 -7
- package/src/dashboard/stat-card.module.css.d.ts +3 -0
- package/src/dashboard/stat-card.tsx +25 -6
- package/src/dashboard/stat-strip.module.css +4 -1
- package/src/dashboard/stat-strip.tsx +1 -1
- package/src/dashboard/widget-header.module.css +17 -1
- package/src/dashboard/widget-header.tsx +29 -5
- package/src/guard/index.ts +2 -0
- package/src/index.ts +4 -0
- package/src/shell/app-main.module.css +18 -0
- package/src/styles.css +46 -8
- package/src/surfaces.ts +7 -1
- package/src/table/cell-kinds.module.css +55 -0
- package/src/table/cell-kinds.module.css.d.ts +15 -0
- package/src/table/cell-kinds.tsx +234 -0
- package/src/table/data-table-fold.tsx +514 -0
- package/src/table/data-table-state.ts +24 -13
- package/src/table/data-table.module.css +210 -3
- package/src/table/data-table.module.css.d.ts +12 -0
- package/src/table/data-table.tsx +406 -359
- package/src/table/table-features.ts +44 -4
- package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
- package/src/theme/card-inset.module.css +35 -0
- package/src/theme/controls.module.css +32 -0
- package/src/theme/ctl-theme.tsx +8 -0
- package/src/theme/index.ts +12 -8
- package/src/tokens/core.ts +1 -0
- package/src/tokens/derive.ts +1 -1
- package/src/tokens/palette.ts +4 -1
package/llms.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# basalt-ui v2.
|
|
1
|
+
# basalt-ui v2.28.0
|
|
2
2
|
# Opinionated framework for Mantine-based React apps — theme, app shell, TanStack Charts, toolchain presets
|
|
3
3
|
#
|
|
4
4
|
# Entry points: use the exact import specifier below; do not guess.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# A subpath's `Install:` line is its required peers; `OptionalPeers:` are import()-only, install on use.
|
|
14
14
|
|
|
15
15
|
Package: basalt-ui
|
|
16
|
-
Version: 2.
|
|
16
|
+
Version: 2.28.0
|
|
17
17
|
|
|
18
18
|
## basalt-ui
|
|
19
19
|
Import: import { ... } from 'basalt-ui'
|
|
@@ -68,6 +68,16 @@ Signature: BasaltShell(props: BasaltShellProps<G, T>): JSX.Element
|
|
|
68
68
|
isActive?: (item: NavItemMeta & { link: AnyNavLink; children?: Readonl…
|
|
69
69
|
getScrollElement?: () => HTMLElement | null
|
|
70
70
|
nav: NavConfig<G, T>
|
|
71
|
+
Signature: Board(props: BoardProps<T>): JSX.Element
|
|
72
|
+
className?: string
|
|
73
|
+
style?: CSSProperties
|
|
74
|
+
label?: string
|
|
75
|
+
columns: readonly { id: T; title: string; tone?: string; total?: str…
|
|
76
|
+
onOpen?: (cardId: string, columnId: string) => void
|
|
77
|
+
height?: string | number
|
|
78
|
+
loading?: boolean
|
|
79
|
+
empty?: { title: string; description?: string; action?: ReactNode; }
|
|
80
|
+
field?: FieldHandle<EnumField<T>>
|
|
71
81
|
Signature: DangerZone(props: SettingsSectionProps): JSX.Element
|
|
72
82
|
className?: string
|
|
73
83
|
style?: CSSProperties
|
|
@@ -94,6 +104,23 @@ Signature: EmptyState(props: EmptyStateProps): JSX.Element
|
|
|
94
104
|
description?: string
|
|
95
105
|
action?: ReactNode
|
|
96
106
|
tier?: "section" | "page"
|
|
107
|
+
Signature: EventList(props: EventListProps): JSX.Element
|
|
108
|
+
className?: string
|
|
109
|
+
style?: CSSProperties
|
|
110
|
+
label?: string
|
|
111
|
+
items: readonly { id: string; at: Date | number; actor?: ReactNode…
|
|
112
|
+
density?: "feed" | "timeline"
|
|
113
|
+
rail?: boolean
|
|
114
|
+
group?: "day" | "none"
|
|
115
|
+
now?: number | Date
|
|
116
|
+
dayLabel?: (day: Date, now: Date) => string
|
|
117
|
+
time?: "clock" | "relative" | "date-time" | ((at: Date) => string)
|
|
118
|
+
order?: "newest-first" | "oldest-first"
|
|
119
|
+
earlier?: { onLoad: () => void; loading?: boolean; remaining?: number…
|
|
120
|
+
height?: string | number
|
|
121
|
+
loading?: boolean
|
|
122
|
+
loadingRows?: number
|
|
123
|
+
empty?: { title: string; description?: string; action?: ReactNode; }
|
|
97
124
|
Signature: Meter(props: MeterProps): JSX.Element
|
|
98
125
|
className?: string
|
|
99
126
|
style?: CSSProperties
|
|
@@ -385,7 +412,7 @@ Signature: ChartCard(props: ChartCardProps): ReactElement<unknown, string | JSXE
|
|
|
385
412
|
actions?: ReactNode
|
|
386
413
|
state?: ChartState
|
|
387
414
|
placeholderHeight?: number | ResponsiveChartHeight | "content"
|
|
388
|
-
ghost?: number | "line" | "bars"
|
|
415
|
+
ghost?: number | "line" | "bars" | "band"
|
|
389
416
|
stale?: boolean
|
|
390
417
|
stateNoun?: string
|
|
391
418
|
onRetry?: (() => void)
|
|
@@ -505,6 +532,7 @@ Signature: Sparkline(props: SparklineProps): ReactElement<unknown, string | JSXE
|
|
|
505
532
|
state?: ChartState
|
|
506
533
|
reference?: number | "mean"
|
|
507
534
|
referenceLabel?: string
|
|
535
|
+
band?: { from: number; to: number; }
|
|
508
536
|
format?: ((value: number) => string)
|
|
509
537
|
labels?: readonly string[]
|
|
510
538
|
Signature: StackedArea(props: StackedAreaProps<T, X>): ReactElement<unknown, string | JSXElementConstructor<any>>
|
|
@@ -680,6 +708,7 @@ Signature: BasaltDataTable(props: BasaltDataTableProps<T>): JSX.Element
|
|
|
680
708
|
globalFilterPlaceholder?: string
|
|
681
709
|
searchIcon?: ReactNode
|
|
682
710
|
initialGlobalFilter?: string
|
|
711
|
+
initialColumnFilters?: ColumnFiltersState
|
|
683
712
|
onGlobalFilterChange?: (value: string) => void
|
|
684
713
|
facets?: DataTableFacet<T>[]
|
|
685
714
|
onColumnFiltersChange?: (filters: ColumnFiltersState) => void
|
|
@@ -697,8 +726,7 @@ Signature: BasaltDataTable(props: BasaltDataTableProps<T>): JSX.Element
|
|
|
697
726
|
enablePagination?: boolean
|
|
698
727
|
pageSizeOptions?: number[]
|
|
699
728
|
initialPagination?: PaginationState
|
|
700
|
-
|
|
701
|
-
… +13 more
|
|
729
|
+
… +14 more
|
|
702
730
|
Signature: createColumnHelper(): ColumnHelper<{ rowSortingFeature: TableFeature; columnFilteringFeatur…
|
|
703
731
|
Install: bun add @tanstack/react-table@9.2.8
|
|
704
732
|
|
|
@@ -884,6 +912,7 @@ Signature: FormGroup(props: FormGroupProps): JSX.Element
|
|
|
884
912
|
error?: ReactNode
|
|
885
913
|
required?: boolean
|
|
886
914
|
direction?: "row" | "column"
|
|
915
|
+
section?: boolean
|
|
887
916
|
children: ReactNode
|
|
888
917
|
Signature: FormRow(props: FormRowProps): JSX.Element
|
|
889
918
|
className?: string
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
UnstyledButton,
|
|
31
31
|
} from '@mantine/core'
|
|
32
32
|
import { useDisclosure, useFocusWithin, useHover, useMergedRef } from '@mantine/hooks'
|
|
33
|
-
import { Fragment,
|
|
33
|
+
import { Fragment, memo, useLayoutEffect, useMemo, useRef } from 'react'
|
|
34
34
|
import type { JSX } from 'react'
|
|
35
35
|
import type {
|
|
36
36
|
AgentPart,
|
|
@@ -49,6 +49,7 @@ import { coalesceParts } from '../coalesce'
|
|
|
49
49
|
import { narrowAgentPart } from '../foreign'
|
|
50
50
|
import { PartList } from '../part-list'
|
|
51
51
|
import { cx } from '../../common/props'
|
|
52
|
+
import { VirtualRows } from '../../common/virtual-rows'
|
|
52
53
|
import type { BasaltProps } from '../../common/props'
|
|
53
54
|
import { assertRequiredProps } from '../../common/validate'
|
|
54
55
|
import { Markdown } from '../../content/markdown'
|
|
@@ -552,13 +553,9 @@ MessageBlock.displayName = 'MessageBlock'
|
|
|
552
553
|
|
|
553
554
|
// ── Virtualization (AGENT-CHAT-SPEC.md §9) ─────────────────────────────────────
|
|
554
555
|
//
|
|
555
|
-
//
|
|
556
|
-
//
|
|
557
|
-
//
|
|
558
|
-
// resolves the peer either) — so a static top-level import here would make every `ThreadTranscript`
|
|
559
|
-
// consumer require the peer, even ones that never pass `virtualize`. Lazy + dynamic `import()` +
|
|
560
|
-
// `.catch()` degrade, mirroring `../agent/stick-to-bottom.tsx`'s established pattern exactly, keeps
|
|
561
|
-
// the non-virtualized path working with the package absent.
|
|
556
|
+
// The windowing itself lives in the package's one lazy seam, `../../common/virtual-rows` — the
|
|
557
|
+
// only module that may `import('@tanstack/react-virtual')` (an OPTIONAL peer), and only
|
|
558
|
+
// dynamically with a `.catch()` degrade to plain rows. This section keeps only the chat's tuning.
|
|
562
559
|
|
|
563
560
|
/** Default extra rows rendered beyond the viewport, each side. Higher than
|
|
564
561
|
* `BasaltVirtualList`'s generic-list default (5) — a streaming transcript's scroll bursts benefit
|
|
@@ -576,409 +573,15 @@ const DEFAULT_VIRTUALIZE_OVERSCAN = 6
|
|
|
576
573
|
* defensible on a shorter/plainer demo thread. */
|
|
577
574
|
const DEFAULT_VIRTUALIZE_ESTIMATE_SIZE = 160
|
|
578
575
|
|
|
579
|
-
/** Default `scrollEndThreshold` — how close (px) to the end still counts as "at the end" for
|
|
580
|
-
* `followOnAppend`/`anchorTo: 'end'` to keep tracking rather than freezing the scroll position. */
|
|
581
|
-
const DEFAULT_VIRTUALIZE_SCROLL_END_THRESHOLD = 64
|
|
582
|
-
|
|
583
576
|
/** Default `VirtualizeOptions.initialScroll` — see `./virtualize`'s fourth composition rule for
|
|
584
577
|
* why a chat transcript opens at the newest message rather than the oldest. */
|
|
585
578
|
const DEFAULT_VIRTUALIZE_INITIAL_SCROLL: NonNullable<VirtualizeOptions['initialScroll']> = 'end'
|
|
586
579
|
|
|
587
|
-
/** Caps `applyInitialScroll`'s clobber-recovery retries (see `./virtualize`'s fourth composition
|
|
588
|
-
* rule for the full mechanism this guards). A small fixed budget, not a time/frame-based deadline:
|
|
589
|
-
* every observed case of virtual-core's `_willUpdate` clobbering this effect's jump resolves within
|
|
590
|
-
* one extra commit, so this exists purely as a backstop against a pathological DOM that never
|
|
591
|
-
* reports settled — not as the expected path. Once exhausted, the effect gives up and marks the
|
|
592
|
-
* jump permanently done wherever the last attempt landed, rather than fighting the DOM (or a user
|
|
593
|
-
* who has since scrolled away) forever. Exported (like `messageBlockRenderCounter`) purely so its
|
|
594
|
-
* test can assert the exact bound without duplicating the number; not part of the public surface. */
|
|
595
|
-
export const MAX_INITIAL_SCROLL_ATTEMPTS = 5
|
|
596
|
-
|
|
597
580
|
type TranscriptRow = {
|
|
598
581
|
readonly key: string
|
|
599
582
|
readonly node: JSX.Element
|
|
600
583
|
}
|
|
601
584
|
|
|
602
|
-
type VirtualizedTranscriptProps = BasaltProps & {
|
|
603
|
-
readonly rows: readonly TranscriptRow[]
|
|
604
|
-
readonly height: number | string
|
|
605
|
-
readonly overscan: number
|
|
606
|
-
readonly estimateSize: number
|
|
607
|
-
readonly initialScroll: NonNullable<VirtualizeOptions['initialScroll']>
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* The degrade target: every row rendered unwindowed inside a fixed-height scroll container.
|
|
612
|
-
* This is what a `virtualize: true` transcript falls back to when `@tanstack/react-virtual` fails
|
|
613
|
-
* to resolve (peer absent) — same visual shape (a scrollable `height`-bound pane), just without
|
|
614
|
-
* windowing.
|
|
615
|
-
*
|
|
616
|
-
* NOT used as the `Suspense` fallback (see `VirtualizeSuspenseFallback` below) — mounting every
|
|
617
|
-
* real `MessageBlock` subtree for the one tick the lazy import takes to settle would make that
|
|
618
|
-
* settle a genuine unmount/remount of every rendered row, re-firing each row's effects once and
|
|
619
|
-
* risking hitting a message mid-stream during the resolve window.
|
|
620
|
-
*/
|
|
621
|
-
function NonVirtualizedRows({
|
|
622
|
-
rows,
|
|
623
|
-
height,
|
|
624
|
-
className,
|
|
625
|
-
style,
|
|
626
|
-
}: VirtualizedTranscriptProps): JSX.Element {
|
|
627
|
-
return (
|
|
628
|
-
// theme-allow raw-scroll-container — degrade target owns its own scroll node, same as the real virtualizer below.
|
|
629
|
-
<Box className={cx(className)} style={{ height, overflow: 'auto', ...style }}>
|
|
630
|
-
<Stack gap="sm">
|
|
631
|
-
{rows.map((row) => (
|
|
632
|
-
<Fragment key={row.key}>{row.node}</Fragment>
|
|
633
|
-
))}
|
|
634
|
-
</Stack>
|
|
635
|
-
</Box>
|
|
636
|
-
)
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/** Test-only escape hatch (mirrors `messageBlockRenderCounter` above) — proves the peer-absent
|
|
640
|
-
* degrade target itself renders every row without windowing and without throwing, without having
|
|
641
|
-
* to fight `React.lazy`'s permanent once-per-module-instance resolution cache to simulate the
|
|
642
|
-
* peer's absence at the `import()` layer (see thread-message.test.tsx's virtualization describe
|
|
643
|
-
* block for why that approach was rejected). Not exported from `agent-chat/index.ts`. */
|
|
644
|
-
export const nonVirtualizedRowsFallback = NonVirtualizedRows
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
* Minimal structural slice of `Virtualizer` (virtual-core 3.17.1) that
|
|
648
|
-
* {@link resolveGuardedMeasurement} needs — `indexFromElement`/`itemSizeCache`/`options` are all
|
|
649
|
-
* public instance members, but typing against the real (generic, peer-only) `Virtualizer` class
|
|
650
|
-
* would force this test-only-exported helper to import the peer's runtime types at module scope,
|
|
651
|
-
* the exact static-import-forces-the-peer problem the surrounding `lazy(() => import(...))` exists
|
|
652
|
-
* to avoid. A structural type sidesteps that without loosening to `any`. Generic over the item
|
|
653
|
-
* element type (rather than fixed at `Element`) so it stays exactly assignable FROM a real
|
|
654
|
-
* `Virtualizer<TScrollElement, TItemElement>` at the call site below — `indexFromElement` is
|
|
655
|
-
* declared with arrow-property (not method) syntax upstream, so it is checked contravariantly, and
|
|
656
|
-
* a fixed `Element` parameter there does not structurally match a real instance's narrower
|
|
657
|
-
* `TItemElement` parameter.
|
|
658
|
-
*/
|
|
659
|
-
type MeasurementCacheHost<TItemElement extends Element> = {
|
|
660
|
-
readonly indexFromElement: (node: TItemElement) => number
|
|
661
|
-
readonly itemSizeCache: Map<unknown, number>
|
|
662
|
-
readonly options: {
|
|
663
|
-
readonly getItemKey: (index: number) => unknown
|
|
664
|
-
readonly estimateSize: (index: number) => number
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
/**
|
|
669
|
-
* Resolves the size a `measureElement` implementation should report, given what the underlying
|
|
670
|
-
* (default or custom) measurement already produced: that value unchanged when it is a genuine
|
|
671
|
-
* measurement, or the row's own last-known size when it is `0` — never a real reading for a mounted
|
|
672
|
-
* row, so a `0` only ever means the ResizeObserver measured through a `display: none` (or otherwise
|
|
673
|
-
* unlaid-out) ancestor, e.g. a virtualized transcript sitting inside a collapsed `ThreadFeedRow`.
|
|
674
|
-
* Falling through to it unguarded is what corrupted `itemSizeCache`/`measurementsCache`: virtual-
|
|
675
|
-
* core's default `resizeItem` writes whatever `measureElement` returns with no floor, so every
|
|
676
|
-
* mounted row remeasures at 0px the instant an ancestor hides, `getTotalSize()` collapses within
|
|
677
|
-
* the same tick, and the collapse is never undone — a later real remeasurement only OVERWRITES
|
|
678
|
-
* entries the ResizeObserver happens to re-fire for, it does not restore ones that silently kept
|
|
679
|
-
* their poisoned 0 (see `virtualize.ts`'s composition-rule doc for the full mechanism and the
|
|
680
|
-
* measured numbers).
|
|
681
|
-
*
|
|
682
|
-
* Takes the already-computed `size` plus the {@link MeasurementCacheHost} slice, rather than
|
|
683
|
-
* wrapping the `measureElement` function itself, so this stays a plain, non-generic-over-a-
|
|
684
|
-
* generic-function call at its one call site below (`instance` there is `Virtualizer<TScrollElement,
|
|
685
|
-
* TItemElement>` for THAT call's concrete type arguments, not the peer's own generic
|
|
686
|
-
* `measureElement` export — wrapping the latter directly hits TS's higher-rank inference limits on
|
|
687
|
-
* a doubly-generic HOF). That shape is also what makes this unit-testable with a fake host object
|
|
688
|
-
* and no ResizeObserver/layout engine at all (happy-dom has neither). Not exported from
|
|
689
|
-
* `agent-chat/index.ts`: a test-only escape hatch, matching
|
|
690
|
-
* `messageBlockRenderCounter`/`nonVirtualizedRowsFallback` above.
|
|
691
|
-
*/
|
|
692
|
-
export function resolveGuardedMeasurement<TItemElement extends Element>(
|
|
693
|
-
host: MeasurementCacheHost<TItemElement>,
|
|
694
|
-
element: TItemElement,
|
|
695
|
-
size: number,
|
|
696
|
-
): number {
|
|
697
|
-
if (size > 0) return size
|
|
698
|
-
// Same key derivation `resizeItem` itself uses (index → getItemKey), read BEFORE `resizeItem`
|
|
699
|
-
// writes the new (bad) size — `itemSizeCache` still holds the last-good measurement here.
|
|
700
|
-
const index = host.indexFromElement(element)
|
|
701
|
-
const key = host.options.getItemKey(index)
|
|
702
|
-
return host.itemSizeCache.get(key) ?? host.options.estimateSize(index)
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Decides what `VirtualizedRowsInner`'s one-shot initial-scroll effect should do this render,
|
|
707
|
-
* given the inputs the effect closes over. Pure and peer/DOM-free — pulled out of the lazy-loaded
|
|
708
|
-
* closure for the same reason `resolveGuardedMeasurement` is: it stays unit-testable without a
|
|
709
|
-
* real `Virtualizer` instance or `@tanstack/react-virtual` itself.
|
|
710
|
-
*
|
|
711
|
-
* `'start'` and an empty transcript resolve to `'skip-done'` — there is nothing to scroll to, and
|
|
712
|
-
* DONE is permanent (see `virtualize.ts`'s fourth composition rule: the real scroll must fire at
|
|
713
|
-
* most once, ever, so a later append never yanks a user who has scrolled up). A non-positive
|
|
714
|
-
* `containerHeight` — the transcript's own scroll node measuring `0`, e.g. mounted behind a
|
|
715
|
-
* `display: none` ancestor per `virtualize.ts`'s third composition rule — resolves to
|
|
716
|
-
* `'skip-retry'`: NOT done, so the caller's effect (which re-runs after EVERY commit until the jump
|
|
717
|
-
* lands — see {@link applyInitialScroll}) gets another chance the next time this subtree renders,
|
|
718
|
-
* instead of permanently stranding the transcript at the top the moment it becomes visible. Only a
|
|
719
|
-
* genuinely measured, non-empty, `'end'`-targeted mount resolves to `'scroll'`.
|
|
720
|
-
*/
|
|
721
|
-
export function resolveInitialScrollAction(
|
|
722
|
-
initialScroll: NonNullable<VirtualizeOptions['initialScroll']>,
|
|
723
|
-
rowCount: number,
|
|
724
|
-
containerHeight: number,
|
|
725
|
-
): 'scroll' | 'skip-done' | 'skip-retry' {
|
|
726
|
-
if (initialScroll === 'start') return 'skip-done'
|
|
727
|
-
if (rowCount === 0) return 'skip-done'
|
|
728
|
-
if (containerHeight <= 0) return 'skip-retry'
|
|
729
|
-
return 'scroll'
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
/** The mutable half of the one-shot initial-scroll contract. `hasApplied` is whether it has
|
|
733
|
-
* PERMANENTLY finished — either there was nothing to do (`'start'`/empty transcript), or
|
|
734
|
-
* `scrollToEnd` fired and was subsequently CONFIRMED (via a real DOM read — see
|
|
735
|
-
* {@link applyInitialScroll}'s doc for why virtual-core's own tracked offset can't be trusted for
|
|
736
|
-
* this) to have survived whatever else committed since. `attempts` counts how many times
|
|
737
|
-
* `scrollToEnd` has been (re-)fired this mount; 0 means never attempted, and also gates whether a
|
|
738
|
-
* call re-derives {@link resolveInitialScrollAction} at all. One instance lives for the lifetime of
|
|
739
|
-
* a `VirtualizedRowsInner` mount, held in a `useRef` so it survives re-renders without itself
|
|
740
|
-
* triggering one. */
|
|
741
|
-
export type InitialScrollState = { hasApplied: boolean; attempts: number }
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* The stateful half of "fires once, on first mount, and never again" (`virtualize.ts`'s fourth
|
|
745
|
-
* composition rule): wraps {@link resolveInitialScrollAction}'s per-call decision with the
|
|
746
|
-
* ACROSS-CALLS memory that decision alone can't carry. Exported (like `resolveGuardedMeasurement`)
|
|
747
|
-
* so `VirtualizedRowsInner`'s effect below calls this SAME function rather than a hand-mirrored
|
|
748
|
-
* copy for tests — a fake `scrollToEnd` is the only DOM/peer-free way to prove the guard, since a
|
|
749
|
-
* real `Virtualizer`'s own `followOnAppend` also calls the real DOM `scrollTo` on a later append,
|
|
750
|
-
* making that specific call indistinguishable from this one at the DOM boundary (see this
|
|
751
|
-
* function's test suite for the measurement that ruled that boundary out).
|
|
752
|
-
*
|
|
753
|
-
* Firing `scrollToEnd()` once is NOT the same as landing there: virtual-core 3.17.1's own
|
|
754
|
-
* `_willUpdate` (verified against the installed dist) writes to the SAME scroll container from
|
|
755
|
-
* `this.scrollOffset`, which updates only from the ASYNCHRONOUS native `scroll` event — never from
|
|
756
|
-
* the synchronous call that requested a scroll. A commit that runs `_willUpdate` before this
|
|
757
|
-
* effect gets a turn (element-attach) or that re-derives an anchor while `scrollOffset` still holds
|
|
758
|
-
* the pre-jump value writes that STALE offset straight back to `scrollTop`, undoing the jump within
|
|
759
|
-
* about one extra commit of it landing (see `./virtualize`'s fourth composition rule for the full
|
|
760
|
-
* trace this was diagnosed from). So `resolveInitialScrollAction`'s `'scroll'` outcome does not, by
|
|
761
|
-
* itself, set `hasApplied`: `isAtEnd` — a real `scrollTop`/`scrollHeight`/`clientHeight` read, the
|
|
762
|
-
* one piece of ground truth that is NEVER stale, unlike virtual-core's own tracked offset — is
|
|
763
|
-
* consulted on the NEXT call (i.e. the next commit, exactly the cadence this dependency-free effect
|
|
764
|
-
* already runs on) to confirm the jump survived. If it didn't, `scrollToEnd` fires again; if it did,
|
|
765
|
-
* `hasApplied` is set and the effect is inert for the rest of the mount. `MAX_INITIAL_SCROLL_ATTEMPTS`
|
|
766
|
-
* bounds this so a DOM that pathologically never reports settled — or a user who scrolls away mid-
|
|
767
|
-
* measurement — can never be fought forever; once exhausted, `hasApplied` is set regardless, wherever
|
|
768
|
-
* the last attempt left the container.
|
|
769
|
-
*
|
|
770
|
-
* `state.hasApplied` is the ONLY thing that can permanently stop this from calling `scrollToEnd`
|
|
771
|
-
* again: `'start'` and an empty transcript set it immediately (nothing to verify), and `'skip-retry'`
|
|
772
|
-
* deliberately leaves it `false` so a transcript that mounted behind a hidden ancestor gets another
|
|
773
|
-
* attempt on the caller's next commit, rather than being silently abandoned the moment it becomes
|
|
774
|
-
* visible. That retry — and the clobber-recovery above — is why the caller's effect carries NO
|
|
775
|
-
* dependency array: the commit that matters (a collapsed `ThreadFeedRow` flipping its body back to
|
|
776
|
-
* `display: block`, or virtual-core's own follow-up commit after this effect's own jump) changes
|
|
777
|
-
* neither the row count nor the virtualizer identity, so a dependency-keyed effect would never
|
|
778
|
-
* re-run for it.
|
|
779
|
-
*
|
|
780
|
-
* `getContainerHeight` is a THUNK, not a number, for the same reason: reading `offsetHeight` forces
|
|
781
|
-
* a synchronous layout, and it is read at most ONCE per mount — only on the very first call
|
|
782
|
-
* (`attempts === 0`) — never again while verifying or retrying, so a landed transcript still pays
|
|
783
|
-
* nothing for the effect it keeps re-running (a streaming transcript commits on every chunk).
|
|
784
|
-
* `isAtEnd` is cheaper (a plain property read, no forced reflow beyond what the browser already
|
|
785
|
-
* tracks) and is exactly what the verification/retry loop above consults instead.
|
|
786
|
-
*/
|
|
787
|
-
export function applyInitialScroll(
|
|
788
|
-
state: InitialScrollState,
|
|
789
|
-
initialScroll: NonNullable<VirtualizeOptions['initialScroll']>,
|
|
790
|
-
rowCount: number,
|
|
791
|
-
getContainerHeight: () => number,
|
|
792
|
-
scrollToEnd: () => void,
|
|
793
|
-
isAtEnd: () => boolean,
|
|
794
|
-
): void {
|
|
795
|
-
if (state.hasApplied) return
|
|
796
|
-
|
|
797
|
-
// Already fired at least once this mount — verify it survived rather than re-deriving
|
|
798
|
-
// `resolveInitialScrollAction` (row count / container height are irrelevant to "did the DOM
|
|
799
|
-
// keep the scroll we already decided on").
|
|
800
|
-
if (state.attempts > 0) {
|
|
801
|
-
if (isAtEnd() || state.attempts >= MAX_INITIAL_SCROLL_ATTEMPTS) {
|
|
802
|
-
state.hasApplied = true
|
|
803
|
-
return
|
|
804
|
-
}
|
|
805
|
-
scrollToEnd()
|
|
806
|
-
state.attempts += 1
|
|
807
|
-
return
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
const action = resolveInitialScrollAction(initialScroll, rowCount, getContainerHeight())
|
|
811
|
-
if (action === 'skip-retry') return
|
|
812
|
-
if (action === 'skip-done') {
|
|
813
|
-
state.hasApplied = true
|
|
814
|
-
return
|
|
815
|
-
}
|
|
816
|
-
scrollToEnd()
|
|
817
|
-
state.attempts += 1
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
/** Reads the transcript's own scroll container to answer "is it currently at (or within
|
|
821
|
-
* `threshold`px of) the end" — the ground-truth check {@link applyInitialScroll} verifies its jump
|
|
822
|
-
* against. Deliberately NOT `virtualizer.isAtEnd()`/`getScrollOffset()`: both are backed by
|
|
823
|
-
* `this.scrollOffset`, the exact value that lags a real scroll until the next native `scroll`
|
|
824
|
-
* event fires — using it here would make the verification vulnerable to the identical staleness
|
|
825
|
-
* that causes the clobber in the first place. `scrollTop`/`scrollHeight`/`clientHeight` are plain
|
|
826
|
-
* DOM properties with no such lag: `Element.scrollTo` with `'auto'` (this module's own behavior)
|
|
827
|
-
* updates `scrollTop` synchronously, so a read immediately after — or, as here, on the next
|
|
828
|
-
* commit — reflects reality. `null` (container not yet attached) reads as "not at end" rather than
|
|
829
|
-
* throwing, matching every other guard in this file's tolerance for a not-yet-mounted ref. */
|
|
830
|
-
function isContainerAtEnd(container: HTMLDivElement | null, threshold: number): boolean {
|
|
831
|
-
if (container === null) return false
|
|
832
|
-
const distanceFromEnd = container.scrollHeight - container.clientHeight - container.scrollTop
|
|
833
|
-
return distanceFromEnd <= threshold
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
/** Lazy-loaded real virtualizer. Resolves once, permanently, for the lifetime of this module
|
|
837
|
-
* instance — identical caching behaviour to `../agent/stick-to-bottom.tsx`'s `LazyStickToBottom`. */
|
|
838
|
-
const LazyVirtualizedRows = lazy(() =>
|
|
839
|
-
import('@tanstack/react-virtual')
|
|
840
|
-
.then(({ useVirtualizer, measureElement: defaultMeasureElement }) => {
|
|
841
|
-
function VirtualizedRowsInner({
|
|
842
|
-
rows,
|
|
843
|
-
height,
|
|
844
|
-
overscan,
|
|
845
|
-
estimateSize,
|
|
846
|
-
initialScroll,
|
|
847
|
-
className,
|
|
848
|
-
style,
|
|
849
|
-
}: VirtualizedTranscriptProps): JSX.Element {
|
|
850
|
-
const parentRef = useRef<HTMLDivElement>(null)
|
|
851
|
-
const initialScrollStateRef = useRef<InitialScrollState>({
|
|
852
|
-
hasApplied: false,
|
|
853
|
-
attempts: 0,
|
|
854
|
-
})
|
|
855
|
-
|
|
856
|
-
// Resolved research facts (virtual-core 3.17.1, carried by react-virtual 3.14.3):
|
|
857
|
-
// `getItemKey` returning `message.id` (NOT the default index) so prepending/streaming
|
|
858
|
-
// doesn't scramble anchoring; `anchorTo: 'end'` + `followOnAppend` for chat-scroll rhythm;
|
|
859
|
-
// `useFlushSync: false` per the same React-19 opt-out `BasaltVirtualList` documents.
|
|
860
|
-
const virtualizer = useVirtualizer({
|
|
861
|
-
count: rows.length,
|
|
862
|
-
getScrollElement: () => parentRef.current,
|
|
863
|
-
estimateSize: () => estimateSize,
|
|
864
|
-
overscan,
|
|
865
|
-
getItemKey: (index) => rows[index]?.key ?? index,
|
|
866
|
-
anchorTo: 'end',
|
|
867
|
-
followOnAppend: true,
|
|
868
|
-
scrollEndThreshold: DEFAULT_VIRTUALIZE_SCROLL_END_THRESHOLD,
|
|
869
|
-
useFlushSync: false,
|
|
870
|
-
// Guards against the hidden-ancestor cache-poisoning mechanism
|
|
871
|
-
// `resolveGuardedMeasurement`'s doc and `virtualize.ts`'s composition rules describe —
|
|
872
|
-
// NOT `enabled: false`, which virtual-core 3.17.1 wires to WIPE
|
|
873
|
-
// `itemSizeCache`/`measurementsCache` entirely (`getMeasurements`'s `!enabled` branch)
|
|
874
|
-
// rather than pause measurement, so toggling it off/on around a collapse would be
|
|
875
|
-
// strictly worse than the bug it was meant to fix.
|
|
876
|
-
measureElement: (element, entry, instance) =>
|
|
877
|
-
resolveGuardedMeasurement(
|
|
878
|
-
instance,
|
|
879
|
-
element,
|
|
880
|
-
defaultMeasureElement(element, entry, instance),
|
|
881
|
-
),
|
|
882
|
-
})
|
|
883
|
-
|
|
884
|
-
// The one-shot "open at the newest message" jump (`virtualize.ts`'s fourth composition
|
|
885
|
-
// rule) — see `applyInitialScroll`'s doc for the guard mechanics, including why this effect
|
|
886
|
-
// deliberately carries NO dependency array. Short version: this subtree can mount while
|
|
887
|
-
// INVISIBLE (the lazy `import()` above settles asynchronously, so a `ThreadFeedRow`
|
|
888
|
-
// collapsed during that window mounts it behind `display: none`), and the commit that makes
|
|
889
|
-
// it visible again changes no dependency a keyed array could watch. That SAME dependency-
|
|
890
|
-
// free cadence is also what lets this effect recover from virtual-core's own `_willUpdate`
|
|
891
|
-
// clobbering the jump on the commit right after it lands (see `applyInitialScroll`'s doc) —
|
|
892
|
-
// `state.hasApplied` only becomes permanent once `isContainerAtEnd` confirms it on a later
|
|
893
|
-
// call, not the instant `scrollToEnd` is invoked. `parentRef.current.offsetHeight` (not
|
|
894
|
-
// `getBoundingClientRect`) matches what virtual-core's own `getRect` reads for the scroll
|
|
895
|
-
// container, so a hidden ancestor is treated as unmeasured in exactly the cases virtual-core
|
|
896
|
-
// itself would also treat that way; it is passed as a thunk (like the `isContainerAtEnd`
|
|
897
|
-
// read below) so nothing is forced once the jump has landed and been confirmed.
|
|
898
|
-
useLayoutEffect(() => {
|
|
899
|
-
applyInitialScroll(
|
|
900
|
-
initialScrollStateRef.current,
|
|
901
|
-
initialScroll,
|
|
902
|
-
rows.length,
|
|
903
|
-
() => parentRef.current?.offsetHeight ?? 0,
|
|
904
|
-
() => virtualizer.scrollToEnd({ behavior: 'auto' }),
|
|
905
|
-
() => isContainerAtEnd(parentRef.current, DEFAULT_VIRTUALIZE_SCROLL_END_THRESHOLD),
|
|
906
|
-
)
|
|
907
|
-
})
|
|
908
|
-
|
|
909
|
-
return (
|
|
910
|
-
<Box
|
|
911
|
-
ref={parentRef}
|
|
912
|
-
className={cx(className)}
|
|
913
|
-
// theme-allow raw-scroll-container — TanStack Virtual measures/scrolls this element (never nest in BasaltStickToBottom, see ./virtualize).
|
|
914
|
-
style={{ height, overflow: 'auto', ...style }}
|
|
915
|
-
>
|
|
916
|
-
<Box style={{ height: virtualizer.getTotalSize(), position: 'relative' }}>
|
|
917
|
-
{virtualizer.getVirtualItems().map((virtualItem) => {
|
|
918
|
-
const row = rows[virtualItem.index]
|
|
919
|
-
if (row === undefined) return null
|
|
920
|
-
return (
|
|
921
|
-
<Box
|
|
922
|
-
key={row.key}
|
|
923
|
-
// Dynamic measurement of variable-height rows (messages vary a lot: a
|
|
924
|
-
// one-line reply vs. a long streamed answer with code fences) — both required
|
|
925
|
-
// together, per the resolved research facts.
|
|
926
|
-
ref={virtualizer.measureElement}
|
|
927
|
-
data-index={virtualItem.index}
|
|
928
|
-
style={{
|
|
929
|
-
position: 'absolute',
|
|
930
|
-
top: 0,
|
|
931
|
-
left: 0,
|
|
932
|
-
width: '100%',
|
|
933
|
-
transform: `translateY(${virtualItem.start}px)`,
|
|
934
|
-
}}
|
|
935
|
-
>
|
|
936
|
-
{row.node}
|
|
937
|
-
</Box>
|
|
938
|
-
)
|
|
939
|
-
})}
|
|
940
|
-
</Box>
|
|
941
|
-
</Box>
|
|
942
|
-
)
|
|
943
|
-
}
|
|
944
|
-
return { default: VirtualizedRowsInner }
|
|
945
|
-
})
|
|
946
|
-
.catch(() => ({ default: NonVirtualizedRows })),
|
|
947
|
-
)
|
|
948
|
-
Object.assign(LazyVirtualizedRows, { displayName: 'LazyVirtualizedRows' })
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* Lightweight `Suspense` fallback for `VirtualizedTranscript` — shown only for the one tick the
|
|
952
|
-
* dynamic `@tanstack/react-virtual` import takes to resolve. Deliberately NOT `NonVirtualizedRows`:
|
|
953
|
-
* see that component's doc for why mounting every real row here would be a genuine (if one-time)
|
|
954
|
-
* unmount/remount of the whole transcript. An empty, correctly-sized scroll pane avoids a layout
|
|
955
|
-
* flash without paying that cost — it settles state before any row has meaningfully mounted.
|
|
956
|
-
*/
|
|
957
|
-
function VirtualizeSuspenseFallback({
|
|
958
|
-
height,
|
|
959
|
-
className,
|
|
960
|
-
style,
|
|
961
|
-
}: BasaltProps & { readonly height: number | string }): JSX.Element {
|
|
962
|
-
// theme-allow raw-scroll-container — placeholder owns its own scroll node, matching the real virtualizer's shape.
|
|
963
|
-
return <Box className={cx(className)} style={{ height, overflow: 'auto', ...style }} />
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
function VirtualizedTranscript(props: VirtualizedTranscriptProps): JSX.Element {
|
|
967
|
-
return (
|
|
968
|
-
<Suspense
|
|
969
|
-
fallback={
|
|
970
|
-
<VirtualizeSuspenseFallback
|
|
971
|
-
height={props.height}
|
|
972
|
-
{...(props.className !== undefined && { className: props.className })}
|
|
973
|
-
{...(props.style !== undefined && { style: props.style })}
|
|
974
|
-
/>
|
|
975
|
-
}
|
|
976
|
-
>
|
|
977
|
-
<LazyVirtualizedRows {...props} />
|
|
978
|
-
</Suspense>
|
|
979
|
-
)
|
|
980
|
-
}
|
|
981
|
-
|
|
982
585
|
// ── ThreadTranscript ──────────────────────────────────────────────────────────
|
|
983
586
|
|
|
984
587
|
const EMPTY_RENDERERS: PartRenderers = {}
|
|
@@ -1194,9 +797,13 @@ export function ThreadTranscript(props: ThreadTranscriptProps): JSX.Element {
|
|
|
1194
797
|
|
|
1195
798
|
if (virtualized !== null) {
|
|
1196
799
|
return (
|
|
1197
|
-
<
|
|
800
|
+
<VirtualRows
|
|
1198
801
|
rows={rows}
|
|
1199
802
|
height={virtualized.height}
|
|
803
|
+
gap={0}
|
|
804
|
+
fallbackGap="var(--mantine-spacing-sm)"
|
|
805
|
+
anchorTo="end"
|
|
806
|
+
followOnAppend
|
|
1200
807
|
overscan={virtualized.options.overscan ?? DEFAULT_VIRTUALIZE_OVERSCAN}
|
|
1201
808
|
estimateSize={virtualized.options.estimateSize ?? DEFAULT_VIRTUALIZE_ESTIMATE_SIZE}
|
|
1202
809
|
initialScroll={virtualized.options.initialScroll ?? DEFAULT_VIRTUALIZE_INITIAL_SCROLL}
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
* `ThreadFeedRow`) — collapsing does not corrupt its measurement cache, and re-expanding restores
|
|
25
25
|
* the same scroll position (same top-visible row) it had before the collapse. This is NOT free of
|
|
26
26
|
* virtual-core: hiding an ancestor makes every mounted row's ResizeObserver box report `0` (a
|
|
27
|
-
* `display: none` ancestor un-lays-out its descendants), and virtual-core 3.
|
|
27
|
+
* `display: none` ancestor un-lays-out its descendants), and virtual-core 3.18.0's default
|
|
28
28
|
* `measureElement`/`resizeItem` write that `0` into `itemSizeCache` with no floor — unguarded, a
|
|
29
29
|
* few collapse/expand cycles permanently shrink `getTotalSize()` and silently scroll the visible
|
|
30
30
|
* window to a DIFFERENT part of the transcript (`scrollTop` stays put; the content under it moves).
|
|
31
|
-
* `
|
|
31
|
+
* `common/virtual-rows.tsx` closes this with a `measureElement` override (`resolveGuardedMeasurement`)
|
|
32
32
|
* that treats a `0` reading as unreliable and keeps the last-known size instead of committing it —
|
|
33
33
|
* see that function's doc for the full mechanism, including why `useVirtualizer`'s `enabled` option
|
|
34
34
|
* is NOT the fix (it wipes the measurement cache outright, worse than the bug). A consumer combining a
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* `useVirtualizer` call has no stale cache to poison).
|
|
38
38
|
*
|
|
39
39
|
* A fourth composition rule: a virtualized transcript SCROLLS ITSELF on mount. `initialScroll`
|
|
40
|
-
* defaults to `'end'` — `anchorTo: 'end'` and `followOnAppend` (both wired in `
|
|
40
|
+
* defaults to `'end'` — `anchorTo: 'end'` and `followOnAppend` (both wired in `common/virtual-rows.tsx`)
|
|
41
41
|
* only keep an ALREADY-at-the-end transcript pinned as content changes; neither performs the initial
|
|
42
42
|
* jump, so left alone a freshly mounted virtualized transcript renders at message #0, not the
|
|
43
43
|
* newest. The fix fires exactly once, on first mount, via `scrollToEnd()` — never again, so a user
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
* if the transcript's own scroll container measures 0px on mount (e.g. mounted behind a hidden
|
|
51
51
|
* ancestor) — it then lands on the first commit where the container is genuinely measurable, which
|
|
52
52
|
* is what makes "opens at the newest message" hold for a transcript whose lazy virtualizer settled
|
|
53
|
-
* while its `ThreadFeedRow` was collapsed. See `
|
|
53
|
+
* while its `ThreadFeedRow` was collapsed. See `common/virtual-rows.tsx`'s `applyInitialScroll` for the
|
|
54
54
|
* guard, and `VirtualizedRowsInner` for why its effect is deliberately dependency-free.
|
|
55
55
|
*
|
|
56
56
|
* Firing `scrollToEnd()` once is not sufficient on its own to land there, because virtual-core
|
|
57
|
-
* 3.
|
|
57
|
+
* 3.18.0's own `_willUpdate` writes to the SAME scroll container on the very next commit it runs
|
|
58
58
|
* on, from state that lags behind the DOM: `_scrollToOffset` only ever records the write's
|
|
59
59
|
* intent (`_intendedScrollOffset`) — `this.scrollOffset` itself updates ASYNCHRONOUSLY, from the
|
|
60
60
|
* native `scroll` event, not from the call that requested it. So a commit that runs `_willUpdate`
|