Skip to content

Commit

Permalink
Fix Safari docs crash (adobe#6930)
Browse files Browse the repository at this point in the history
* Fix Safari docs crash
  • Loading branch information
snowystinger committed Aug 22, 2024
1 parent acddd45 commit c8e5ed4
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/dev/docs/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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';
}
Expand All @@ -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 {
Expand Down

0 comments on commit c8e5ed4

Please sign in to comment.