-
Notifications
You must be signed in to change notification settings - Fork 796
Props shouldn’t be overwritten #967
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
Conversation
Another solution to the problem we're having with styles-jsx is to remove the extra |
Codecov Report
@@ Coverage Diff @@
## master #967 +/- ##
=======================================
Coverage 88.99% 88.99%
=======================================
Files 30 30
Lines 727 727
Branches 166 166
=======================================
Hits 647 647
Misses 66 66
Partials 14 14
Continue to review full report at Codecov.
|
As far as I know - the logic around merging props should correct. const Switch = ({flag}) => flag ? <button1 /> : <button2 />;
<Switch flag={0}
// and then
<Switch flag={1} React will re-render something with flag={1} and that means that we have to work with flag={1}, with a new prop, not the old one. Look like, you dont need this change. You might need remove side effect on props. So - store the original props, and restore them just after render.
I have to double check. Meanwhile - could you double check that const next = instance => {
// copy over props as long new component may be hidden inside them
// child does not have all props, as long some of them can be calculated on componentMount.
const realProps = instance.props; // <<-------
const nextProps = {
...instance.props,
...(child.nextProps || {}),
...(child.props || {}),
}
if (isReactClass(instance) && instance.componentWillUpdate) {
// Force-refresh component (bypass redux renderedComponent)
instance.componentWillUpdate(nextProps, instance.state)
}
instance.props = nextProps
hotReplacementRender(instance, stackChild)
instance.props = realProps; // <<-----
} Fixes your problem. Might be this change should be added. |
Since:
is still called the result is the same |
The code is located here: https://github.com/zeit/styled-jsx/blob/master/src/style.js#L26-L28 |
Why changing the props merge order (and why you are getting new values?) fixes the problem? |
Ok. So what I found:
See #968 |
Awesome @theKashey 🏆 ❤️
Yeah so this is what was done before (in rhl 3 / 4.0.0/4.0.1), I'll check your branch 👍 |
#968 fixes this issue. |
I'm not sure what the correct functionality is, either providing the new props vs the old ones / merging them etc. But the change made in 4.1.0 is breaking and should be part of a major version.
It also seems weird to me that
componentWillUpdate
is called from react-hot-loader 🤔Fixes vercel/next.js#4299
testProps
is the old way they were calculated in 4.0.0/4.1.0nextProps
are the new way they were calculated in 4.1.0+My change brings back the result of
testProps
rather thannextProps
.