Skip to content

Commit a07a883

Browse files
committed
Address Stale lastSeenValueRef causes visual regression on re-entry
When the targetValue changes while the element is out of viewport, the else-if branch (lines 96-100) correctly snaps the display to the new target but fails to clear lastSeenValueRef. This ref retains a stale mid-animation value from when the element exited viewport. When the element later re-enters viewport, the condition at line 88 evaluates true (stale value differs from new target), causing the animation to start from the old saved value instead of the current displayed value. This produces a visible backward jump in the counter before it animates forward.
1 parent fb7554b commit a07a883

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

special-pages/pages/new-tab/app/protections/utils/useAnimatedCount.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ export function useAnimatedCount(targetValue, elementRef) {
148148
// This handles the case where value changes while element is out of viewport
149149
setAnimatedValue(targetValue);
150150
animatedValueRef.current = targetValue;
151+
// Clear lastSeenValueRef since we've updated to the new target
152+
// This prevents stale values from causing backward jumps on re-entry
153+
lastSeenValueRef.current = null;
151154
}
152155
// else: conditions not met and haven't animated yet, do nothing (wait for viewport entry)
153156

@@ -164,6 +167,8 @@ export function useAnimatedCount(targetValue, elementRef) {
164167
if (hasAnimatedRef.current) {
165168
setAnimatedValue(targetValue);
166169
animatedValueRef.current = targetValue;
170+
// Clear lastSeenValueRef since we've updated to the current target
171+
lastSeenValueRef.current = null;
167172
}
168173
}
169174
};

0 commit comments

Comments
 (0)