Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit dabdf26

Browse files
committed
fix react doctor warnings
1 parent 6c24d2a commit dabdf26

2 files changed

Lines changed: 22 additions & 30 deletions

File tree

packages/ui/src/features/sessions/components/ReasoningLevelDropdown.tsx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from "@posthog/quill";
2525
import { Badge } from "@posthog/ui/primitives/Badge";
2626
import { openUrlInBrowser } from "@posthog/ui/utils/browser";
27-
import { Fragment, useEffect, useRef, useState } from "react";
27+
import { Fragment, useRef, useState } from "react";
2828

2929
export interface ReasoningLevelOption {
3030
value: string;
@@ -230,27 +230,24 @@ export function ReasoningSliderFace({
230230
const matchedIndex = stops.findIndex((stop) => stop.key === currentKey);
231231
const activeIndex =
232232
matchedIndex >= 0 ? matchedIndex : Math.floor((stops.length - 1) / 2);
233-
// Continuous position so the thumb tracks the pointer fluidly; the nearest
234-
// notch is applied live and the thumb snaps to it on release.
235-
const [position, setPosition] = useState<number>(activeIndex);
236-
const draggingRef = useRef(false);
233+
// Continuous drag position so the thumb tracks the pointer fluidly; outside
234+
// a drag the thumb derives from the current selection, so releasing snaps
235+
// it to the notch the live-applied selection landed on.
236+
const [dragPosition, setDragPosition] = useState<number | null>(null);
237+
const position = dragPosition ?? activeIndex;
237238
const nearestIndex = Math.min(
238239
stops.length - 1,
239240
Math.max(0, Math.round(position)),
240241
);
241242

242-
useEffect(() => {
243-
if (!draggingRef.current) setPosition(activeIndex);
244-
}, [activeIndex]);
245-
246243
const applyNotch = (notch: number) => {
247244
const stop = stops[notch];
248245
if (stop && stop.key !== currentKey) onSelect(stop.key);
249246
};
250247

251248
const nudge = (delta: number) => {
252249
const next = Math.min(stops.length - 1, Math.max(0, nearestIndex + delta));
253-
setPosition(next);
250+
setDragPosition(null);
254251
applyNotch(next);
255252
};
256253

@@ -348,21 +345,18 @@ export function ReasoningSliderFace({
348345
onValueChange={(next: number | readonly number[]) => {
349346
const raw = Array.isArray(next) ? next[0] : next;
350347
if (typeof raw !== "number") return;
351-
draggingRef.current = true;
352-
setPosition(raw);
348+
setDragPosition(raw);
353349
// Applied per notch crossing so the trigger pill tracks the drag.
354350
applyNotch(Math.round(raw));
355351
}}
356352
onValueCommitted={(next: number | readonly number[]) => {
357353
const raw = Array.isArray(next) ? next[0] : next;
358-
draggingRef.current = false;
359-
if (typeof raw !== "number") return;
360-
const notch = Math.min(
361-
stops.length - 1,
362-
Math.max(0, Math.round(raw)),
363-
);
364-
setPosition(notch);
365-
applyNotch(notch);
354+
if (typeof raw === "number") {
355+
applyNotch(
356+
Math.min(stops.length - 1, Math.max(0, Math.round(raw))),
357+
);
358+
}
359+
setDragPosition(null);
366360
}}
367361
/>
368362
<div className="-translate-y-1/2 pointer-events-none absolute inset-x-2 top-1/2 flex justify-between">

packages/ui/src/features/sessions/components/ReasoningLevelSelector.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function AnimatedHeight({ children }: { children: React.ReactNode }) {
107107
);
108108
}
109109

110-
export function toDropdownOptions(
110+
function toDropdownOptions(
111111
option: SessionConfigOption,
112112
): ReasoningLevelOption[] {
113113
if (option.type !== "select") return [];
@@ -269,6 +269,7 @@ export function ReasoningLevelSelector({
269269
valueLabel:
270270
options.find((entry) => entry.value === option.currentValue)?.label ??
271271
option.currentValue,
272+
defaultValue: options.find((entry) => entry.isDefault)?.value,
272273
options,
273274
},
274275
];
@@ -294,11 +295,8 @@ export function ReasoningLevelSelector({
294295
}
295296
}
296297
for (const row of toggleRows) {
297-
const rowDefault = row.options.find(
298-
(option) => option.isDefault,
299-
)?.value;
300-
if (rowDefault && rowDefault !== row.value) {
301-
onConfigOptionChange?.(row.id, rowDefault);
298+
if (row.defaultValue && row.defaultValue !== row.value) {
299+
onConfigOptionChange?.(row.id, row.defaultValue);
302300
}
303301
}
304302
if (fastSelect && fastSelect.currentValue !== "off") {
@@ -451,8 +449,8 @@ export function ReasoningLevelSelector({
451449
? modelGroups.map((group, index) => (
452450
<Fragment key={group.group}>
453451
{index > 0 && <DropdownMenuSeparator />}
454-
{[...group.options]
455-
.sort((a, b) =>
452+
{group.options
453+
.toSorted((a, b) =>
456454
compareModelsForPicker(a.value, b.value),
457455
)
458456
.map((model) => (
@@ -463,8 +461,8 @@ export function ReasoningLevelSelector({
463461
))}
464462
</Fragment>
465463
))
466-
: [...modelEntries]
467-
.sort((a, b) =>
464+
: modelEntries
465+
.toSorted((a, b) =>
468466
compareModelsForPicker(a.value, b.value),
469467
)
470468
.map((model) => (

0 commit comments

Comments
 (0)