Skip to content

Commit

Permalink
ensure resize observer is calculated once per frame to avoid loops (#763
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sserrata committed Mar 21, 2024
1 parent effd6b9 commit 748e42c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,13 @@ function TabList({
useEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
requestAnimationFrame(() => {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
});
}
});

Expand Down Expand Up @@ -159,8 +161,8 @@ function TabList({
parseInt(value) >= 400
? "danger"
: parseInt(value) >= 200 && parseInt(value) < 300
? "success"
: "info",
? "success"
: "info",
{
active: selectedValue === value,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ function TabList({
useEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
requestAnimationFrame(() => {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
});
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ function TabList({
useEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
requestAnimationFrame(() => {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
});
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ function TabList({
useEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
requestAnimationFrame(() => {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
});
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ function TabList({
useEffect(() => {
const resizeObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
requestAnimationFrame(() => {
if (entry.target.clientWidth < entry.target.scrollWidth) {
setShowTabArrows(true);
} else {
setShowTabArrows(false);
}
});
}
});

Expand Down

0 comments on commit 748e42c

Please sign in to comment.