Skip to content

Commit

Permalink
Don't touch needless peroperties for better performance #3557
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed May 23, 2024
1 parent 0abe3e2 commit 9022cb0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
23 changes: 18 additions & 5 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,10 +985,16 @@ export async function doProgressively(tabs, task, interval) {
}


export function watchOverflowStateChange({ target, moreResizeTargets, onOverflow, onUnderflow }) {
export function watchOverflowStateChange({ target, moreResizeTargets, onOverflow, onUnderflow, horizontal, vertical }) {
if (!horizontal && !vertical)
return;

onOverflow = onOverflow || (() => {});
onUnderflow = onUnderflow || (() => {});
let lastOverflow = isOverflow(target);
let lastOverflow = (
(horizontal && isOverflowHorizontally(target)) ||
(vertical && isOverflowVertically(target))
);
let lastStarted = new Map();
const onObserved = () => {
const startAt = `${Date.now()}-${parseInt(Math.random() * 65000)}`;
Expand All @@ -997,7 +1003,10 @@ export function watchOverflowStateChange({ target, moreResizeTargets, onOverflow
if (lastStarted.get(target) != startAt)
return;

const overflow = isOverflow(target);
const overflow = (
(horizontal && isOverflowHorizontally(target)) ||
(vertical && isOverflowVertically(target))
);
if (overflow == lastOverflow)
return;

Expand Down Expand Up @@ -1053,8 +1062,12 @@ export function watchOverflowStateChange({ target, moreResizeTargets, onOverflow
return unwatch;
}

function isOverflow(target) {
return target.scrollHeight > target.clientHeight || target.scrollWidth > target.clientWidth;
function isOverflowHorizontally(target) {
return target.scrollWidth > target.clientWidth;
}

function isOverflowVertically(target) {
return target.scrollHeight > target.clientHeight;
}


Expand Down
1 change: 1 addition & 0 deletions webextensions/sidebar/components/TabLabelElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export class TabLabelElement extends HTMLElement {
this.__onUnderflow = this._onUnderflow.bind(this);
this.__unwatch = watchOverflowStateChange({
target: this,
horizontal: true,
onOverflow: () => this.__onOverflow(),
onUnderflow: () => this.__onUnderflow(),
});
Expand Down
1 change: 1 addition & 0 deletions webextensions/sidebar/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export function init(scrollPosition) {
function startObserveOverflowStateChange() {
watchOverflowStateChange({
target: mNormalScrollBox,
vertical: true,
moreResizeTargets: [
// We need to watch resizing of the virtual scroll container to detect the changed state correctly.
mNormalScrollBox.querySelector('.virtual-scroll-container'),
Expand Down

0 comments on commit 9022cb0

Please sign in to comment.