Skip to content

Commit 34f38a3

Browse files
chore(lint): enforce react/refs
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 80b48cc commit 34f38a3

11 files changed

Lines changed: 44 additions & 18 deletions

‎apps/mobile/src/components/ui/AndroidAnchoredMenu.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ export function AndroidAnchoredMenu(props: AndroidAnchoredMenuProps) {
145145
<>
146146
{typeof props.children === "function" ? (
147147
<View ref={anchorRef} collapsable={false} className={props.className} style={props.style}>
148-
{props.children(open)}
148+
{
149+
/* oxlint-disable react/refs -- Cloning the trigger installs event callbacks; the refs are accessed when those callbacks run. */
150+
props.children(open)
151+
/* oxlint-enable react/refs */
152+
}
149153
</View>
150154
) : (
151155
<Pressable

‎apps/mobile/src/components/ui/Menu.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function Menu(props: MenuProps) {
5151
let children = menuProps.children;
5252
if (props.shouldOpenOnLongPress && isValidElement(children)) {
5353
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. */
5455
children = cloneElement(child, {
5556
onTouchStart: (event) => {
5657
// onPressIn can repeat within one gesture when a finger leaves and re-enters the row.
@@ -74,6 +75,7 @@ export function Menu(props: MenuProps) {
7475
child.props.onPress?.(event);
7576
},
7677
});
78+
/* oxlint-enable react/refs */
7779
menuProps.onMenuInteractionStart = () => {
7880
menuPress.current.isPreparing = true;
7981
props.onMenuInteractionStart?.();

‎apps/mobile/src/features/diffs/nativeReviewDiffSurface.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ function NativeReviewDiffContent(
387387
return null;
388388
}
389389

390+
/* oxlint-disable react/refs -- The native view receives this ref; only event callbacks access its current value. */
390391
return createElement(RawNativeView, {
391392
...nativeProps,
392393
refreshEnabled: props.onPullToRefresh !== undefined,
@@ -399,6 +400,7 @@ function NativeReviewDiffContent(
399400
},
400401
ref: nativeRef,
401402
});
403+
/* oxlint-enable react/refs */
402404
}
403405

404406
export function resolveNativeReviewDiffView(): ComponentType<NativeReviewDiffViewProps> | null {

‎apps/mobile/src/features/home/thread-swipe-actions.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,11 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
506506
rightThreshold={actionsWidth * 0.42}
507507
simultaneousWith={props.simultaneousWith}
508508
>
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+
}
510514
</ReanimatedSwipeable>
511515
</View>
512516
</Animated.View>

‎apps/mobile/src/features/threads/ThreadArrangementSheet.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ function DragHandle(props: {
102102
canMoveDown: boolean;
103103
}) {
104104
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. */
105106
latest.current = props;
106107
const gesture = useMemo(
107108
() =>
@@ -117,6 +118,7 @@ function DragHandle(props: {
117118
.onFinalize((_, success) => latest.current.onEnd(!success)),
118119
[props.disabled],
119120
);
121+
/* oxlint-enable react/refs */
120122
return (
121123
<GestureDetector gesture={gesture}>
122124
<View
@@ -271,8 +273,9 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
271273
const drag = useRef<Drag | null>(null);
272274
const frame = useRef<number | null>(null);
273275
const [preview, setPreview] = useState<Drag | null>(null);
274-
const translateY = useRef(new Animated.Value(0)).current;
276+
const [translateY] = useState(() => new Animated.Value(0));
275277
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.
276279
latest.current = { rows, planners, moveThread };
277280

278281
function stop() {

‎apps/mobile/src/features/voice-input/VoiceInputProvider.tsx‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
AudioModule,
44
RecordingPresets,
55
requestRecordingPermissionsAsync,
6-
type RecorderState,
76
type RecordingStatus,
87
} from "expo-audio";
98
import { File } from "expo-file-system";
@@ -35,7 +34,7 @@ import {
3534
voiceInputBlocksSubmission,
3635
type VoiceInputState,
3736
} from "@t3tools/client-runtime/voice-input";
38-
import { createLazyVoiceRecorder, type LazyVoiceRecorder } from "./lazyVoiceRecorder";
37+
import { createLazyVoiceRecorder } from "./lazyVoiceRecorder";
3938
import { normalizeVoiceInputDecibels, VOICE_WAVEFORM_SAMPLE_COUNT } from "./voiceInputMetering";
4039
import { VoiceInputSession } from "./voiceInputSession";
4140
import {
@@ -93,17 +92,18 @@ function useVoiceInputRuntime() {
9392
const keepAwakeId = useId();
9493
const keepAwakeSessionRef = useRef(0);
9594
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);
10098
const audioToken = useRef<ReturnType<typeof acquireAudioSession> | null>(null);
10199

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;
103103
const recorder = createLazyVoiceRecorder({
104104
create: () => new AudioModule.AudioRecorder(VOICE_RECORDING_OPTIONS),
105105
onStatus: (status: RecordingStatus) => {
106-
sessionRef.current?.controller.handleRecorderStatus({
106+
session?.controller.handleRecorderStatus({
107107
isFinished: status.isFinished,
108108
hasError: status.hasError || status.mediaServicesDidReset === true,
109109
error: status.error,
@@ -126,8 +126,7 @@ function useVoiceInputRuntime() {
126126
return preferredMicrophoneInput(inputs, order);
127127
},
128128
});
129-
recorderRef.current = recorder;
130-
sessionRef.current = new VoiceInputSession({
129+
session = new VoiceInputSession({
131130
recorder,
132131
getTranscriber: getLocalVoiceTranscriber,
133132
requestPermission: async () => {
@@ -152,15 +151,15 @@ function useVoiceInputRuntime() {
152151
onStateChange: (nextState) =>
153152
setState({
154153
state: nextState,
155-
ownerKey: sessionRef.current?.ownerKey ?? null,
156-
label: sessionRef.current?.label ?? null,
154+
ownerKey: session?.ownerKey ?? null,
155+
label: session?.label ?? null,
157156
}),
158157
});
159-
}
158+
return { session, recorder };
159+
});
160+
/* oxlint-enable react/refs */
160161

161-
const session = sessionRef.current;
162162
const controller = session.controller;
163-
const recorder = recorderRef.current;
164163

165164
useEffect(() => {
166165
const subscription = AppState.addEventListener("change", (nextState) => {

‎apps/mobile/src/features/voice-input/useVoiceInputController.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function useVoiceInputController(input: {
2424
const global = useGlobalVoiceInput();
2525
const { setOwnerFocused, session } = global;
2626
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.
2728
latestInput.current = input;
2829
const mounted = useRef(true);
2930
useEffect(() => {

‎apps/mobile/src/native/StackHeader.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export function NativeStackScreenOptions(props: {
195195
const latestOptionFunctionsRef = useRef(new Map<string, (...args: unknown[]) => unknown>());
196196
const optionFunctionWrappersRef = useRef(new Map<string, (...args: unknown[]) => unknown>());
197197
const normalizedOptions = useMemo(() => normalizeScreenOptions(props.options), [props.options]);
198+
/* oxlint-disable react/refs -- Native navigation needs stable callback wrappers across renders; these maps retain wrapper identity. */
198199
const stableOptions = normalizedOptions
199200
? (stabilizeOptionFunctions(
200201
normalizedOptions,
@@ -203,6 +204,7 @@ export function NativeStackScreenOptions(props: {
203204
optionFunctionWrappersRef.current,
204205
) as NativeStackNavigationOptions)
205206
: undefined;
207+
/* oxlint-enable react/refs */
206208

207209
useLayoutEffect(() => {
208210
if (!tabActive) {

‎apps/mobile/src/native/T3ComposerEditor.ios.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,12 @@ export function ComposerEditor({
158158
const skillLabels = useMemo(() => composerSkillLabels(skills), [skills]);
159159
const chipTextColor = createNativeComposerTheme(theme).text;
160160
const tokensJson = useMemo(() => {
161+
/* oxlint-disable react/refs -- Native controlled edits must reconcile against the last acknowledged native event before sending the next payload. */
161162
const tokens = collectComposerInlineTokens(props.value, {
162163
preserveTrailingFrom: confirmedTokensRef.current,
163164
});
164165
confirmedTokensRef.current = tokens;
166+
/* oxlint-enable react/refs */
165167
return JSON.stringify(
166168
composerContextEditorTokens(props.value, tokens, skillLabels).map((token) => {
167169
const record =
@@ -199,6 +201,7 @@ export function ComposerEditor({
199201
// (value, selection) lags the acknowledged native state is stamped behind
200202
// the native revision and rejected by the editor instead of re-applying a
201203
// stale caret or stale text mid-typing.
204+
/* oxlint-disable react/refs -- Native controlled edits must reconcile against the last acknowledged native event before sending the next payload. */
202205
const controlledEventCount = resolveComposerControlledEventCount(
203206
props.value,
204207
selection ?? null,
@@ -211,6 +214,7 @@ export function ComposerEditor({
211214
mostRecentEventCount,
212215
nativeEventSnapshotsRef.current,
213216
);
217+
/* oxlint-enable react/refs */
214218
const isNativeEcho =
215219
controlledEventCount === mostRecentEventCount && acknowledgesLatestNativeEvent;
216220
const controlledDocumentJson = JSON.stringify({

‎apps/mobile/src/native/T3ComposerEditor.native.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ export function ComposerEditor({
156156
const skillLabels = useMemo(() => composerSkillLabels(skills), [skills]);
157157
const chipTextColor = createNativeComposerTheme(theme).text;
158158
const tokensJson = useMemo(() => {
159+
/* oxlint-disable react/refs -- Native controlled edits must reconcile against the last acknowledged native event before sending the next payload. */
159160
const tokens = collectComposerInlineTokens(props.value, {
160161
preserveTrailingFrom: confirmedTokensRef.current,
161162
});
162163
confirmedTokensRef.current = tokens;
164+
/* oxlint-enable react/refs */
163165
return JSON.stringify(
164166
composerContextEditorTokens(props.value, tokens, skillLabels).map((token) => {
165167
const record =
@@ -197,6 +199,7 @@ export function ComposerEditor({
197199
// (value, selection) lags the acknowledged native state is stamped behind
198200
// the native revision and rejected by the editor instead of re-applying a
199201
// stale caret or stale text mid-typing.
202+
/* oxlint-disable react/refs -- Native controlled edits must reconcile against the last acknowledged native event before sending the next payload. */
200203
const controlledEventCount = resolveComposerControlledEventCount(
201204
props.value,
202205
selection ?? null,
@@ -209,6 +212,7 @@ export function ComposerEditor({
209212
mostRecentEventCount,
210213
nativeEventSnapshotsRef.current,
211214
);
215+
/* oxlint-enable react/refs */
212216
const isNativeEcho =
213217
controlledEventCount === mostRecentEventCount && acknowledgesLatestNativeEvent;
214218
const controlledDocumentJson = JSON.stringify({

0 commit comments

Comments
 (0)