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

React 16 #104

Merged
merged 11 commits into from
Sep 3, 2019
Merged

React 16 #104

merged 11 commits into from
Sep 3, 2019

Conversation

landonreed
Copy link
Member

@landonreed landonreed commented Aug 23, 2019

Update app to React 16. This also:

  • updates a number of other deps,
  • removes PropTypes imports from React, and
  • changes some lifecycle methods as required by migration to 16.

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).

@codecov-io
Copy link

codecov-io commented Aug 23, 2019

Codecov Report

Merging #104 into dev will increase coverage by 0.07%.
The diff coverage is 3.78%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
lib/components/mobile/results-screen.js 0% <ø> (ø) ⬆️
lib/actions/api.js 44.37% <0%> (ø) ⬆️
lib/components/narrative/default/transit-leg.js 0% <0%> (ø) ⬆️
lib/components/app/responsive-webapp.js 0% <0%> (ø) ⬆️
lib/components/narrative/default/tnc-leg.js 0% <0%> (ø) ⬆️
lib/components/map/zipcar-overlay.js 0% <0%> (ø) ⬆️
lib/components/form/date-time-modal.js 0% <0%> (ø) ⬆️
lib/components/narrative/leg-diagram-preview.js 0% <0%> (ø) ⬆️
lib/components/narrative/narrative-itineraries.js 0% <0%> (ø) ⬆️
lib/components/form/date-time-preview.js 0% <0%> (ø) ⬆️
... and 52 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d24ce6...b9be98d. Read the comment docs.

Copy link
Contributor

@evansiroky evansiroky left a 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.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Aug 26, 2019
@landonreed landonreed marked this pull request as ready for review August 26, 2019 17:34
@landonreed landonreed assigned evansiroky and unassigned landonreed Aug 26, 2019
@landonreed landonreed requested a review from evansiroky August 26, 2019 17:34
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.
Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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)
}
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

Copy link
Member Author

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()
Copy link
Contributor

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.

Copy link
Member Author

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 })
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@evansiroky evansiroky left a 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:

  1. 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.
  2. 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.
  3. 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.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Aug 26, 2019
@landonreed landonreed assigned evansiroky and unassigned landonreed Aug 28, 2019
Copy link
Contributor

@evansiroky evansiroky left a 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.

@evansiroky evansiroky assigned landonreed and unassigned evansiroky Aug 30, 2019
@landonreed landonreed merged commit b17ab42 into dev Sep 3, 2019
@landonreed landonreed deleted the react16 branch September 3, 2019 14:38
@evansiroky
Copy link
Contributor

🎉 This PR is included in version 0.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants