-
Notifications
You must be signed in to change notification settings - Fork 53
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
React 16 #104
React 16 #104
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #104 +/- ##
==========================================
+ Coverage 10.54% 10.62% +0.07%
==========================================
Files 134 134
Lines 6039 6079 +40
Branches 1748 1750 +2
==========================================
+ Hits 637 646 +9
- Misses 4579 4614 +35
+ Partials 823 819 -4
Continue to review full report at Codecov.
|
componentWillReceiveProps is deprecated in React 16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still a draft PR, or is it ready for review? If it's ready, please remove the Draft label.
This was added in an attempt to silence an error/warning during debugging the upgrade to React 16, but the fix was a red herring (something else was the matter).
// If location is updated externally, replace value and geocoded features | ||
// in internal state. | ||
// TODO: This might be considered an anti-pattern. There may be a more | ||
// effective way to handle this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is less-worse than how the geocode results are saved and accessed later. This whole component could use a good refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something for a later round of work...
componentDidUpdate (prevProps) { | ||
this._updateBounds(prevProps, this.props) | ||
// Check if any overlays should be toggled due to mode change | ||
this._handleQueryChange(prevProps.query, this.props.query) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just feels like most of it should be handled elsewhere and not here. Wouldn't these methods get fired on every component update?
if (leg && this.props.leg && leg.startTime !== this.props.leg.startTime) { | ||
componentDidUpdate (prevProps) { | ||
const { leg } = this.props | ||
if (leg && prevProps.leg && leg.startTime !== prevProps.leg.startTime) { | ||
this._determineCompressionFactor(this.state.width, leg) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably not be handled with state. Something for a future refactor.
(acc, ptn) => { | ||
return acc.concat(polyline.decode(ptn.geometry.points)) | ||
}, | ||
[] | ||
) | ||
this.context.map.fitBounds(allPoints) | ||
this.props.leaflet.map.fitBounds(allPoints) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels kind of clunky. Isn't it possible for the react-leaflet map component to accept a bounds prop? If so, it'd be much better to have the bounds for the map set once where one would expect it to be set instead of like here and other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you on this point, but making the bounds entirely controlled is probably an issue for another day. I want to avoid changing too many things at once.
this.props.setMainPanelContent(null) | ||
} | ||
if (!this.props.error && nextProps.error) this.props.setMainPanelContent(null) | ||
if (!prevProps.error && this.props.error) this.props.setMainPanelContent(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all feels like it should be part of an action behind the scenes and not be called after a particular component updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add a FIXME
, but I think we should be careful about changing too many things at once. This PR is intended to update React 16. Perhaps the correct approach to fixing something like this would be to add ticket this and add any thoughts on a proposed solution there if you have them
componentDidMount () { | ||
// this.props.findRoute({ routeId: 'TriMet:1' }) | ||
// this.props.setViewedRoute({ routeId: 'TriMet:1' }) | ||
this.props.findRoutes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could result in numerous findRoutes actions being dispatched whenever the component updates. It seems the intent of this is to do this on the loading of the component, so a better spot to put this would probably be in the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the recommendation is to put ajax requests in componentDidMount
rather than constructors. In any case, I'm not sure it matters that much: reactjs/react.dev#302 (comment)
Regardless, this wouldn't be dispatched whenever the component updates -- only on mount.
componentDidMount () { | ||
const { findTrip, viewedTrip } = this.props | ||
const { tripId } = viewedTrip | ||
findTrip({ tripId }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also probably be in the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #104 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default of renaming componetWillMount
/componentWillReceiveProps
to componentDidUpdate
doesn't seem like the right approach for a lot of cases. I think putting stuff in constructor
for componentWillMount
is probably a better idea. For componentWillReceiveProps
, it does seem right for a few cases, but others maybe not. I think we may end up doing some more refactors on these changes in the future. I don't think we need to do all that now, but it seems like this reveals a few things that could use a future refactor:
- PropTypes should be replaced with static typing as a lot of the PropTypes are so far away from what actually are the props of components.
- An audit of everything that now exists in componentDidUpdate should probably occur. It feels like a lot of what's going on in these components could be handled by moving component into the redux store.
- A lot of these componentDidUpdate methods have things that set the map bounds. It could get hard to track down all these individual calls to leaflet. It's not a very React-way-of-doing-things this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, fine. I'll approve. This all does appear to work fine and there aren't any extra calls that I can see, so good enough. While there's always room for refactors and other ideas, I'll not even recommend creating tickets just yet as the refactoring opportunities I see now may not align with the next latest priorities and pain points we have.
🎉 This PR is included in version 0.13.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Update app to React 16. This also:
Note: You'll see some warnings about lifecycle methods needing to be updated, but these are for components in
react-bootstrap
. We're currently pinned to the latest non-beta (and non Bootstrap v4) version of the dependency, so I'm not sure there's much we can do (and it's probably not worth worrying about since these are just warnings).