RN: Cleanup scheduleAnimatedCleanupInMicrotask Flag (#52685)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52685

Cleans up the `scheduleAnimatedCleanupInMicrotask ` feature flag and deletes code paths that are now unreachable.

Changelog:
[Internal]

Reviewed By: mdvacca

Differential Revision: D78498600

fbshipit-source-id: 307562030373742e64968ae4c92d6bfbb48ddc71
This commit is contained in:
Tim Yung authored and Facebook GitHub Bot committed 2025-07-17 12:59:13 -07:00
1 parent 5c7fdb252e
commit 5d4d1ce84b
4 files changed
+2 -120

No files matched your search

@@ -31,12 +31,8 @@ function mockQueueMicrotask() {
}
describe('Animated', () => {
let ReactNativeFeatureFlags;
beforeEach(() => {
jest.resetModules();
ReactNativeFeatureFlags = require('../../../src/private/featureflags/ReactNativeFeatureFlags');
});
mockQueueMicrotask();
@@ -113,50 +109,7 @@ describe('Animated', () => {
expect(callback.mock.calls.length).toBe(1);
});
it('does not detach on updates', async () => {
ReactNativeFeatureFlags.override({
scheduleAnimatedCleanupInMicrotask: () => false,
});
const opacity = new Animated.Value(0);
jest.spyOn(opacity, '__detach');
const root = await create(<Animated.View style={{opacity}} />);
expect(opacity.__detach).not.toBeCalled();
await update(root, <Animated.View style={{opacity}} />);
expect(opacity.__detach).not.toBeCalled();
await unmount(root);
expect(opacity.__detach).toBeCalled();
});
it('stops animation when detached', async () => {
ReactNativeFeatureFlags.override({
scheduleAnimatedCleanupInMicrotask: () => false,
});
const opacity = new Animated.Value(0);
const callback = jest.fn();
const root = await create(<Animated.View style={{opacity}} />);
Animated.timing(opacity, {
toValue: 10,
duration: 1000,
useNativeDriver: false,
}).start(callback);
await unmount(root);
expect(callback).toBeCalledWith({finished: false});
});
it('detaches only on unmount (in a microtask)', async () => {
ReactNativeFeatureFlags.override({
scheduleAnimatedCleanupInMicrotask: () => true,
});
const opacity = new Animated.Value(0);
jest.spyOn(opacity, '__detach');
@@ -175,10 +128,6 @@ describe('Animated', () => {
});
it('restores default values only on update (in a microtask)', async () => {
ReactNativeFeatureFlags.override({
scheduleAnimatedCleanupInMicrotask: () => true,
});
const __restoreDefaultValues = jest.spyOn(
AnimatedProps.prototype,
'__restoreDefaultValues',
@@ -213,10 +162,6 @@ describe('Animated', () => {
});
it('stops animation when detached (in a microtask)', async () => {
ReactNativeFeatureFlags.override({
scheduleAnimatedCleanupInMicrotask: () => true,
});
const opacity = new Animated.Value(0);
const callback = jest.fn();
@@ -783,16 +783,6 @@ const definitions: FeatureFlagDefinitions = {
},
ossReleaseStage: 'none',
},
scheduleAnimatedCleanupInMicrotask: {
defaultValue: true,
metadata: {
description:
'Changes the cleanup of `AnimatedProps` to occur in a microtask instead of synchronously during effect cleanup (for unmount) or subsequent mounts (for updates).',
expectedReleaseValue: true,
purpose: 'release',
},
ossReleaseStage: 'none',
},
shouldUseAnimatedObjectForTransform: {
defaultValue: false,
metadata: {
@@ -89,13 +89,6 @@ export default function createAnimatedPropsHook(
};
});
// NOTE: This feature flag must be evaluated inside the hook because this
// module factory can be evaluated much sooner, before overrides are set.
const useAnimatedPropsLifecycle =
ReactNativeFeatureFlags.scheduleAnimatedCleanupInMicrotask()
? useAnimatedPropsLifecycleWithCleanupInMicrotask
: useAnimatedPropsLifecycleWithPrevNodeRef;
useAnimatedPropsLifecycle(node);
// TODO: This "effect" does three things:
@@ -262,44 +255,6 @@ function addAnimatedValuesListenersToProps(
}
}
/**
* Manages the lifecycle of the supplied `AnimatedProps` by invoking `__attach`
* and `__detach`. However, this is more complicated because `AnimatedProps`
* uses reference counting to determine when to recursively detach its children
* nodes. So in order to optimize this, we avoid detaching until the next attach
* unless we are unmounting.
*/
function useAnimatedPropsLifecycleWithPrevNodeRef(node: AnimatedProps): void {
const prevNodeRef = useRef<?AnimatedProps>(null);
const isUnmountingRef = useRef<boolean>(false);
useInsertionEffect(() => {
isUnmountingRef.current = false;
return () => {
isUnmountingRef.current = true;
};
}, []);
useInsertionEffect(() => {
node.__attach();
if (prevNodeRef.current != null) {
const prevNode = prevNodeRef.current;
// TODO: Stop restoring default values (unless `reset` is called).
prevNode.__restoreDefaultValues();
prevNode.__detach();
prevNodeRef.current = null;
}
return () => {
if (isUnmountingRef.current) {
// NOTE: Do not restore default values on unmount, see D18197735.
node.__detach();
} else {
prevNodeRef.current = node;
}
};
}, [node]);
}
/**
* Manages the lifecycle of the supplied `AnimatedProps` by invoking `__attach`
* and `__detach`. However, `__detach` occurs in a microtask for these reasons:
@@ -314,9 +269,7 @@ function useAnimatedPropsLifecycleWithPrevNodeRef(node: AnimatedProps): void {
* callbacks may update state, which is unsupported and will force synchronous
* updates.
*/
function useAnimatedPropsLifecycleWithCleanupInMicrotask(
node: AnimatedProps,
): void {
function useAnimatedPropsLifecycle(node: AnimatedProps): void {
const isMounted = useRef<boolean>(false);
useInsertionEffect(() => {
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<99d6ed3c0a9bfd543d58de5b2fdfffdf>>
* @generated SignedSource<<fd428af720f8a8cf58e5beb582078825>>
* @flow strict
* @noformat
*/
@@ -36,7 +36,6 @@ export type ReactNativeFeatureFlagsJsOnly = $ReadOnly<{
fixVirtualizeListCollapseWindowSize: Getter<boolean>,
isLayoutAnimationEnabled: Getter<boolean>,
reduceDefaultPropsInView: Getter<boolean>,
scheduleAnimatedCleanupInMicrotask: Getter<boolean>,
shouldUseAnimatedObjectForTransform: Getter<boolean>,
shouldUseRemoveClippedSubviewsAsDefaultOnIOS: Getter<boolean>,
shouldUseSetNativePropsInFabric: Getter<boolean>,
@@ -152,11 +151,6 @@ export const isLayoutAnimationEnabled: Getter<boolean> = createJavaScriptFlagGet
*/
export const reduceDefaultPropsInView: Getter<boolean> = createJavaScriptFlagGetter('reduceDefaultPropsInView', true);
/**
* Changes the cleanup of `AnimatedProps` to occur in a microtask instead of synchronously during effect cleanup (for unmount) or subsequent mounts (for updates).
*/
export const scheduleAnimatedCleanupInMicrotask: Getter<boolean> = createJavaScriptFlagGetter('scheduleAnimatedCleanupInMicrotask', true);
/**
* Enables use of AnimatedObject for animating transform values.
*/