Reset scratch class cache when new stylesheets are added to <head>
For example, when scratch-paint loads lazily
This commit is contained in:
1 file changed
+14
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user