@@ -109,19 +109,19 @@ export const GalleryContainer = ({
109109 > ( [ ] ) ;
110110
111111 useLayoutEffect ( ( ) => {
112- if (
113- imageElements . current &&
114- imageElements . current . every ( ( element ) => ! ! element ) &&
115- imageAttachmentSizeHandler
116- ) {
117- const newConfigurations : ImageAttachmentConfiguration [ ] = [ ] ;
118- imageElements . current . forEach ( ( element , i ) => {
119- const config = imageAttachmentSizeHandler ( attachment . images [ i ] , element ) ;
120- newConfigurations . push ( config ) ;
121- } ) ;
122- setAttachmentConfigurations ( newConfigurations ) ;
112+ if ( ! imageElements . current || ! imageAttachmentSizeHandler ) return ;
113+ const newConfigurations : ImageAttachmentConfiguration [ ] = [ ] ;
114+ const nonNullImageElements = imageElements . current . filter ( ( e ) => ! ! e ) ;
115+ if ( nonNullImageElements . length < imageElements . current . length ) {
116+ imageElements . current = nonNullImageElements ;
123117 }
124- } , [ imageElements , imageAttachmentSizeHandler , attachment ] ) ;
118+ imageElements . current . forEach ( ( element , i ) => {
119+ if ( ! element ) return ;
120+ const config = imageAttachmentSizeHandler ( attachment . images [ i ] , element ) ;
121+ newConfigurations . push ( config ) ;
122+ } ) ;
123+ setAttachmentConfigurations ( newConfigurations ) ;
124+ } , [ imageAttachmentSizeHandler , attachment ] ) ;
125125
126126 const images = attachment . images . map ( ( image , i ) => ( {
127127 ...image ,
0 commit comments