File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
plugins/optimization-detective Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -325,6 +325,16 @@ export default async function detect( {
325
325
return ;
326
326
}
327
327
328
+ // Keep track of whether the window resized. If it resized, we abort sending the URLMetric.
329
+ let didWindowResize = false ;
330
+ window . addEventListener (
331
+ 'resize' ,
332
+ ( ) => {
333
+ didWindowResize = true ;
334
+ } ,
335
+ { once : true }
336
+ ) ;
337
+
328
338
// TODO: Does this make sense here?
329
339
// Prevent detection when page is not scrolled to the initial viewport.
330
340
if ( doc . documentElement . scrollTop > 0 ) {
@@ -507,6 +517,17 @@ export default async function detect( {
507
517
) ;
508
518
} ) ;
509
519
520
+ // Only proceed with submitting the URL Metric if viewport stayed the same size. Changing the viewport size (e.g. due
521
+ // to resizing a window or changing the orientation of a device) will result in unexpected metrics being collected.
522
+ if ( didWindowResize ) {
523
+ if ( isDebug ) {
524
+ log (
525
+ 'Aborting URL Metric collection due to viewport size change.'
526
+ ) ;
527
+ }
528
+ return ;
529
+ }
530
+
510
531
if ( extensions . size > 0 ) {
511
532
for ( const [
512
533
extensionModuleUrl ,
You can’t perform that action at this time.
0 commit comments