Skip to content

Commit

Permalink
Don't update max tree level immediately when requested too many times…
Browse files Browse the repository at this point in the history
… at a time #3383
  • Loading branch information
piroor committed Nov 1, 2023
1 parent 10f955e commit 5fa5f8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export const configs = new Configs({
// animation
animation: true,
animationForce: false,
maxAllowedImmediateRefreshCount: 10,
smoothScrollEnabled: true,
smoothScrollDuration: 150,
burstDuration: 375,
Expand Down
27 changes: 25 additions & 2 deletions webextensions/sidebar/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,39 @@ export async function reserveToUpdateVisualMaxTreeLevel() {
delete updateVisualMaxTreeLevel.waiting;
}

if (!shouldApplyAnimation()) {
reserveToUpdateVisualMaxTreeLevel.calledCount++;

const animation = shouldApplyAnimation();

// Immediate update may cause a performance issue when this function
// is called too many times.
// On the other hand, delayed update exposes "not updated yet" visual
// to people unexpectedly and it may stress some people sensitive to
// flickers.
// The threshold is a workaround to run immediate update while the
// slowing down is acceptable.
// See also: https://github.com/piroor/treestyletab/issues/3383
if (reserveToUpdateVisualMaxTreeLevel.calledCount <= configs.maxAllowedImmediateRefreshCount &&
!animation) {
updateVisualMaxTreeLevel();
if (reserveToUpdateVisualMaxTreeLevel.waitingToResetCalledCount)
clearTimeout(reserveToUpdateVisualMaxTreeLevel.waitingToResetCalledCount);
reserveToUpdateVisualMaxTreeLevel.waitingToResetCalledCount = setTimeout(() => {
delete reserveToUpdateVisualMaxTreeLevel.waitingToResetCalledCount;
reserveToUpdateVisualMaxTreeLevel.calledCount = 0;
}, 0);
return;
}

const delay = animation ? configs.collapseDuration * 1.5 : 0;

updateVisualMaxTreeLevel.waiting = setTimeout(() => {
delete updateVisualMaxTreeLevel.waiting;
reserveToUpdateVisualMaxTreeLevel.calledCount = 0;
updateVisualMaxTreeLevel();
}, configs.collapseDuration * 1.5);
}, delay);
}
reserveToUpdateVisualMaxTreeLevel.calledCount = 0;

function updateVisualMaxTreeLevel() {
const maxLevel = getMaxTreeLevel(mTargetWindow, {
Expand Down

0 comments on commit 5fa5f8d

Please sign in to comment.