Skip to content

Commit

Permalink
now with functioning tree-shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrencrona committed Jun 30, 2020
1 parent 74b7c3b commit ed25dd1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/gatsby-image/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,22 @@ Img.propTypes = {
onLoad: PropTypes.func,
}

// Intentionally not an instance method because webpack is not able to
// three-shake it away in production
function validateImageProps({ fluid, fixed }) {
if (!fluid && !fixed) {
console.warn(
`gatsby-image expects a 'fixed' or a 'fluid' prop; neither was present.`
)
}
}

class Image extends React.Component {
constructor(props) {
super(props)

if (process.env.NODE_ENV !== `production`) {
this.validateProps(props)
validateImageProps(props)
}

// If this image has already been loaded before then we can assume it's
Expand Down Expand Up @@ -368,14 +378,6 @@ class Image extends React.Component {
this.handleRef = this.handleRef.bind(this)
}

validateProps({ fluid, fixed }) {
if (!fluid && !fixed) {
console.warn(
`gatsby-image expects a 'fixed' or a 'fluid' prop; neither was present.`
)
}
}

componentDidMount() {
if (this.state.isVisible && typeof this.props.onStartLoad === `function`) {
this.props.onStartLoad({ wasCached: inImageCache(this.props) })
Expand Down

0 comments on commit ed25dd1

Please sign in to comment.