TypeScript
chore(lint): enforce react/immutability (#25115)
Julius Marminge908226fc88e8
diff --git a/apps/mobile/src/features/layout/workspace-inspector-pane.tsx b/apps/mobile/src/features/layout/workspace-inspector-pane.tsxindex 9a44aadc052..fea0b3964f9 100644--- a/apps/mobile/src/features/layout/workspace-inspector-pane.tsx+++ b/apps/mobile/src/features/layout/workspace-inspector-pane.tsx@@ -36,14 +36,12 @@ export function WorkspaceInspectorPane(props: {const onClosed = props.onClosed;useEffect(() => {- inspectorProgress.value = withTiming(- inspectorVisible ? 1 : 0,- WORKSPACE_PANE_TIMING,- (finished) => {+ inspectorProgress.set(+ withTiming(inspectorVisible ? 1 : 0, WORKSPACE_PANE_TIMING, (finished) => {if (finished === true && !inspectorVisible && onClosed !== undefined) {runOnJS(onClosed)();}- },+ }),);const targetWidth = inspectorVisible ? (inspectorWidth ?? 0) : 0;renderedInspectorWidth.set(@@ -61,10 +59,10 @@ export function WorkspaceInspectorPane(props: {useEffect(() => {const targetWidth = inspectorWidth ?? 0;if (!inspectorVisible || resizing) {- renderedContentWidth.value = targetWidth;+ renderedContentWidth.set(targetWidth);return;}- renderedContentWidth.value = withTiming(targetWidth, WORKSPACE_PANE_TIMING);+ renderedContentWidth.set(withTiming(targetWidth, WORKSPACE_PANE_TIMING));}, [inspectorVisible, inspectorWidth, renderedContentWidth, resizing]);const inspectorStyle = useAnimatedStyle(diff --git a/apps/mobile/src/features/threads/PendingUserInputCard.tsx b/apps/mobile/src/features/threads/PendingUserInputCard.tsxindex af6663538f8..89edbd7a44a 100644--- a/apps/mobile/src/features/threads/PendingUserInputCard.tsx+++ b/apps/mobile/src/features/threads/PendingUserInputCard.tsx@@ -87,7 +87,7 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {}// The card resizes with the keyboard every frame, so easing each sample would leave the// feed inset and floating controls trailing it.- cardCoverage.value = Math.max(0, cardHeightRef.current - barHeightRef.current);+ cardCoverage.set(Math.max(0, cardHeightRef.current - barHeightRef.current));}, [cardCoverage]);const handleBarLayout = useCallback((event: LayoutChangeEvent) => {@@ -99,7 +99,7 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {const handleCardLayout = useCallback((event: LayoutChangeEvent) => {cardHeightRef.current = event.nativeEvent.layout.height;- cardHeight.value = event.nativeEvent.layout.height;+ cardHeight.set(event.nativeEvent.layout.height);notifyCoverage();},[cardHeight, notifyCoverage],diff --git a/apps/mobile/src/features/threads/ThreadComposer.tsx b/apps/mobile/src/features/threads/ThreadComposer.tsxindex 2f913144332..9687136761f 100644--- a/apps/mobile/src/features/threads/ThreadComposer.tsx+++ b/apps/mobile/src/features/threads/ThreadComposer.tsx@@ -385,12 +385,14 @@ export function ComposerSurface(props: {const animatedBorderRadius = useSharedValue(targetBorderRadius);const shouldAnimate = props.animateLayout !== false && Platform.OS !== "android";useLayoutEffect(() => {- animatedBorderRadius.value = shouldAnimate- ? withTiming(targetBorderRadius, {- duration: COMPOSER_TRANSITION_DURATION_MS,- reduceMotion: ReduceMotion.System,- })- : targetBorderRadius;+ animatedBorderRadius.set(+ shouldAnimate+ ? withTiming(targetBorderRadius, {+ duration: COMPOSER_TRANSITION_DURATION_MS,+ reduceMotion: ReduceMotion.System,+ })+ : targetBorderRadius,+ );}, [animatedBorderRadius, shouldAnimate, targetBorderRadius]);const borderCurve = props.style.borderCurve;const animatedShapeStyle = useAnimatedStyle(() => ({diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsxindex f2bd35ffbf1..b455c8f5ef5 100644--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx@@ -968,9 +968,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetaishowFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0,);useEffect(() => {- floatingControlCoverage.value = withTiming(- showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0,- { duration: 180, reduceMotion: ReduceMotion.System },+ floatingControlCoverage.set(+ withTiming(showFloatingStatus ? FLOATING_WORKING_CONTROL_COVERAGE : 0, {+ duration: 180,+ reduceMotion: ReduceMotion.System,+ }),);}, [floatingControlCoverage, showFloatingStatus]);// Android measures its expanded card in-flow; only iOS needs extra overlay coverage.@@ -984,7 +986,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetaifloatingControlCoverage.value +(userInputCoverageApplies ? userInputInsetProgress.value * userInputCardCoverage.value : 0),(value) => {- combinedContentInsetEndAdjustment.value = value;+ combinedContentInsetEndAdjustment.set(value);},[userInputCoverageApplies],);diff --git a/apps/mobile/src/features/threads/floating-working-control.tsx b/apps/mobile/src/features/threads/floating-working-control.tsxindex 22428209c83..24322aa46d4 100644--- a/apps/mobile/src/features/threads/floating-working-control.tsx+++ b/apps/mobile/src/features/threads/floating-working-control.tsx@@ -105,7 +105,7 @@ export function FloatingWorkingControl(props: {const separationProgress = useSharedValue(props.showScrollToEnd ? 1 : 0);useEffect(() => {- separationProgress.value = withTiming(props.showScrollToEnd ? 1 : 0, CONTROL_TIMING);+ separationProgress.set(withTiming(props.showScrollToEnd ? 1 : 0, CONTROL_TIMING));}, [props.showScrollToEnd, separationProgress]);const lift = props.lift;@@ -129,14 +129,14 @@ export function FloatingWorkingControl(props: {}const first = measuredWidthRef.current === null;measuredWidthRef.current = width;- capsuleWidth.value = first ? width : withTiming(width, CONTROL_TIMING);+ capsuleWidth.set(first ? width : withTiming(width, CONTROL_TIMING));};const hasStatus = props.status !== null;const hasCapsule = hasStatus || hasQueue || hasAgents || hasPreview;useEffect(() => {if (!hasStatus) {measuredWidthRef.current = null;- capsuleWidth.value = null;+ capsuleWidth.set(null);}}, [capsuleWidth, hasStatus]);const capsuleStyle = useAnimatedStyle(() => ({diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsxindex 259cdb399d1..0ea7616f31d 100644--- a/apps/mobile/src/features/threads/thread-work-log.tsx+++ b/apps/mobile/src/features/threads/thread-work-log.tsx@@ -171,10 +171,12 @@ export function ThreadDisclosureChevron(props: {const rotation = useSharedValue(props.expanded ? expandedAngle : 0);useLayoutEffect(() => {- rotation.value = withTiming(props.expanded ? expandedAngle : 0, {- duration: THREAD_DISCLOSURE_TRANSITION_MS,- reduceMotion: ReduceMotion.System,- });+ rotation.set(+ withTiming(props.expanded ? expandedAngle : 0, {+ duration: THREAD_DISCLOSURE_TRANSITION_MS,+ reduceMotion: ReduceMotion.System,+ }),+ );}, [expandedAngle, props.expanded, rotation]);const rotationStyle = useAnimatedStyle(() => ({diff --git a/apps/mobile/src/features/voice-input/ComposerDictationControl.tsx b/apps/mobile/src/features/voice-input/ComposerDictationControl.tsxindex b1b0d2b69ac..cd7976232e6 100644--- a/apps/mobile/src/features/voice-input/ComposerDictationControl.tsx+++ b/apps/mobile/src/features/voice-input/ComposerDictationControl.tsx@@ -90,7 +90,7 @@ export function ComposerDictationDraftContent(props: {}) {const rotation = useSharedValue(props.hidden ? 1 : 0);useLayoutEffect(() => {- rotation.value = withTiming(props.hidden ? 1 : 0, TOOLBAR_FLIP_TIMING);+ rotation.set(withTiming(props.hidden ? 1 : 0, TOOLBAR_FLIP_TIMING));}, [props.hidden, rotation]);const compact = props.compact;const animatedStyle = useAnimatedStyle(() => ({@@ -263,7 +263,7 @@ function VoiceActionButton(props: {const variant = props.variant ?? "plain";const loadingVisibility = useSharedValue(props.loading ? 1 : 0);useLayoutEffect(() => {- loadingVisibility.value = withTiming(props.loading ? 1 : 0, DICTATION_TIMING);+ loadingVisibility.set(withTiming(props.loading ? 1 : 0, DICTATION_TIMING));}, [loadingVisibility, props.loading]);const primaryStyle = useAnimatedStyle(() => ({ opacity: 1 - loadingVisibility.value }));@@ -322,7 +322,7 @@ export function ComposerDictationStatus(props: {}) {const recordingVisibility = useSharedValue(props.phase === "recording" ? 1 : 0);useLayoutEffect(() => {- recordingVisibility.value = withTiming(props.phase === "recording" ? 1 : 0, DICTATION_TIMING);+ recordingVisibility.set(withTiming(props.phase === "recording" ? 1 : 0, DICTATION_TIMING));}, [props.phase, recordingVisibility]);const waveformStyle = useAnimatedStyle(() => ({opacity: recordingVisibility.value,diff --git a/apps/mobile/src/features/voice-input/GlobalVoiceInputControl.tsx b/apps/mobile/src/features/voice-input/GlobalVoiceInputControl.tsxindex 9b212a86732..a9d9544c663 100644--- a/apps/mobile/src/features/voice-input/GlobalVoiceInputControl.tsx+++ b/apps/mobile/src/features/voice-input/GlobalVoiceInputControl.tsx@@ -65,7 +65,7 @@ function EdgeDictationPill(props: { readonly collapseRef: RefObject<(() => void)const [expanded, setExpanded] = useState(false);const progress = useSharedValue(0);useEffect(() => {- progress.value = withTiming(expanded ? 1 : 0, MORPH_TIMING);+ progress.set(withTiming(expanded ? 1 : 0, MORPH_TIMING));}, [expanded, progress]);const { collapseRef } = props;useEffect(() => {diff --git a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsxindex fe768932978..039f0545722 100644--- a/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx+++ b/apps/mobile/src/features/voice-input/VoiceInputProvider.tsx@@ -195,7 +195,7 @@ function useVoiceInputRuntime() {if (audioLevelsRef.current.some((level) => level !== 0)) {audioLevelsRef.current = Array<number>(VOICE_WAVEFORM_SAMPLE_COUNT).fill(0);- audioLevels.value = audioLevelsRef.current;+ audioLevels.set(audioLevelsRef.current);}if (elapsedSecondsRef.current !== 0) {elapsedSecondsRef.current = 0;@@ -213,7 +213,7 @@ function useVoiceInputRuntime() {if (level !== 0 || history.some((sample) => sample !== 0)) {const nextLevels = [...history.slice(1), level];audioLevelsRef.current = nextLevels;- audioLevels.value = nextLevels;+ audioLevels.set(nextLevels);}const nextElapsedSeconds = Math.min(diff --git a/apps/mobile/src/reactCompilerCoverage.test.ts b/apps/mobile/src/reactCompilerCoverage.test.tsindex e5f86349d0c..7eb3b3c915a 100644--- a/apps/mobile/src/reactCompilerCoverage.test.ts+++ b/apps/mobile/src/reactCompilerCoverage.test.ts@@ -19,7 +19,6 @@ const KNOWN_BAILOUTS: Record<string, string> = {"src/components/ui/Menu.tsx": "ref read during render","src/features/diffs/nativeReviewDiffSurface.ts": "ref read during render","src/features/home/thread-swipe-actions.tsx": "ref read during render",- "src/features/threads/PendingUserInputCard.tsx": "mutates a frozen value","src/features/threads/ThreadArrangementSheet.tsx": "ref read during render","src/features/voice-input/VoiceInputProvider.tsx": "ref read during render","src/features/voice-input/useVoiceInputController.ts": "ref read during render",diff --git a/vite.config.ts b/vite.config.tsindex 2a48daa13ac..beb3d8af9da 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -216,6 +216,7 @@ export default defineConfig({perf: "warn",},rules: {+ "react/immutability": "error","react/no-array-index-key": "error","react/no-unstable-nested-components": "error","react/static-components": "error",