@@ -358,6 +358,7 @@ class Image extends React.Component {
358
358
imgLoaded : false ,
359
359
imgCached : false ,
360
360
fadeIn : ! this . seenBefore && props . fadeIn ,
361
+ isHydrated : false ,
361
362
}
362
363
363
364
this . imageRef = React . createRef ( )
@@ -367,6 +368,10 @@ class Image extends React.Component {
367
368
}
368
369
369
370
componentDidMount ( ) {
371
+ this . setState ( {
372
+ isHydrated : isBrowser ,
373
+ } )
374
+
370
375
if ( this . state . isVisible && typeof this . props . onStartLoad === `function` ) {
371
376
this . props . onStartLoad ( { wasCached : inImageCache ( this . props ) } )
372
377
}
@@ -445,6 +450,12 @@ class Image extends React.Component {
445
450
draggable,
446
451
} = convertProps ( this . props )
447
452
453
+ const imageVariants = fluid || fixed
454
+ // Abort early if missing image data (#25371)
455
+ if ( ! imageVariants ) {
456
+ return null
457
+ }
458
+
448
459
const shouldReveal = this . state . fadeIn === false || this . state . imgLoaded
449
460
const shouldFadeIn = this . state . fadeIn === true && ! this . state . imgCached
450
461
@@ -476,10 +487,14 @@ class Image extends React.Component {
476
487
itemProp,
477
488
}
478
489
479
- if ( fluid ) {
480
- const imageVariants = fluid
481
- const image = getCurrentSrcData ( fluid )
490
+ // Initial client render state needs to match SSR until hydration finishes.
491
+ // Once hydration completes, render again to update to the correct image.
492
+ // `imageVariants` is always an Array type at this point due to `convertProps()`
493
+ const image = ! this . state . isHydrated
494
+ ? imageVariants [ 0 ]
495
+ : getCurrentSrcData ( imageVariants )
482
496
497
+ if ( fluid ) {
483
498
return (
484
499
< Tag
485
500
className = { `${ className ? className : `` } gatsby-image-wrapper` }
@@ -585,9 +600,6 @@ class Image extends React.Component {
585
600
}
586
601
587
602
if ( fixed ) {
588
- const imageVariants = fixed
589
- const image = getCurrentSrcData ( fixed )
590
-
591
603
const divStyle = {
592
604
position : `relative` ,
593
605
overflow : `hidden` ,
0 commit comments