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

Stylesheet.create incompatible return type #2068

Closed
badsyntax opened this issue Jun 24, 2021 · 2 comments
Closed

Stylesheet.create incompatible return type #2068

badsyntax opened this issue Jun 24, 2021 · 2 comments

Comments

@badsyntax
Copy link

badsyntax commented Jun 24, 2021

The problem

The return type of RNW StyleSheet.create is incompatible with RN StyleSheet.create. This causes problems in css libraries where RN is aliased to RNW via https://www.npmjs.com/package/babel-plugin-react-native-web.

RNW implementation:

create(styles: Object): {| [key: string]: number |} {
const result = {};
Object.keys(styles).forEach((key) => {
if (process.env.NODE_ENV !== 'production') {
validate(key, styles);
}
const id = styles[key] && ReactNativePropRegistry.register(styles[key]);
result[key] = id;
});
return result;
},

RN implementation:

https://github.com/facebook/react-native/blob/36318b6776507ba31070f6c8a3493609238a1a98/Libraries/StyleSheet/StyleSheet.js#L359-L371

How to reproduce

// RNW
StyleSheet.create({
  foo: {
    color: 'blue'
  }
})
// results in: { foo: 89 }


// RN
StyleSheet.create({
  foo: {
    color: 'blue'
  }
})
// results in: { foo: { color: 'blue' } }

Simplified test case: Not sure if this is useful: https://codesandbox.io/s/async-bush-kfpgo?file=/src/App.js

Expected behavior

I expect the return type to match RN.

Environment (include versions). Did this work in previous versions?

  • React Native for Web (version): 0.17.0
  • React (version): 16.14.0
  • Browser: n/a

Additional context

@necolas
Copy link
Owner

necolas commented Jun 24, 2021

This has been discussed before and for now we keep the original RN return type as web optimisations are built around it

@necolas necolas closed this as completed Jun 24, 2021
@badsyntax
Copy link
Author

Okie doke. I took a quick look at the required changes and I agree it seems like high effort to refactor things to align with react-native, which is unfortunate.

Here's some related issues where this change was previously discussed:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants