The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 15:45 UTC
chore(lint): enforce react/refs (#25116)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 25, 2026 at 21:31 UTC
beeb2159e132f2e3bfb60cbd217d9ed386ce7699
9 files changed
+61
-30
apps/mobile/src/components/ui/Menu.tsx
+2
@@ -51,6 +51,7 @@ export function Menu(props: MenuProps) {
51
let children = menuProps.children;
52
if (props.shouldOpenOnLongPress && isValidElement(children)) {
53
const child = children as ReactElement<Pick<PressableProps, "onTouchStart" | "onPress">>;
54
+ /* oxlint-disable react/refs -- Cloning the trigger installs event callbacks; the refs are accessed when those callbacks run. */
55
children = cloneElement(child, {
56
onTouchStart: (event) => {
57
// onPressIn can repeat within one gesture when a finger leaves and re-enters the row.
@@ -74,6 +75,7 @@ export function Menu(props: MenuProps) {
75
child.props.onPress?.(event);
76
},
77
});
78
+ /* oxlint-enable react/refs */
79
menuProps.onMenuInteractionStart = () => {
80
menuPress.current.isPreparing = true;
81
props.onMenuInteractionStart?.();
apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts
+2
@@ -387,6 +387,7 @@ function NativeReviewDiffContent(
387
return null;
388
}
389
390
+ /* oxlint-disable react/refs -- The native view receives this ref; only event callbacks access its current value. */
391
return createElement(RawNativeView, {
392
...nativeProps,
393
refreshEnabled: props.onPullToRefresh !== undefined,
@@ -399,6 +400,7 @@ function NativeReviewDiffContent(
400
},
401
ref: nativeRef,
402
});
403
+ /* oxlint-enable react/refs */
404
}
405
406
export function resolveNativeReviewDiffView(): ComponentType<NativeReviewDiffViewProps> | null {
apps/mobile/src/features/home/thread-swipe-actions.tsx
+5
-1
@@ -506,7 +506,11 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
506
rightThreshold={actionsWidth * 0.42}
507
simultaneousWith={props.simultaneousWith}
508
>
509
- {props.children(close)}
509
+ {
510
+ /* oxlint-disable react/refs -- The render callback receives a close/open handler; only invoking that handler accesses the ref. */
511
+ props.children(close)
512
+ /* oxlint-enable react/refs */
513
+ }
514
</ReanimatedSwipeable>
515
</View>
516
</Animated.View>
apps/mobile/src/features/threads/ThreadArrangementSheet.tsx
+4
-1
@@ -102,6 +102,7 @@ function DragHandle(props: {
102
canMoveDown: boolean;
103
}) {
104
const latest = useRef(props);
105
+ /* oxlint-disable react/refs -- The pan gesture captures its callbacks once per `disabled` change; they read the latest handlers when native gesture events fire. */
106
latest.current = props;
107
const gesture = useMemo(
108
() =>
@@ -117,6 +118,7 @@ function DragHandle(props: {
118
.onFinalize((_, success) => latest.current.onEnd(!success)),
119
[props.disabled, latest],
120
);
121
+ /* oxlint-enable react/refs */
122
return (
123
<GestureDetector gesture={gesture}>
124
<View
@@ -271,8 +273,9 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
273
const drag = useRef<Drag | null>(null);
274
const frame = useRef<number | null>(null);
275
const [preview, setPreview] = useState<Drag | null>(null);
274
- const translateY = useRef(new Animated.Value(0)).current;
276
+ const [translateY] = useState(() => new Animated.Value(0));
277
const latest = useRef({ rows, planners, moveThread });
278
+ // oxlint-disable-next-line react/refs -- The autoscroll rAF loop started at drag start reads the current rows and planners on every frame.
279
latest.current = { rows, planners, moveThread };
280
281
function stop() {
apps/mobile/src/features/voice-input/VoiceInputProvider.tsx
+14
-15
@@ -3,7 +3,6 @@ import {
3
AudioModule,
4
RecordingPresets,
5
requestRecordingPermissionsAsync,
6
- type RecorderState,
6
type RecordingStatus,
7
} from "expo-audio";
8
import { File } from "expo-file-system";
@@ -35,7 +34,7 @@ import {
34
voiceInputBlocksSubmission,
35
type VoiceInputState,
36
} from "@t3tools/client-runtime/voice-input";
38
-import { createLazyVoiceRecorder, type LazyVoiceRecorder } from "./lazyVoiceRecorder";
37
+import { createLazyVoiceRecorder } from "./lazyVoiceRecorder";
38
import { normalizeVoiceInputDecibels, VOICE_WAVEFORM_SAMPLE_COUNT } from "./voiceInputMetering";
39
import { VoiceInputSession } from "./voiceInputSession";
40
import {
@@ -93,17 +92,18 @@ function useVoiceInputRuntime() {
92
const keepAwakeId = useId();
93
const keepAwakeSessionRef = useRef(0);
94
const elapsedSecondsRef = useRef(0);
96
- const audioLevelsRef = useRef(Array<number>(VOICE_WAVEFORM_SAMPLE_COUNT).fill(0));
97
- const audioLevels = useSharedValue(audioLevelsRef.current);
98
- const sessionRef = useRef<VoiceInputSession | null>(null);
99
- const recorderRef = useRef<LazyVoiceRecorder<RecorderState> | null>(null);
95
+ const [initialLevels] = useState(() => Array<number>(VOICE_WAVEFORM_SAMPLE_COUNT).fill(0));
96
+ const audioLevelsRef = useRef(initialLevels);
97
+ const audioLevels = useSharedValue(initialLevels);
98
const audioToken = useRef<ReturnType<typeof acquireAudioSession> | null>(null);
99
102
- if (!sessionRef.current || !recorderRef.current) {
100
+ /* oxlint-disable react/refs -- The initializer captures the audio-session ref for later recording callbacks; it does not read it. */
101
+ const [{ session, recorder }] = useState(() => {
102
+ let session: VoiceInputSession | null = null;
103
const recorder = createLazyVoiceRecorder({
104
create: () => new AudioModule.AudioRecorder(VOICE_RECORDING_OPTIONS),
105
onStatus: (status: RecordingStatus) => {
106
- sessionRef.current?.controller.handleRecorderStatus({
106
+ session?.controller.handleRecorderStatus({
107
isFinished: status.isFinished,
108
hasError: status.hasError || status.mediaServicesDidReset === true,
109
error: status.error,
@@ -126,8 +126,7 @@ function useVoiceInputRuntime() {
126
return preferredMicrophoneInput(inputs, order);
127
},
128
});
129
- recorderRef.current = recorder;
130
- sessionRef.current = new VoiceInputSession({
129
+ session = new VoiceInputSession({
130
recorder,
131
getTranscriber: getLocalVoiceTranscriber,
132
requestPermission: async () => {
@@ -152,15 +151,15 @@ function useVoiceInputRuntime() {
151
onStateChange: (nextState) =>
152
setState({
153
state: nextState,
155
- ownerKey: sessionRef.current?.ownerKey ?? null,
156
- label: sessionRef.current?.label ?? null,
154
+ ownerKey: session?.ownerKey ?? null,
155
+ label: session?.label ?? null,
156
}),
157
});
159
- }
158
+ return { session, recorder };
159
+ });
160
+ /* oxlint-enable react/refs */
161
161
- const session = sessionRef.current;
162
const controller = session.controller;
163
- const recorder = recorderRef.current;
163
164
useEffect(() => {
165
const subscription = AppState.addEventListener("change", (nextState) => {
apps/mobile/src/features/voice-input/useVoiceInputController.ts
+1
@@ -24,6 +24,7 @@ export function useVoiceInputController(input: {
24
const global = useGlobalVoiceInput();
25
const { setOwnerFocused, session } = global;
26
const latestInput = useRef(input);
27
+ // oxlint-disable-next-line react/refs -- Transcription finishes asynchronously and must reach the composer's current selection setter, not the one captured at start.
28
latestInput.current = input;
29
const mounted = useRef(true);
30
useEffect(() => {
apps/mobile/src/native/T3ComposerEditor.ios.tsx
+16
-6
@@ -139,7 +139,19 @@ export function ComposerEditor({
139
const [, forceNativeEventRender] = useState(0);
140
// Start history empty so restored drafts or recycled views receive a non-echo controlled payload.
141
const nativeEventSnapshotsRef = useRef<ComposerNativeEventSnapshot[]>([]);
142
- const confirmedTokensRef = useRef(collectComposerInlineTokens(props.value));
142
+ // Tokens advance from the previous committed value; render-phase state keeps
143
+ // an abandoned render from leaking a trailing token into the next one.
144
+ const [confirmedTokens, setConfirmedTokens] = useState(() => ({
145
+ value: props.value,
146
+ tokens: collectComposerInlineTokens(props.value),
147
+ }));
148
+ let tokens = confirmedTokens.tokens;
149
+ if (confirmedTokens.value !== props.value) {
150
+ tokens = collectComposerInlineTokens(props.value, {
151
+ preserveTrailingFrom: confirmedTokens.tokens,
152
+ });
153
+ setConfirmedTokens({ value: props.value, tokens });
154
+ }
155
const bodyText = useScaledTextRole("body");
156
const theme = useUniwindTheme();
157
const fontFamily = FONT_FAMILIES.regular;
@@ -158,10 +170,6 @@ export function ComposerEditor({
170
const skillLabels = useMemo(() => composerSkillLabels(skills), [skills]);
171
const chipTextColor = createNativeComposerTheme(theme).text;
172
const tokensJson = useMemo(() => {
161
- const tokens = collectComposerInlineTokens(props.value, {
162
- preserveTrailingFrom: confirmedTokensRef.current,
163
- });
164
- confirmedTokensRef.current = tokens;
173
return JSON.stringify(
174
composerContextEditorTokens(props.value, tokens, skillLabels).map((token) => {
175
const record =
@@ -194,11 +202,12 @@ export function ComposerEditor({
202
};
203
}),
204
);
197
- }, [props.value, props.context, skillLabels, theme, chipTextColor, confirmedTokensRef]);
205
+ }, [props.value, tokens, props.context, skillLabels, theme, chipTextColor]);
206
// Every render resolves against the snapshot history, so a render whose
207
// (value, selection) lags the acknowledged native state is stamped behind
208
// the native revision and rejected by the editor instead of re-applying a
209
// stale caret or stale text mid-typing.
210
+ /* oxlint-disable react/refs -- Native controlled edits must reconcile against the last acknowledged native event before sending the next payload. */
211
const controlledEventCount = resolveComposerControlledEventCount(
212
props.value,
213
selection ?? null,
@@ -211,6 +220,7 @@ export function ComposerEditor({
220
mostRecentEventCount,
221
nativeEventSnapshotsRef.current,
222
);
223
+ /* oxlint-enable react/refs */
224
const isNativeEcho =
225
controlledEventCount === mostRecentEventCount && acknowledgesLatestNativeEvent;
226
const controlledDocumentJson = JSON.stringify({
apps/mobile/src/native/T3ComposerEditor.native.tsx
+16
-7
@@ -137,8 +137,19 @@ export function ComposerEditor({
137
const [, forceNativeEventRender] = useState(0);
138
// Start history empty so restored drafts or recycled views receive a non-echo controlled payload.
139
const nativeEventSnapshotsRef = useRef<ComposerNativeEventSnapshot[]>([]);
140
- const [initialConfirmedTokens] = useState(() => collectComposerInlineTokens(props.value));
141
- const confirmedTokensRef = useRef(initialConfirmedTokens);
140
+ // Tokens advance from the previous committed value; render-phase state keeps
141
+ // an abandoned render from leaking a trailing token into the next one.
142
+ const [confirmedTokens, setConfirmedTokens] = useState(() => ({
143
+ value: props.value,
144
+ tokens: collectComposerInlineTokens(props.value),
145
+ }));
146
+ let tokens = confirmedTokens.tokens;
147
+ if (confirmedTokens.value !== props.value) {
148
+ tokens = collectComposerInlineTokens(props.value, {
149
+ preserveTrailingFrom: confirmedTokens.tokens,
150
+ });
151
+ setConfirmedTokens({ value: props.value, tokens });
152
+ }
153
const theme = useUniwindTheme();
154
const handlePaste = useNativePaste((uris) => onPasteImages?.(uris));
155
@@ -156,10 +167,6 @@ export function ComposerEditor({
167
const skillLabels = useMemo(() => composerSkillLabels(skills), [skills]);
168
const chipTextColor = createNativeComposerTheme(theme).text;
169
const tokensJson = useMemo(() => {
159
- const tokens = collectComposerInlineTokens(props.value, {
160
- preserveTrailingFrom: confirmedTokensRef.current,
161
- });
162
- confirmedTokensRef.current = tokens;
170
return JSON.stringify(
171
composerContextEditorTokens(props.value, tokens, skillLabels).map((token) => {
172
const record =
@@ -192,11 +199,12 @@ export function ComposerEditor({
199
};
200
}),
201
);
195
- }, [props.value, props.context, skillLabels, theme, chipTextColor, confirmedTokensRef]);
202
+ }, [props.value, tokens, props.context, skillLabels, theme, chipTextColor]);
203
// Every render resolves against the snapshot history, so a render whose
204
// (value, selection) lags the acknowledged native state is stamped behind
205
// the native revision and rejected by the editor instead of re-applying a
206
// stale caret or stale text mid-typing.
207
+ /* oxlint-disable react/refs -- Native controlled edits must reconcile against the last acknowledged native event before sending the next payload. */
208
const controlledEventCount = resolveComposerControlledEventCount(
209
props.value,
210
selection ?? null,
@@ -209,6 +217,7 @@ export function ComposerEditor({
217
mostRecentEventCount,
218
nativeEventSnapshotsRef.current,
219
);
220
+ /* oxlint-enable react/refs */
221
const isNativeEcho =
222
controlledEventCount === mostRecentEventCount && acknowledgesLatestNativeEvent;
223
const controlledDocumentJson = JSON.stringify({
vite.config.ts
+1
@@ -228,6 +228,7 @@ export default defineConfig({
228
"react/jsx-no-constructed-context-values": "off",
229
"react/memo-dependencies": "error",
230
"react/purity": "error",
231
+ "react/refs": "error",
232
"react/immutability": "error",
233
"react/no-array-index-key": "error",
234
"react/no-unstable-nested-components": "error",