Reset scratch class cache when new stylesheets are added to <head>

For example, when scratch-paint loads lazily
This commit is contained in:
Thomas Weber committed 2021-04-10 01:37:55 -05:00
1 parent 54a6ff771b
commit 4f38dc92d9
1 file changed
+14
+14
View File
@@ -64,6 +64,20 @@ const getScratchClassNames = () => {
.filter(e => e)
.flat();
_scratchClassNames = [...new Set(classes)];
const observer = new MutationObserver(mutationList => {
for (const mutation of mutationList) {
for (const node of mutation.addedNodes) {
if (node.tagName === 'STYLE') {
_scratchClassNames = null;
observer.disconnect();
return;
}
}
}
});
observer.observe(document.head, {
childList: true
});
return _scratchClassNames;
};