Fix comma-operator bug that made shadow*/textShadow* deprecation warnings and conversion unconditional#2844
Conversation
The 'shadow' and 'textShadow' preprocess option flags were written with a comma operator instead of a logical AND, so the flag was evaluated and discarded. As a result the "shadow*"/"textShadow*" deprecation warnings fired (and the conversion ran) for every style containing those props, regardless of the caller's options. Use a logical AND so the conversion and deprecation warning only run when the corresponding option is enabled, as intended by 2a901e5. Fix necolas#2782
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f66e9eb:
|
|
@necolas TL;DR: the two shadow guards in |
Problem
Using
textShadow*(orshadow*) style props triggers the deprecation warning"textShadow*" style props are deprecated. Use "textShadow".for every caller ofpreprocess, regardless of theshadow/textShadowoption flags, and the conversion toboxShadow/textShadowalso runs unconditionally.Root cause
In
packages/react-native-web/src/exports/StyleSheet/preprocess.jsthe two guards were written with the comma operator instead of a logical AND:The comma operator evaluates and discards
options.shadow === true, so the condition reduces to "style contains shadow props" and the flag introduced in 2a901e5 ("Once Image is implemented using createElement, we can disable the 'boxShadow' generation just for Image") never had any effect.Fix
Use a logical AND so the conversion and its deprecation warning only run when the corresponding option is enabled:
Behavior through the public
StyleSheetAPI is unchanged (it passes{ shadow: true, textShadow: true }by default); only directpreprocesscallers that did not opt in stop warning/converting, as originally intended.To be explicit about scope: the deprecation warning for
shadow*/textShadow*through the public API is intentional and retained — those props are deprecated. This PR fixes the broken option flag, not the deprecation itself, so the warning in the issue's repro still fires by design. If removing the public-API warning is wanted too, that seems like a separate decision (theremove-deprecation-warningsbranch deliberately kept these two).Tests
preprocess-test.jsto opt in via the option flags.deprecation warnings for shadow stylesdescribe block asserting: noconsole.warnand no conversion when the flag is not set (previously false-positive paths), and that the warning still fires when the flag is set. The new no-warning tests fail without the fix.jest(full dom + node suites),prettier --check,eslint, andflowall pass.Refs #2782