Skip to content

Commit

Permalink
fix leak by releasing ref to observed element
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeAstapov committed Nov 10, 2022
1 parent fe89c8c commit f1b3f14
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface IOptions {
}

type StateForRoot = {
elements: [HTMLElement];
elements: HTMLElement[];
options: IOptions;
intersectionObserver: any;
};
Expand Down Expand Up @@ -61,6 +61,11 @@ export default class IntersectionObserverAdmin extends Notifications {
if (matchingRootEntry) {
const { intersectionObserver } = matchingRootEntry;
intersectionObserver.unobserve(target);

const elIndex = matchingRootEntry.elements.indexOf(target);
if (elIndex !== -1) {
matchingRootEntry.elements.splice(elIndex, 1);
}
}
}

Expand Down

0 comments on commit f1b3f14

Please sign in to comment.