From 610192ed9b326c96da5416af7fe9e3e2e2c70091 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 29 Jun 2026 06:40:21 -0700 Subject: [PATCH] Clean up `enableEagerAlternateStateNodeCleanup` (#57358) Summary: Pull Request resolved: https://github.com/react/react-native/pull/57358 The `enableEagerAlternateStateNodeCleanup` flag is no longer read by the renderer, so the feature-flag definition and the two prelude overrides that forced it on become dead code. [Internal] Reviewed By: lenaic Differential Revision: D110043719 fbshipit-source-id: 24a7e2b85ec60da1cb1855f444bba5e1e6fc4288 --- ...bleEagerAlternateStateNodeCleanup-itest.js | 47 ------------------- .../__tests__/VirtualView-itest.js | 23 +++++++++ .../mocks/ReactNativeInternalFeatureFlags.js | 6 --- 3 files changed, 23 insertions(+), 53 deletions(-) delete mode 100644 packages/react-native/src/private/components/virtualview/__tests__/VirtualView-enableEagerAlternateStateNodeCleanup-itest.js diff --git a/packages/react-native/src/private/components/virtualview/__tests__/VirtualView-enableEagerAlternateStateNodeCleanup-itest.js b/packages/react-native/src/private/components/virtualview/__tests__/VirtualView-enableEagerAlternateStateNodeCleanup-itest.js deleted file mode 100644 index 06a87fadbf2..00000000000 --- a/packages/react-native/src/private/components/virtualview/__tests__/VirtualView-enableEagerAlternateStateNodeCleanup-itest.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow strict-local - * @format - */ - -import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment'; - -import {createShadowNodeReferenceCountingRef} from '../../../__tests__/utilities/ShadowNodeReferenceCounter'; -import VirtualView, {_logs, VirtualViewMode} from '../VirtualView'; -import {dispatchModeChangeEvent} from './VirtualView-itest'; -import * as Fantom from '@react-native/fantom'; -import * as React from 'react'; -import {createRef} from 'react'; -import {Text} from 'react-native'; - -beforeEach(() => { - _logs.states = []; -}); - -describe('VirtualView with enableEagerAlternateStateNodeCleanup flag', () => { - test('does not retain shadow node after becoming hidden', () => { - const root = Fantom.createRoot(); - - const [getReferenceCount, childRef] = - createShadowNodeReferenceCountingRef(); - const viewRef = createRef>(); - - Fantom.runTask(() => { - root.render( - - Child - , - ); - }); - - expect(getReferenceCount()).toBeGreaterThan(0); - - dispatchModeChangeEvent(viewRef.current, VirtualViewMode.Hidden); - - expect(getReferenceCount()).toBe(0); - }); -}); diff --git a/packages/react-native/src/private/components/virtualview/__tests__/VirtualView-itest.js b/packages/react-native/src/private/components/virtualview/__tests__/VirtualView-itest.js index bcc17b87f05..06436e9e417 100644 --- a/packages/react-native/src/private/components/virtualview/__tests__/VirtualView-itest.js +++ b/packages/react-native/src/private/components/virtualview/__tests__/VirtualView-itest.js @@ -15,6 +15,7 @@ import type {NativeModeChangeEvent} from '../VirtualViewNativeComponent'; import ensureInstance from '../../../__tests__/utilities/ensureInstance'; import isUnreachable from '../../../__tests__/utilities/isUnreachable'; +import {createShadowNodeReferenceCountingRef} from '../../../__tests__/utilities/ShadowNodeReferenceCounter'; import {getNodeFromPublicInstance} from '../../../../../Libraries/ReactPrivate/ReactNativePrivateInterface'; import ReactNativeElement from '../../../webapis/dom/nodes/ReactNativeElement'; import VirtualView, {_logs, VirtualViewMode} from '../VirtualView'; @@ -291,6 +292,28 @@ describe('memory management', () => { expect(isUnreachable(nullthrows(weakRef))).toBe(true); }); + + test('does not retain shadow node after becoming hidden', () => { + const root = Fantom.createRoot(); + + const [getReferenceCount, childRef] = + createShadowNodeReferenceCountingRef(); + const viewRef = createRef>(); + + Fantom.runTask(() => { + root.render( + + Child + , + ); + }); + + expect(getReferenceCount()).toBeGreaterThan(0); + + dispatchModeChangeEvent(viewRef.current, VirtualViewMode.Hidden); + + expect(getReferenceCount()).toBe(0); + }); }); /** diff --git a/private/react-native-fantom/runtime/mocks/ReactNativeInternalFeatureFlags.js b/private/react-native-fantom/runtime/mocks/ReactNativeInternalFeatureFlags.js index 133a0bee1ba..140add8e868 100644 --- a/private/react-native-fantom/runtime/mocks/ReactNativeInternalFeatureFlags.js +++ b/private/react-native-fantom/runtime/mocks/ReactNativeInternalFeatureFlags.js @@ -9,12 +9,6 @@ */ module.exports = { - // When enableEagerAlternateStateNodeCleanup is enabled, alternate.stateNode is proactively - // pointed towards finishedWork's stateNode, releasing resources sooner. - // With enableEagerAlternateStateNodeCleanup enabled, we can remove workarounds in tests - // and have predictable memory model. - // See https://github.com/facebook/react/pull/33161 for details. - enableEagerAlternateStateNodeCleanup: true, enableFragmentRefs: true, enableFragmentRefsInstanceHandles: true, enableFragmentRefsTextNodes: true,