@@ -152,17 +152,33 @@ function PuckProvider<
152152
153153 const viewportWidth = window . innerWidth ;
154154
155+ const fullWidthViewport = Object . values ( viewports ) . find (
156+ ( v ) => v . width === "100%"
157+ ) ;
158+
159+ const containsFullWidthViewport = ! ! fullWidthViewport ;
160+
155161 const viewportDifferences = Object . entries ( viewports )
162+ . filter ( ( [ _ , value ] ) => value . width !== "100%" )
156163 . map ( ( [ key , value ] ) => ( {
157164 key,
158165 diff : Math . abs (
159166 viewportWidth -
160167 ( typeof value . width === "string" ? viewportWidth : viewportWidth )
161168 ) ,
169+ value,
162170 } ) )
163171 . sort ( ( a , b ) => ( a . diff > b . diff ? 1 : - 1 ) ) ;
164172
165- const closestViewport = viewportDifferences [ 0 ] . key as any ;
173+ let closestViewport = viewportDifferences [ 0 ] . value ;
174+
175+ // Select full width viewport if it exists, and the closest viewport is smaller than the window
176+ if (
177+ ( closestViewport . width as number ) > viewportWidth &&
178+ containsFullWidthViewport
179+ ) {
180+ closestViewport = fullWidthViewport ;
181+ }
166182
167183 if ( iframe . enabled ) {
168184 clientUiState = {
@@ -174,11 +190,10 @@ function PuckProvider<
174190 ...initial . viewports . current ,
175191 height :
176192 initialUi ?. viewports ?. current ?. height ||
177- viewports [ closestViewport ] ?. height ||
193+ closestViewport ?. height ||
178194 "auto" ,
179195 width :
180- initialUi ?. viewports ?. current ?. width ||
181- viewports [ closestViewport ] ?. width ,
196+ initialUi ?. viewports ?. current ?. width || closestViewport ?. width ,
182197 } ,
183198 } ,
184199 } ;
0 commit comments