react-native-macos/Libraries/StyleSheet
Nick Gerleman e75557b48f Restore Previous Behavior for StyleSheet Validation of Null/Undefined Styles (#29171)
Summary:
https://github.com/facebook/react-native/issues/27264 changed stylesheet validation to avoid enumerating properties on the prototype of a style. It introduces a secondary behavior change, where null/undefined styles used to be tolerated but now lead to an exception. This is because `for in undefined` will noop where `for of Object.keys(undefined)` will throw.

This scenario of undefined/null styles seems to actually show up in practice and was previously well tolerated. E.g. `Button.js` has code that looks like this:

```jsx
const styles = StyleSheet.create({
  button: Platform.select({
    ios: {},
    android: {
      elevation: 4,
      // Material design blue from https://material.google.com/style/color.html#color-color-palette
      backgroundColor: '#2196F3',
      borderRadius: 2,
    },
  }),
```

For non ios/Android platforms, that creates a style object which looks like:
```js
{
  button: undefined,
  ...
}
```

This previously meant that the component would be unstyled if created, but now means out-of-tree platforms throw if the builtin Button component is required.

This change restores the previous `for in` loop but adds a `hasOwnProperty` check to avoid properties on prototypes.

## Changelog

[General] [Fixed] - Restore Previous Behavior for StyleSheet Validation of Null/Undefined Styles
Pull Request resolved: https://github.com/facebook/react-native/pull/29171

Test Plan: Validated that importing Buttons will no longer cause an exception, and that invalid properties are still caught.

Reviewed By: JoshuaGross

Differential Revision: D22118379

Pulled By: TheSavior

fbshipit-source-id: 650c64b934ccd12a3dc1b75e95debc359925ad73
2020-06-25 15:31:54 -07:00
..
__flowtests__ Upgrade Prettier in Xplat to version 1.19.1 2020-04-09 11:01:58 -07:00
__tests__ Add ES Lint rules for `DynamicColorIOS()`and `ColorAndroid()` (#28398) 2020-03-27 23:02:15 -07:00
EdgeInsetsPropType.js Do not explicitly include ".js" in Library imports (#28311) 2020-03-17 02:11:53 -07:00
PlatformColorValueTypes.android.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
PlatformColorValueTypes.ios.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
PlatformColorValueTypesIOS.ios.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
PlatformColorValueTypesIOS.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
PointPropType.js Exact-by-default codemod for react-native-github 2019-11-21 09:42:57 -08:00
Rect.js Pressability: Support Rect or Numeric Size 2020-01-28 15:14:23 -08:00
StyleSheet.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
StyleSheetTypes.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
StyleSheetValidation.js Restore Previous Behavior for StyleSheet Validation of Null/Undefined Styles (#29171) 2020-06-25 15:31:54 -07:00
flattenStyle.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
normalizeColor.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
processColor.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
processColorArray.js Make ColorValue public in StyleSheet.js 2020-04-17 13:03:47 -07:00
processTransform.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
setNormalizedColorAlpha.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
splitLayoutProps.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00