File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ if (process.env.NODE_ENV === 'production') {
24
24
window . addEventListener ( 'load' , ( ) => listen ( ) ) ;
25
25
}
26
26
27
+ let raf = null ;
27
28
let title = document . querySelector ( 'h1' ) ;
28
29
29
30
// Size the title to fit the available space.
@@ -45,7 +46,7 @@ function updateTitleFontSize() {
45
46
}
46
47
47
48
// Reduce the font size until it doesn't overflow.
48
- while ( title . scrollWidth > title . clientWidth ) {
49
+ while ( fontSize > 10 && title . scrollWidth > title . clientWidth + 1 ) {
49
50
fontSize -- ;
50
51
title . style . fontSize = fontSize + 'px' ;
51
52
}
@@ -56,8 +57,13 @@ updateTitleFontSize();
56
57
// Use ResizeObserver where available to detect size changes not related to window resizing, e.g. font loading.
57
58
if ( typeof ResizeObserver !== 'undefined' ) {
58
59
let observer = new ResizeObserver ( ( ) => {
60
+ if ( ! raf ) {
59
61
// Avoid updating the layout during the resize event and creating circular notifications.
60
- requestAnimationFrame ( updateTitleFontSize ) ;
62
+ raf = requestAnimationFrame ( ( ) => {
63
+ updateTitleFontSize ( ) ;
64
+ raf = null ;
65
+ } ) ;
66
+ }
61
67
} ) ;
62
68
observer . observe ( title ) ;
63
69
} else {
You can’t perform that action at this time.
0 commit comments