Skip to content

Commit

Permalink
feat(masthead-v2): debounce resize observer callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jkaeser committed Oct 10, 2023
1 parent 9f5f71f commit 9ff1d18
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1339,9 +1339,26 @@ class DDSMastheadComposite extends HostListenerMixin(LitElement) {
* @private
*/
private _heightResizeObserver = new ResizeObserver(
this._setContainerHeight.bind(this)
this._resizeObserverCallback.bind(this)
);

/**
* Prevents resize observer from blocking main thread.
*/
private _resizeObserverThrottle?: NodeJS.Timeout

/**
* Throttled callback for _heightResizeObserver.
*/
protected _resizeObserverCallback() {
if (!this._resizeObserverThrottle) {
this._setContainerHeight();
this._resizeObserverThrottle = setTimeout(() => {
this._resizeObserverThrottle = undefined;
}, 100);
}
}

/**
* Sets root element's height equal to the height of the fixed masthead elements.
*/
Expand Down

0 comments on commit 9ff1d18

Please sign in to comment.