Skip to content

Commit d39d5d8

Browse files
sammy-SCmeta-codesync[bot]
authored andcommitted
Remove enableOptimizedBoxShadowParsing feature flag (facebook#56098)
Summary: Pull Request resolved: facebook#56098 changelog: [internal] Delete the `enableOptimizedBoxShadowParsing` flag and enable the optimized box shadow parsing by default. The optimization hoists regex patterns to module scope in `processBoxShadow.js`. Impact in production was small since this is a minor perf improvement to regex compilation. Reviewed By: javache Differential Revision: D96594041 fbshipit-source-id: 3ecf2e68a063e831f50ce9137155c7255495327f
1 parent 2a63938 commit d39d5d8

File tree

4 files changed

+10
-66
lines changed

4 files changed

+10
-66
lines changed

packages/react-native/Libraries/StyleSheet/__tests__/processBoxShadow-itest.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* LICENSE file in the root directory of this source tree.
66
*
77
* @flow strict-local
8-
* @fantom_flags enableOptimizedBoxShadowParsing:*
98
* @format
109
*/
1110

packages/react-native/Libraries/StyleSheet/processBoxShadow.js

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
import type {ProcessedColorValue} from './processColor';
1212
import type {BoxShadowValue} from './StyleSheetTypes';
1313

14-
import {enableOptimizedBoxShadowParsing} from '../../src/private/featureflags/ReactNativeFeatureFlags';
1514
import processColor from './processColor';
1615

17-
// Pre-compiled regex patterns for performance - avoids regex compilation on each call
1816
const COMMA_SPLIT_REGEX = /,(?![^()]*\))/;
1917
const WHITESPACE_SPLIT_REGEX = /\s+(?![^(]*\))/;
2018
const LENGTH_PARSE_REGEX = /^([+-]?\d*\.?\d+)(px)?$/;
@@ -39,12 +37,7 @@ export default function processBoxShadow(
3937

4038
const boxShadowList =
4139
typeof rawBoxShadows === 'string'
42-
? parseBoxShadowString(
43-
rawBoxShadows.replace(
44-
enableOptimizedBoxShadowParsing() ? NEWLINE_REGEX : /\n/g,
45-
' ',
46-
),
47-
)
40+
? parseBoxShadowString(rawBoxShadows.replace(NEWLINE_REGEX, ' '))
4841
: rawBoxShadows;
4942

5043
for (const rawBoxShadow of boxShadowList) {
@@ -121,9 +114,7 @@ function parseBoxShadowString(rawBoxShadows: string): Array<BoxShadowValue> {
121114
let result: Array<BoxShadowValue> = [];
122115

123116
for (const rawBoxShadow of rawBoxShadows
124-
.split(
125-
enableOptimizedBoxShadowParsing() ? COMMA_SPLIT_REGEX : /,(?![^()]*\))/,
126-
) // split by comma that is not in parenthesis
117+
.split(COMMA_SPLIT_REGEX)
127118
.map(bS => bS.trim())
128119
.filter(bS => bS !== '')) {
129120
const boxShadow: BoxShadowValue = {
@@ -137,11 +128,7 @@ function parseBoxShadowString(rawBoxShadows: string): Array<BoxShadowValue> {
137128
let lengthCount = 0;
138129

139130
// split rawBoxShadow string by all whitespaces that are not in parenthesis
140-
const args = rawBoxShadow.split(
141-
enableOptimizedBoxShadowParsing()
142-
? WHITESPACE_SPLIT_REGEX
143-
: /\s+(?![^(]*\))/,
144-
);
131+
const args = rawBoxShadow.split(WHITESPACE_SPLIT_REGEX);
145132
for (const arg of args) {
146133
const processedColor = processColor(arg);
147134
if (processedColor != null) {
@@ -210,43 +197,18 @@ function parseBoxShadowString(rawBoxShadows: string): Array<BoxShadowValue> {
210197
}
211198

212199
function parseLength(length: string): ?number {
213-
if (enableOptimizedBoxShadowParsing()) {
214-
// Use pre-compiled regex for performance
215-
const match = LENGTH_PARSE_REGEX.exec(length);
200+
const match = LENGTH_PARSE_REGEX.exec(length);
216201

217-
if (!match) {
218-
return null;
219-
}
220-
221-
const value = parseFloat(match[1]);
222-
if (Number.isNaN(value)) {
223-
return null;
224-
}
225-
226-
// match[2] is 'px' or undefined
227-
// If no unit and value is not 0, return null
228-
if (match[2] == null && value !== 0) {
229-
return null;
230-
}
231-
232-
return value;
233-
}
234-
235-
// matches on args with units like "1.5 5% -80deg"
236-
const argsWithUnitsRegex = /([+-]?\d*(\.\d+)?)([\w\W]+)?/g;
237-
const match = argsWithUnitsRegex.exec(length);
238-
239-
if (!match || Number.isNaN(match[1])) {
202+
if (!match) {
240203
return null;
241204
}
242205

243-
if (match[3] != null && match[3] !== 'px') {
244-
return null;
245-
}
206+
const value = parseFloat(match[1]);
246207

247-
if (match[3] == null && match[1] !== '0') {
208+
// If no unit (px) and value is not 0, reject it
209+
if (match[2] == null && value !== 0) {
248210
return null;
249211
}
250212

251-
return Number(match[1]);
213+
return value;
252214
}

packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,17 +1054,6 @@ const definitions: FeatureFlagDefinitions = {
10541054
},
10551055
ossReleaseStage: 'none',
10561056
},
1057-
enableOptimizedBoxShadowParsing: {
1058-
defaultValue: false,
1059-
metadata: {
1060-
dateAdded: '2026-02-26',
1061-
description:
1062-
'Hoists regex patterns to module scope and optimizes parseLength in processBoxShadow for improved performance.',
1063-
expectedReleaseValue: true,
1064-
purpose: 'experimentation',
1065-
},
1066-
ossReleaseStage: 'none',
1067-
},
10681057
externalElementInspectionEnabled: {
10691058
defaultValue: true,
10701059
metadata: {

packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<5966ef11ee71a38059decda1c529fd6f>>
7+
* @generated SignedSource<<0fffffdeaf8ab7210131ac789f8b208b>>
88
* @flow strict
99
* @noformat
1010
*/
@@ -33,7 +33,6 @@ export type ReactNativeFeatureFlagsJsOnly = $ReadOnly<{
3333
animatedShouldUseSingleOp: Getter<boolean>,
3434
deferFlatListFocusChangeRenderUpdate: Getter<boolean>,
3535
disableMaintainVisibleContentPosition: Getter<boolean>,
36-
enableOptimizedBoxShadowParsing: Getter<boolean>,
3736
externalElementInspectionEnabled: Getter<boolean>,
3837
fixImageSrcDimensionPropagation: Getter<boolean>,
3938
fixVirtualizeListCollapseWindowSize: Getter<boolean>,
@@ -165,11 +164,6 @@ export const deferFlatListFocusChangeRenderUpdate: Getter<boolean> = createJavaS
165164
*/
166165
export const disableMaintainVisibleContentPosition: Getter<boolean> = createJavaScriptFlagGetter('disableMaintainVisibleContentPosition', false);
167166

168-
/**
169-
* Hoists regex patterns to module scope and optimizes parseLength in processBoxShadow for improved performance.
170-
*/
171-
export const enableOptimizedBoxShadowParsing: Getter<boolean> = createJavaScriptFlagGetter('enableOptimizedBoxShadowParsing', false);
172-
173167
/**
174168
* Enable the external inspection API for DevTools to communicate with the Inspector overlay.
175169
*/

0 commit comments

Comments
 (0)