Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Fix issue with react-transition-group's PropTypes (#21)
Browse files Browse the repository at this point in the history
* Fix issue with Node production envirnoment

`react-transition-group`'s custom PropTypes are null if the NODE_ENV is "production."  This causes an Internal Server Error in Next.js, "Cannot read property 'isRequired' of null." 

To fix this, I simply mirrored the react-transition-group's code by nullifying the prop type `timeoutsShape` only if `process.env.NODE_ENV` is "production".

* Avoiding production console error

I realized my previous commit fixed the problem but would have resulted in a console.error in production for any time that a  `loadingTimeout` prop was supplied.
  • Loading branch information
ScottMorse authored and nwalters512 committed Jan 30, 2019
1 parent 6d158ed commit 74ae9d8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/PageTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,17 @@ class PageTransition extends React.Component {
PageTransition.propTypes = {
children: PropTypes.node.isRequired,
classNames: PropTypes.string.isRequired,
timeout: timeoutsShape.isRequired,
timeout: process.env.NODE_ENV !== "production" ? timeoutsShape.isRequired : null,
loadingComponent: PropTypes.element,
loadingDelay: PropTypes.number,
loadingCallbackName: PropTypes.string,
/* eslint-disable react/require-default-props */
loadingTimeout: (props, ...args) => {
let pt = timeoutsShape
if (props.loadingComponent) pt = pt.isRequired
return pt(props, ...args)
if (props.loadingComponent && process.env.NODE_ENV !== "production"){
pt = pt.isRequired
return pt(props, ...args)
}
},
loadingClassNames: (props, ...args) => {
let pt = PropTypes.string
Expand Down

0 comments on commit 74ae9d8

Please sign in to comment.