Skip to content

Commit

Permalink
fix dimension.resize
Browse files Browse the repository at this point in the history
  • Loading branch information
clementroche committed Feb 25, 2024
1 parent 081fffd commit d68b1c1
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.cjs.js.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/lenis/dist/lenis.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@
this.content = content;

if (autoResize) {
const resize = debounce(this.resize, debounceValue);
this.debouncedResize = debounce(this.resize, debounceValue);

if (this.wrapper === window) {
window.addEventListener('resize', resize, false);
window.addEventListener('resize', this.debouncedResize, false);
} else {
this.wrapperResizeObserver = new ResizeObserver(resize);
this.wrapperResizeObserver = new ResizeObserver(this.debouncedResize);
this.wrapperResizeObserver.observe(this.wrapper);
}

this.contentResizeObserver = new ResizeObserver(resize);
this.contentResizeObserver = new ResizeObserver(this.debouncedResize);
this.contentResizeObserver.observe(this.content);
}

Expand All @@ -125,7 +125,7 @@
destroy() {
this.wrapperResizeObserver?.disconnect();
this.contentResizeObserver?.disconnect();
window.removeEventListener('resize', resize, false);
window.removeEventListener('resize', this.debouncedResize, false);
}

resize = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/lenis/dist/lenis.umd.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/lenis/dist/types/dimensions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class Dimensions {
});
wrapper: any;
content: any;
debouncedResize: ((...args: any[]) => void) | undefined;
wrapperResizeObserver: ResizeObserver | undefined;
contentResizeObserver: ResizeObserver | undefined;
destroy(): void;
Expand Down
10 changes: 5 additions & 5 deletions packages/lenis/src/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ export class Dimensions {
this.content = content

if (autoResize) {
const resize = debounce(this.resize, debounceValue)
this.debouncedResize = debounce(this.resize, debounceValue)

if (this.wrapper === window) {
window.addEventListener('resize', resize, false)
window.addEventListener('resize', this.debouncedResize, false)
} else {
this.wrapperResizeObserver = new ResizeObserver(resize)
this.wrapperResizeObserver = new ResizeObserver(this.debouncedResize)
this.wrapperResizeObserver.observe(this.wrapper)
}

this.contentResizeObserver = new ResizeObserver(resize)
this.contentResizeObserver = new ResizeObserver(this.debouncedResize)
this.contentResizeObserver.observe(this.content)
}

Expand All @@ -30,7 +30,7 @@ export class Dimensions {
destroy() {
this.wrapperResizeObserver?.disconnect()
this.contentResizeObserver?.disconnect()
window.removeEventListener('resize', resize, false)
window.removeEventListener('resize', this.debouncedResize, false)
}

resize = () => {
Expand Down

1 comment on commit d68b1c1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"⚡️ Lighthouse report for the changes in this commit:

🟢 Performance: 91
🟢 Accessibility: 96
🟢 Best practices: 100
🟠 SEO: 67
🔴 PWA: 33

Lighthouse ran on https://lenis-i9zb0q6rl-studio-freight.vercel.app/"

Please sign in to comment.