@@ -161,8 +161,7 @@ export class NgOptimizedImage implements OnInit, OnChanges, OnDestroy {
161161 assertNoConflictingSrcset ( this ) ;
162162 assertNotBase64Image ( this ) ;
163163 assertNotBlobURL ( this ) ;
164- assertRequiredNumberInput ( this , this . width , 'width' ) ;
165- assertRequiredNumberInput ( this , this . height , 'height' ) ;
164+ assertNonEmptyWidthAndHeight ( this ) ;
166165 assertValidLoadingInput ( this ) ;
167166 assertNoImageDistortion ( this , this . imgElement , this . renderer ) ;
168167 if ( this . priority ) {
@@ -507,13 +506,17 @@ function assertNoImageDistortion(
507506}
508507
509508// Verifies that a specified input is set.
510- function assertRequiredNumberInput ( dir : NgOptimizedImage , inputValue : unknown , inputName : string ) {
511- if ( typeof inputValue === 'undefined' ) {
509+ function assertNonEmptyWidthAndHeight ( dir : NgOptimizedImage ) {
510+ let missingAttributes = [ ] ;
511+ if ( dir . width === undefined ) missingAttributes . push ( 'width' ) ;
512+ if ( dir . height === undefined ) missingAttributes . push ( 'height' ) ;
513+ if ( missingAttributes . length > 0 ) {
512514 throw new RuntimeError (
513515 RuntimeErrorCode . REQUIRED_INPUT_MISSING ,
514- `${ imgDirectiveDetails ( dir . rawSrc ) } has detected that the required \`${ inputName } \` ` +
515- `attribute is missing. Please specify the \`${ inputName } \` attribute ` +
516- `on the mentioned element.` ) ;
516+ `${ imgDirectiveDetails ( dir . rawSrc ) } has detected that these required attributes` +
517+ ` are missing:\`${ missingAttributes . join ( ',' ) } \`. Including "width" and "height" ` +
518+ `attributes will prevent image-related layout shifts. Please include "width" and ` +
519+ `"height" attributes on the image tag.` ) ;
517520 }
518521}
519522
0 commit comments