Skip to content

Commit 43536e0

Browse files
glennreyeswardpeet
authored andcommitted
fix(gatsby-image): Fix loading="eager" & critical (#17148)
1 parent fe89795 commit 43536e0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/gatsby-image/src/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,17 @@ class Image extends React.Component {
283283
// already in the browser cache so it's cheap to just show directly.
284284
this.seenBefore = isBrowser && inImageCache(props)
285285

286-
this.addNoScript = !(props.critical && !props.fadeIn)
286+
this.isCritical = props.loading === `eager` || props.critical
287+
288+
this.addNoScript = !(this.isCritical && !props.fadeIn)
287289
this.useIOSupport =
288290
!hasNativeLazyLoadSupport &&
289291
hasIOSupport &&
290-
!props.critical &&
292+
!this.isCritical &&
291293
!this.seenBefore
292294

293295
const isVisible =
294-
props.critical ||
295-
props.loading == `eager` ||
296+
this.isCritical ||
296297
(isBrowser && (hasNativeLazyLoadSupport || !this.useIOSupport))
297298

298299
this.state = {
@@ -311,7 +312,7 @@ class Image extends React.Component {
311312
if (this.state.isVisible && typeof this.props.onStartLoad === `function`) {
312313
this.props.onStartLoad({ wasCached: inImageCache(this.props) })
313314
}
314-
if (this.props.critical) {
315+
if (this.isCritical) {
315316
const img = this.imageRef.current
316317
if (img && img.complete) {
317318
this.handleImageLoaded()

0 commit comments

Comments
 (0)