Skip to content

Commit

Permalink
bug fix for "ResizeObserver loop completed with undelivered notificat…
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholeuf committed Dec 16, 2023
1 parent a192ade commit ec75dd8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions course-react-ts-portfolio/jbook/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ReactDOM from 'react-dom';
import CodeCell from './components/code-cell';
import './resize-observer-bug-fix';

const App = () => {
return (
Expand Down
24 changes: 24 additions & 0 deletions course-react-ts-portfolio/jbook/src/resize-observer-bug-fix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Taken from https://github.com/vuejs/vue-cli/issues/7431#issuecomment-1793385162

// Stop error resizeObserver
const debounce = (callback: (...args: any[]) => void, delay: number) => {
let tid: any;
return function (...args: any[]) {
// eslint-disable-next-line no-restricted-globals
const ctx = self;
tid && clearTimeout(tid);
tid = setTimeout(() => {
callback.apply(ctx, args);
}, delay);
};
};

const _ = (window as any).ResizeObserver;
(window as any).ResizeObserver = class ResizeObserver extends _ {
constructor(callback: (...args: any[]) => void) {
callback = debounce(callback, 20);
super(callback);
}
};

export {};

0 comments on commit ec75dd8

Please sign in to comment.