From c8e5ed4890942c367ffb832052b1ae1f09fe4b44 Mon Sep 17 00:00:00 2001 From: Robert Snow Date: Fri, 23 Aug 2024 07:58:03 +1000 Subject: [PATCH] Fix Safari docs crash (#6930) * Fix Safari docs crash --- packages/dev/docs/src/client.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/dev/docs/src/client.js b/packages/dev/docs/src/client.js index f959b884286..f92f63fa291 100644 --- a/packages/dev/docs/src/client.js +++ b/packages/dev/docs/src/client.js @@ -24,6 +24,7 @@ if (process.env.NODE_ENV === 'production') { window.addEventListener('load', () => listen()); } +let raf = null; let title = document.querySelector('h1'); // Size the title to fit the available space. @@ -45,7 +46,7 @@ function updateTitleFontSize() { } // Reduce the font size until it doesn't overflow. - while (title.scrollWidth > title.clientWidth) { + while (fontSize > 10 && title.scrollWidth > title.clientWidth + 1) { fontSize--; title.style.fontSize = fontSize + 'px'; } @@ -56,8 +57,13 @@ updateTitleFontSize(); // Use ResizeObserver where available to detect size changes not related to window resizing, e.g. font loading. if (typeof ResizeObserver !== 'undefined') { let observer = new ResizeObserver(() => { + if (!raf) { // Avoid updating the layout during the resize event and creating circular notifications. - requestAnimationFrame(updateTitleFontSize); + raf = requestAnimationFrame(() => { + updateTitleFontSize(); + raf = null; + }); + } }); observer.observe(title); } else {