-
-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Labels
Description
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch [email protected] for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/beasties/dist/index.cjs b/node_modules/beasties/dist/index.cjs
index 4c3cbe2..2a16283 100644
--- a/node_modules/beasties/dist/index.cjs
+++ b/node_modules/beasties/dist/index.cjs
@@ -211,13 +211,15 @@ function createDocument(html) {
const document = htmlparser2.parseDocument(html, { decodeEntities: false });
extendDocument(document);
extendElement(domhandler.Element.prototype);
let beastiesContainer = document.querySelector("[data-beasties-container]");
+ if(typeof document !== 'undefined' && document.documentElement && typeof document.documentElement.setAttribute === 'function'){
if (!beastiesContainer) {
document.documentElement?.setAttribute("data-beasties-container", "");
beastiesContainer = document.documentElement || document;
}
+ }
document.beastiesContainer = beastiesContainer;
buildCache(beastiesContainer);
return document;
}
@@ -190,21 +190,23 @@ function buildCache(container) {
classCache = /* @__PURE__ */ new Set();
idCache = /* @__PURE__ */ new Set();
const queue = [container];
while (queue.length) {
const node = queue.shift();
+ if (node) {//Add additional null check for node before accessing
if (node.hasAttribute?.("class")) {
const classList = node.getAttribute("class").trim().split(" ");
classList.forEach((cls) => {
classCache.add(cls);
});
}
if (node.hasAttribute?.("id")) {
const id = node.getAttribute("id").trim();
idCache.add(id);
}
if ("children" in node) {
queue.push(...node.children.filter((child) => child.type === "tag"));
}
+ }
}
}
<em>This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).</em>danielroe