Skip to content

Commit c8e5ed4

Browse files
authored
Fix Safari docs crash (#6930)
* Fix Safari docs crash
1 parent acddd45 commit c8e5ed4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/dev/docs/src/client.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if (process.env.NODE_ENV === 'production') {
2424
window.addEventListener('load', () => listen());
2525
}
2626

27+
let raf = null;
2728
let title = document.querySelector('h1');
2829

2930
// Size the title to fit the available space.
@@ -45,7 +46,7 @@ function updateTitleFontSize() {
4546
}
4647

4748
// Reduce the font size until it doesn't overflow.
48-
while (title.scrollWidth > title.clientWidth) {
49+
while (fontSize > 10 && title.scrollWidth > title.clientWidth + 1) {
4950
fontSize--;
5051
title.style.fontSize = fontSize + 'px';
5152
}
@@ -56,8 +57,13 @@ updateTitleFontSize();
5657
// Use ResizeObserver where available to detect size changes not related to window resizing, e.g. font loading.
5758
if (typeof ResizeObserver !== 'undefined') {
5859
let observer = new ResizeObserver(() => {
60+
if (!raf) {
5961
// 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+
}
6167
});
6268
observer.observe(title);
6369
} else {

0 commit comments

Comments
 (0)