Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enableShallowPropDiffing feature flag #29664

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import {
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
import isArray from 'shared/isArray';

import {enableAddPropertiesFastPath} from 'shared/ReactFeatureFlags';
import {
enableAddPropertiesFastPath,
enableShallowPropDiffing,
} from 'shared/ReactFeatureFlags';

import type {AttributeConfiguration} from './ReactNativeTypes';

Expand Down Expand Up @@ -342,7 +345,7 @@ function diffProperties(
// Pattern match on: attributeConfig
if (typeof attributeConfig !== 'object') {
// case: !Object is the default case
if (defaultDiffer(prevProp, nextProp)) {
if (enableShallowPropDiffing || defaultDiffer(prevProp, nextProp)) {
// a normal leaf has changed
(updatePayload || (updatePayload = ({}: {[string]: $FlowFixMe})))[
propKey
Expand All @@ -354,6 +357,7 @@ function diffProperties(
) {
// case: CustomAttributeConfiguration
const shouldUpdate =
enableShallowPropDiffing ||
prevProp === undefined ||
(typeof attributeConfig.diff === 'function'
? attributeConfig.diff(prevProp, nextProp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

const {diff, create} = require('../ReactNativeAttributePayloadFabric');

describe('ReactNativeAttributePayload.create', () => {
describe('ReactNativeAttributePayloadFabric.create', () => {
it('should work with simple example', () => {
expect(create({b: 2, c: 3}, {a: true, b: true})).toEqual({
b: 2,
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('ReactNativeAttributePayload.create', () => {
});
});

describe('ReactNativeAttributePayload.diff', () => {
describe('ReactNativeAttributePayloadFabric.diff', () => {
it('should work with simple example', () => {
expect(diff({a: 1, c: 3}, {b: 2, c: 3}, {a: true, b: true})).toEqual({
a: null,
Expand Down Expand Up @@ -201,6 +201,7 @@ describe('ReactNativeAttributePayload.diff', () => {
expect(diff({a: 1}, {b: 2}, {})).toEqual(null);
});

// @gate !enableShallowPropDiffing
it('should use the diff attribute', () => {
const diffA = jest.fn((a, b) => true);
const diffB = jest.fn((a, b) => false);
Expand All @@ -225,6 +226,7 @@ describe('ReactNativeAttributePayload.diff', () => {
expect(diffB).not.toBeCalled();
});

// @gate !enableShallowPropDiffing
it('should do deep diffs of Objects by default', () => {
expect(
diff(
Expand Down Expand Up @@ -422,6 +424,7 @@ describe('ReactNativeAttributePayload.diff', () => {
).toEqual(null);
});

// @gate !enableShallowPropDiffing
it('should skip deeply-nested changed functions', () => {
expect(
diff(
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export const enableAddPropertiesFastPath = false;

export const enableOwnerStacks = __EXPERIMENTAL__;

export const enableShallowPropDiffing = false;

/**
* Enables an expiration time for retry lanes to avoid starvation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export const enableAddPropertiesFastPath = __VARIANT__;
export const enableDeferRootSchedulingToMicrotask = __VARIANT__;
export const enableFastJSX = __VARIANT__;
export const enableInfiniteRenderLoopDetection = __VARIANT__;
export const enableShallowPropDiffing = __VARIANT__;
export const passChildrenWhenCloningPersistedNodes = __VARIANT__;
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const {
enableDeferRootSchedulingToMicrotask,
enableFastJSX,
enableInfiniteRenderLoopDetection,
enableShallowPropDiffing,
passChildrenWhenCloningPersistedNodes,
} = dynamicFlags;

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
export const passChildrenWhenCloningPersistedNodes = false;
export const enableAsyncIterableChildren = false;
export const enableAddPropertiesFastPath = false;

export const enableShallowPropDiffing = false;
export const renameElementSymbol = true;

export const enableOwnerStacks = __EXPERIMENTAL__;
Expand Down
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const enableInfiniteRenderLoopDetection = false;
export const enableAddPropertiesFastPath = false;

export const renameElementSymbol = true;
export const enableShallowPropDiffing = false;

// TODO: This must be in sync with the main ReactFeatureFlags file because
// the Test Renderer's value must be the same as the one used by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const enableAddPropertiesFastPath = false;
export const renameElementSymbol = false;

export const enableOwnerStacks = false;
export const enableShallowPropDiffing = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const enableAddPropertiesFastPath = false;
export const renameElementSymbol = false;

export const enableOwnerStacks = false;
export const enableShallowPropDiffing = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);
1 change: 1 addition & 0 deletions packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const disableStringRefs = false;
export const disableLegacyMode = __EXPERIMENTAL__;

export const enableOwnerStacks = false;
export const enableShallowPropDiffing = false;

// Flow magic to verify the exports of this file match the original version.
((((null: any): ExportsType): FeatureFlagsType): ExportsType);