Skip to content
TypeScript

chore(lint): enforce react/purity (#25038)

Julius Marminge1de64942be49
diff --git a/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx b/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
index 49980f89ce9..8c6df5a7715 100644
--- a/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
+++ b/apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
@@ -348,6 +348,7 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
};
setPreview({ ...drag.current });
update(0);
+ // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
let last = performance.now();
const tick = () => {
const current = drag.current;
diff --git a/apps/mobile/src/features/threads/thread-list-v2-items.tsx b/apps/mobile/src/features/threads/thread-list-v2-items.tsx
index 5d458ede8e0..57f2d75671d 100644
--- a/apps/mobile/src/features/threads/thread-list-v2-items.tsx
+++ b/apps/mobile/src/features/threads/thread-list-v2-items.tsx
@@ -709,6 +709,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
const canUnsettle = variant === "slim";
// Keep time in state; cached render-time reads freeze the gate and trigger 50ms expiry loops.
const [snoozeGateClock, setSnoozeGateClock] = useState(() => ({ thread, now: Date.now() }));
+ // oxlint-disable-next-line react/purity -- Reseeds the snooze gate clock only in the render-phase adjustment that runs when the thread changes.
if (snoozeGateClock.thread !== thread) setSnoozeGateClock({ thread, now: Date.now() });
const snoozeGateNow = new Date(snoozeGateClock.now).toISOString();
const snoozeGateExpiryMs = props.snoozeSupported
@@ -730,6 +731,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
snoozed: snoozedRow,
});
const snoozePresets = useMemo(
+ // oxlint-disable-next-line react/purity -- The memo recomputes on the snoozePresetMinute tick, so preset times refresh every minute.
() => (swipeActions.secondary === "snooze" ? resolveSnoozePresets(new Date()) : ([] as const)),
// oxlint-disable-next-line react/memo-dependencies -- The minute tick refreshes relative snooze times while the row remains mounted.
[props.snoozePresetMinute, swipeActions.secondary],
diff --git a/apps/web/src/components/CommandPalette.tsx b/apps/web/src/components/CommandPalette.tsx
index 8c8e170d923..a89c3960fd9 100644
--- a/apps/web/src/components/CommandPalette.tsx
+++ b/apps/web/src/components/CommandPalette.tsx
@@ -2060,6 +2060,7 @@ function OpenCommandPaletteDialog(props: {
input: {
projectId,
title: inferProjectTitleFromPath(destinationPath),
+ // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
createdAt: new Date().toISOString(),
remoteUrl: addProjectCloneFlow.remoteUrl,
destinationPath,
diff --git a/apps/web/src/components/CommandPaletteThreadItems.tsx b/apps/web/src/components/CommandPaletteThreadItems.tsx
index 5312e13893b..d106b4d1069 100644
--- a/apps/web/src/components/CommandPaletteThreadItems.tsx
+++ b/apps/web/src/components/CommandPaletteThreadItems.tsx
@@ -164,6 +164,7 @@ export function useCommandPaletteThreadItems(input: {
const isOpen =
activeThread?.environmentId === thread.environmentId && activeThread.id === thread.id;
if (threadSearchQuery.trim().length > 0 && !threadSearchQuery.startsWith(">") && !isOpen) {
+ // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
claimThreadOpen(thread.environmentId, thread.id, Date.now());
}
if (
diff --git a/apps/web/src/components/CustomSnoozeDialog.tsx b/apps/web/src/components/CustomSnoozeDialog.tsx
index 670df0e3e12..74414dc5f1e 100644
--- a/apps/web/src/components/CustomSnoozeDialog.tsx
+++ b/apps/web/src/components/CustomSnoozeDialog.tsx
@@ -10,6 +10,7 @@ import { Button } from "./ui/button";
import { CalendarIcon } from "lucide-react";
import { Calendar } from "./ui/calendar";
import { weekStartsOn } from "../timestampFormat";
+import { useNowMinute } from "../hooks/useNowMinute";
import { Popover, PopoverTrigger, PopoverPopup } from "./ui/popover";
import { Input } from "./ui/input";
import { Label } from "./ui/label";
@@ -47,6 +48,12 @@ function finish(choice: SnoozeChoice | null) {
request?.resolve(choice);
}
+function startOfLocalDay(ms: number) {
+ const day = new Date(ms);
+ day.setHours(0, 0, 0, 0);
+ return day;
+}
+
export function CustomSnoozeDialogHost() {
const request = useRequest((state) => state.request);
useEffect(() => () => finish(null), []);
@@ -56,6 +63,9 @@ export function CustomSnoozeDialogHost() {
function CustomSnoozeDialog() {
const id = useId();
const [initial] = useState(() => new Date(Date.now() + 3_600_000));
+ const nowMinute = useNowMinute();
+ // Follows the clock so a dialog left open past midnight stops offering yesterday.
+ const today = startOfLocalDay(Date.parse(`${nowMinute}Z`));
const [mode, setMode] = useState<CustomSnoozeInput["mode"]>("date");
const [date, setDate] = useState(initial);
const [calendarOpen, setCalendarOpen] = useState(false);
@@ -137,7 +147,7 @@ function CustomSnoozeDialog() {
selected={date}
defaultMonth={date}
{...(weekStartsOn === undefined ? {} : { weekStartsOn })}
- disabled={{ before: new Date(new Date().setHours(0, 0, 0, 0)) }}
+ disabled={{ before: today }}
onSelect={(selected) => {
setDate(selected);
setCalendarOpen(false);
diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx
index ff27e688768..29ca99efee3 100644
--- a/apps/web/src/components/Sidebar.tsx
+++ b/apps/web/src/components/Sidebar.tsx
@@ -1174,6 +1174,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
return thread ? threadSearchSubject(thread, null) : undefined;
},
foldSearchQuery(threadSearchQuery),
+ // oxlint-disable-next-line react/purity -- Recency ranking samples the clock when the search matches change; the compiler recomputes it only then.
Date.now(),
// A list filter, as on mobile: a pick would move rows unexplained.
{ picks: false },
diff --git a/apps/web/src/components/chat/useThreadLifecycle.tsx b/apps/web/src/components/chat/useThreadLifecycle.tsx
index 77a47eeb482..d992a11315d 100644
--- a/apps/web/src/components/chat/useThreadLifecycle.tsx
+++ b/apps/web/src/components/chat/useThreadLifecycle.tsx
@@ -179,6 +179,7 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
now: new Date().toISOString(),
}));
if (snoozeClockState.shell !== activeThreadShell) {
+ // oxlint-disable-next-line react/purity -- Reseeds the snooze clock only in the render-phase adjustment that runs when the shell changes.
setSnoozeClockState({ shell: activeThreadShell, now: new Date().toISOString() });
}
const snoozeClock = snoozeClockState.now;
diff --git a/apps/web/src/components/sidebar/SidebarThreadRow.tsx b/apps/web/src/components/sidebar/SidebarThreadRow.tsx
index efd23bfe265..7e631a9acaa 100644
--- a/apps/web/src/components/sidebar/SidebarThreadRow.tsx
+++ b/apps/web/src/components/sidebar/SidebarThreadRow.tsx
@@ -370,6 +370,7 @@ function SnoozeMenuButton(props: {
timestampFormat: TimestampFormat;
}) {
const { open, onOpenChange, onSnooze, timestampFormat } = props;
+ // oxlint-disable-next-line react/purity -- Presets are resolved only while the menu is open, so each opening reads a fresh time.
const presets = open ? resolveSnoozePresets(new Date(), timestampFormat) : [];
return (
<Menu open={open} onOpenChange={onOpenChange}>
@@ -857,6 +858,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
now: new Date().toISOString(),
}));
if (snoozeGateClock.thread !== thread) {
+ // oxlint-disable-next-line react/purity -- Reseeds the snooze gate clock only in the render-phase adjustment that runs when the thread changes.
setSnoozeGateClock({ thread, now: new Date().toISOString() });
}
const snoozeGateNow = snoozeGateClock.now;
diff --git a/apps/web/src/hooks/useThreadActions.ts b/apps/web/src/hooks/useThreadActions.ts
index 00138102ee7..376bb207530 100644
--- a/apps/web/src/hooks/useThreadActions.ts
+++ b/apps/web/src/hooks/useThreadActions.ts
@@ -723,9 +723,9 @@ export function useThreadActions() {
);
}
const resolved = resolveThreadTarget(target);
- const wokeAt = resolved
- ? threadWokeAt(resolved.thread, { now: new Date().toISOString() })
- : null;
+ // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
+ const nowIso = new Date().toISOString();
+ const wokeAt = resolved ? threadWokeAt(resolved.thread, { now: nowIso }) : null;
const undoPlan = ThreadUndo.planThreadUndo("settle", resolved?.thread);
// An older unpin/snooze Undo would re-pin or re-snooze, and the server
// treats either as a promotion that un-settles; settling supersedes them.
@@ -836,6 +836,7 @@ export function useThreadActions() {
);
}
const resolved = resolveThreadTarget(target);
+ // oxlint-disable-next-line react/purity -- runs in an event handler (oxc#27309)
if (resolved && !canSnooze(resolved.thread, { now: new Date().toISOString() })) {
return AsyncResult.failure(
Cause.fail(
diff --git a/vite.config.ts b/vite.config.ts
index d37e8f0d103..1352189136e 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -227,6 +227,7 @@ export default defineConfig({
"react/no-object-type-as-default-prop": "off",
"react/jsx-no-constructed-context-values": "off",
"react/memo-dependencies": "error",
+ "react/purity": "error",
"react/immutability": "error",
"react/no-array-index-key": "error",
"react/no-unstable-nested-components": "error",
@@ -580,10 +581,10 @@ export default defineConfig({
"react/jsx-no-constructed-context-values": "off",
"react/memo-dependencies": "error",
"react/preserve-manual-memoization": "error",
- // oxlint 1.88 treats `new Date()` as impure (oxc#26894) and also flags it inside event
- // handlers (oxc#27309). The compiler we ship (oxc-transform-react) still compiles
- // those files, and reactCompilerCoverage.test.ts fails on real bailouts.
- "react/purity": "warn",
+ // Render-time clock reads use @t3tools/client-runtime/clock or state seeded with the
+ // time; any other read carries a suppression that says why. oxlint also flags time reads
+ // inside event handlers (oxc#27309); those suppressions cite it.
+ "react/purity": "error",
"react/refs": "error",
"react/set-state-in-effect": "error",
"react/set-state-in-render": "error",