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

Inconsistent defaultProps behavior in debug / no debug mode #131

Open
djaonourside opened this issue Oct 11, 2019 · 8 comments
Open

Inconsistent defaultProps behavior in debug / no debug mode #131

djaonourside opened this issue Oct 11, 2019 · 8 comments

Comments

@djaonourside
Copy link

djaonourside commented Oct 11, 2019

It's not picked up default props if they aren't passed from parent component in no debug mode. Maybe react inlining problem:
https://try.haxe.org/#1489A

@elsassph
Copy link
Contributor

@kLabz I'm looking at the defaultProps handling and it looks like components with default props aren't de-optimised but instead the default props are added as a spread - looks like your change?

@elsassph
Copy link
Contributor

elsassph commented Oct 18, 2019

Ooooh I got it @djaonourside

When inlined, the defaultProps are added as spread and plucked to remove the props passed at compile time. Effectively, if props.color has an undefined value the component won't get the default value because of inlining.

@kLabz do you have an idea on how to solve this? React.createComponent will pick default props if the value is undefined at run time.

@kLabz
Copy link
Contributor

kLabz commented Oct 18, 2019

I'm not sure what change you are talking about.

I handled the issue in react-next (last 4 commits here -- diff) but haven't had time to extract it in a PR here yet. I think the issue has always existed here, since the behavior is different at its core: in haxe-react we use the default prop if the prop is not passed while reactjs uses the default prop for every prop that as undefined as a value.

So if we end up passing undefined (when passing a prop from a component to another for example) we have a different behavior.

@elsassph
Copy link
Contributor

elsassph commented Oct 18, 2019

I'm not sure what change you are talking about.

Originally I was de-optimising components with default props completely, so it was going through React.createComponent even for prod builds.

@kLabz
Copy link
Contributor

kLabz commented Oct 18, 2019

I have no memory of either components being de-optimised when they had default props or changing anything about that.

Original implementation seemed to already have the issue.

@elsassph
Copy link
Contributor

@kLabz you're right, it's from my original code 😅. I guess the solution is to never remove fields from defaultProps.

@kLabz
Copy link
Contributor

kLabz commented Oct 18, 2019

Doesn't work either, if you pass undefined as prop it will overwrite the default prop.

@elsassph
Copy link
Contributor

Damn you can overwrite with undefined :/

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

3 participants