Skip to content

Commit

Permalink
turn on by default optimization for memoization of virtualized list c…
Browse files Browse the repository at this point in the history
…ells (#47724)

Summary:
Changelog: [General] [Changed] - Fix unnececary rerenders of VirtualizedListCells with strictMode={true}

Pull Request resolved: #47724

Reviewed By: sammy-SC

Differential Revision: D66123469

fbshipit-source-id: 295e10add51bc1c319b8b8e3a9f4874c5e5a386d
  • Loading branch information
Tom910 authored and facebook-github-bot committed Nov 21, 2024
1 parent 6e06a81 commit aafe696
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,6 @@ const definitions: FeatureFlagDefinitions = {
purpose: 'release',
},
},
enableOptimisedVirtualizedCells: {
defaultValue: false,
metadata: {
dateAdded: '2024-08-21',
description:
'Removing unnecessary rerenders Virtualized cells after any rerenders of Virualized list. Works with strict=true option',
purpose: 'experimentation',
},
},
isLayoutAnimationEnabled: {
defaultValue: true,
metadata: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<36e8036fd1f45794c37a6fa22cde9b05>>
* @generated SignedSource<<83b5798ee1c7a28fffbf110e19641d69>>
* @flow strict
*/

Expand Down Expand Up @@ -36,7 +36,6 @@ export type ReactNativeFeatureFlagsJsOnly = {
enableAnimatedAllowlist: Getter<boolean>,
enableAnimatedClearImmediateFix: Getter<boolean>,
enableAnimatedPropsMemo: Getter<boolean>,
enableOptimisedVirtualizedCells: Getter<boolean>,
isLayoutAnimationEnabled: Getter<boolean>,
shouldSkipStateUpdatesForLoopingAnimations: Getter<boolean>,
shouldUseAnimatedObjectForTransform: Getter<boolean>,
Expand Down Expand Up @@ -143,11 +142,6 @@ export const enableAnimatedClearImmediateFix: Getter<boolean> = createJavaScript
*/
export const enableAnimatedPropsMemo: Getter<boolean> = createJavaScriptFlagGetter('enableAnimatedPropsMemo', true);

/**
* Removing unnecessary rerenders Virtualized cells after any rerenders of Virualized list. Works with strict=true option
*/
export const enableOptimisedVirtualizedCells: Getter<boolean> = createJavaScriptFlagGetter('enableOptimisedVirtualizedCells', false);

/**
* Function used to enable / disabled Layout Animations in React Native.
*/
Expand Down
14 changes: 2 additions & 12 deletions packages/virtualized-lists/Lists/VirtualizedListCellRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {VirtualizedListCellContextProvider} from './VirtualizedListContext.js';
import invariant from 'invariant';
import * as React from 'react';
import {StyleSheet, View} from 'react-native';
import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags';

export type Props<ItemT> = {
CellRendererComponent?: ?React.ComponentType<CellRendererProps<ItemT>>,
Expand Down Expand Up @@ -69,24 +68,15 @@ export default class CellRenderer<ItemT> extends React.PureComponent<
props: Props<ItemT>,
prevState: State<ItemT>,
): ?State<ItemT> {
if (ReactNativeFeatureFlags.enableOptimisedVirtualizedCells()) {
if (props.item !== prevState.separatorProps.leadingItem) {
return {
separatorProps: {
...prevState.separatorProps,
leadingItem: props.item,
},
};
}
return null;
} else {
if (props.item !== prevState.separatorProps.leadingItem) {
return {
separatorProps: {
...prevState.separatorProps,
leadingItem: props.item,
},
};
}
return null;
}

// TODO: consider factoring separator stuff out of VirtualizedList into FlatList since it's not
Expand Down

0 comments on commit aafe696

Please sign in to comment.