shirakaba / react-nativescript

React renderer for NativeScript
https://react-nativescript.netlify.com
MIT License
280 stars 14 forks source link

Error when re-rendering from <page> to <page style={{ width: "100%", height: "100%" }}/> #58

Closed shirakaba closed 3 years ago

t1amat9409 commented 4 years ago

I haven't noticed. Should run a quick dummy, but I might have had a crash while using the old goToReactPage() func.

shirakaba commented 4 years ago

@t1amat9409 it's usually something you might only notice during HMR updates. It's not to do with the Page element but rather the style prop. When the style prop is unspecified, it is treated as null by the reconciler. And when it's specified, it's an object of styles that we call Object.keys(stylesObject) upon. The problem is that I haven't put in a guard to prevent Object.keys(null) from occurring.

I'll get around to it. I hope to make style accept an array of styles (just like in React Native) at the same time, but last time I tried to implement it, I couldn't get it working perfectly. It should be doable once I have a free day to try it.

So, as a workaround for now, in case you encounter this in the wild:

// Don't do this
function willThrowError({ someCondition }){
  return (
    someCondition ? <page/> : <page style={{ backgroundColor: "red" }}/>;
  );
}

// Do do this
function willRender({ someCondition }){
  return (
    someCondition ? <page style={{}}/> : <page style={{ backgroundColor: "red" }}/>;
  );
}
shirakaba commented 3 years ago

Fixed in RNS v2.2.0!