@devries-cameron20 / t3code Mirror · read-only / commits / 006d7e38f0
Fork 0

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, 02:00 UTC

fix(mobile): stop the work-row shimmer from updating every frame (#28530)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 7, 2026 at 10:15 UTC 006d7e38f0485431c314a1afcc39fa823f379092
3 files changed +63 -25
apps/mobile/src/features/threads/thread-work-log.tsx
+12 -25
@@ -34,7 +34,6 @@ import {
34 import {
35 Animated as NativeAnimated,
36 type ColorValue,
37 - Easing,
37 Pressable,
38 ScrollView,
39 StyleSheet,
@@ -105,10 +104,9 @@ import Animated, {
104 import { useAssetUrl } from "../../state/assets";
105 import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
106 import { useOpenLinkedThread } from "./useOpenLinkedThread";
107 +import { startShimmerSteps } from "./work-shimmer-steps";
108
109 const SHIMMER_WIDTH = 72;
110 -const SHIMMER_SWEEP_MS = 1_350;
111 -const SHIMMER_PAUSE_MS = 1_450;
110 const SHIMMER_ICON_AND_GAP_WIDTH = 30;
111 export const THREAD_DISCLOSURE_TRANSITION_MS = 180;
112 const WORK_LOG_LAYOUT_TRANSITION = LinearTransition.duration(THREAD_DISCLOSURE_TRANSITION_MS);
@@ -269,44 +267,33 @@ export function ShimmeringWorkContent(props: {
267 const appIsActive = useAppActive();
268 const reducedMotion = useReduceMotionEnabled();
269 const screenIsFocused = useIsFocused();
272 - const progress = useAnimatedValue(0);
270 + // Native from creation, so each setValue updates the view without a React render.
271 + const progress = useAnimatedValue(0, { useNativeDriver: true });
272 const gradientId = `work-shimmer-${useId().replaceAll(":", "")}`;
273 const contentWidth = Math.min(
274 availableWidth,
275 (props.showIcon ? SHIMMER_ICON_AND_GAP_WIDTH : 0) + Math.ceil(textWidth),
276 );
277
279 - // Runs on React Native's native driver instead of Reanimated, whose
280 - // per-frame commits starve React's while commit pausing is disabled
281 - // (package.json). See docs/internals/performance-regressions.md.
282 - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- starts the native-driver shimmer loop while visible and active, and stops it on cleanup
278 + // Uses a native Animated value instead of Reanimated, whose per-frame commits
279 + // starve React's while commit pausing is disabled (package.json). See
280 + // docs/internals/performance-regressions.md.
281 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- steps the native shimmer value on timers while visible and active, and stops them on cleanup
282 useEffect(() => {
283 progress.setValue(0);
284 if (contentWidth <= 0 || reducedMotion || !appIsActive || !screenIsFocused) return;
286 -
287 - const loop = NativeAnimated.loop(
288 - NativeAnimated.timing(progress, {
289 - toValue: 1,
290 - duration: SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS,
291 - easing: Easing.linear,
292 - useNativeDriver: true,
293 - }),
294 - );
295 - loop.start();
296 - return () => loop.stop();
285 + return startShimmerSteps(progress);
286 }, [appIsActive, contentWidth, progress, reducedMotion, screenIsFocused]);
287
299 - // One timing covers the sweep and the pause, so the native driver can loop it.
288 // The React Compiler memoizes these, so re-renders don't rebuild the native
289 // animation nodes.
302 - const inputRange = [0, SHIMMER_SWEEP_MS / (SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS), 1];
290 const sweepTranslateX = progress.interpolate({
304 - inputRange,
305 - outputRange: [-SHIMMER_WIDTH, contentWidth, contentWidth],
291 + inputRange: [0, 1],
292 + outputRange: [-SHIMMER_WIDTH, contentWidth],
293 });
294 const counterSweepTranslateX = progress.interpolate({
308 - inputRange,
309 - outputRange: [SHIMMER_WIDTH, -contentWidth, -contentWidth],
295 + inputRange: [0, 1],
296 + outputRange: [SHIMMER_WIDTH, -contentWidth],
297 });
298
299 return (
apps/mobile/src/features/threads/work-shimmer-steps.test.ts new
+30
@@ -0,0 +1,30 @@
1 +import { expect, it, vi } from "vite-plus/test";
2 +
3 +import {
4 + SHIMMER_PAUSE_MS,
5 + SHIMMER_STEPS,
6 + SHIMMER_SWEEP_MS,
7 + startShimmerSteps,
8 +} from "./work-shimmer-steps";
9 +
10 +it("steps the sweep, stays quiet through the pause, and stops on cleanup", () => {
11 + using _timers = { [Symbol.dispose]: () => vi.useRealTimers() };
12 + vi.useFakeTimers();
13 + const values: number[] = [];
14 + const stop = startShimmerSteps({ setValue: (value) => values.push(value) });
15 + const valuesDuring = (ms: number) => {
16 + vi.advanceTimersByTime(ms);
17 + return values.splice(0);
18 + };
19 +
20 + const sweep = valuesDuring(SHIMMER_SWEEP_MS);
21 + expect(sweep).toHaveLength(SHIMMER_STEPS);
22 + expect(sweep.at(-1)).toBe(1);
23 + expect(sweep).toEqual(Array.from({ length: SHIMMER_STEPS }, (_, i) => (i + 1) / SHIMMER_STEPS));
24 + expect(valuesDuring(SHIMMER_PAUSE_MS)).toEqual([]);
25 + expect(valuesDuring(SHIMMER_SWEEP_MS)).toEqual(sweep);
26 +
27 + stop();
28 + expect(vi.getTimerCount()).toBe(0);
29 + expect(valuesDuring((SHIMMER_SWEEP_MS + SHIMMER_PAUSE_MS) * 2)).toEqual([]);
30 +});
apps/mobile/src/features/threads/work-shimmer-steps.ts new
+21
@@ -0,0 +1,21 @@
1 +export const SHIMMER_SWEEP_MS = 1_350;
2 +export const SHIMMER_PAUSE_MS = 1_450;
3 +export const SHIMMER_STEPS = 12;
4 +const SHIMMER_STEP_MS = SHIMMER_SWEEP_MS / SHIMMER_STEPS;
5 +
6 +// No progress updates run during the pause. Progress 0 and 1 both sit off the
7 +// content, so the cycle only needs steps 1 through SHIMMER_STEPS.
8 +export function startShimmerSteps(progress: { setValue(value: number): void }): () => void {
9 + let step = 0;
10 + let timer: ReturnType<typeof setTimeout>;
11 + const advance = () => {
12 + step = (step % SHIMMER_STEPS) + 1;
13 + progress.setValue(step / SHIMMER_STEPS);
14 + timer = setTimeout(
15 + advance,
16 + step === SHIMMER_STEPS ? SHIMMER_PAUSE_MS + SHIMMER_STEP_MS : SHIMMER_STEP_MS,
17 + );
18 + };
19 + timer = setTimeout(advance, SHIMMER_STEP_MS);
20 + return () => clearTimeout(timer);
21 +}