Skip to content

Commit

Permalink
Clean up as much as possible from the previous update call when calli…
Browse files Browse the repository at this point in the history
…ng update again.
  • Loading branch information
flackr committed Aug 1, 2024
1 parent 6d598f9 commit a7336ab
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion polyfill/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function eventTarget(scroller) {
let markerSelectors = new Set();
let markerVars = new Set();
let flowSelectors = new Set();
const skipGroups = new Set();
let skipGroups = new Set();

function handleScroll() {
const scrollerElement = this == window ? document.documentElement : this;
Expand Down Expand Up @@ -464,6 +464,17 @@ function addPseudoMarker(elem, usedProps) {
}

function update() {
// Cleans up the global state associated with the previous update and injected stylesheets.
// Note that the DOM changes are not cleaned up so this will only work if you have replaced all of the modified DOM.
markerSelectors = new Set();
markerVars = new Set();
flowSelectors = new Set();
skipGroups = new Set();
let removeStyles = document.querySelectorAll('style[polyfill-generated]');
for (let sheet of removeStyles) {
sheet.remove();
}

let generated = document.createElement('style');
generated.setAttribute('polyfill-generated', 'true');
let stylesheets = document.querySelectorAll('style:not([polyfill-generated])');
Expand Down

0 comments on commit a7336ab

Please sign in to comment.