From fdb87e34df0eeaae21ee5f442ff99a962d334324 Mon Sep 17 00:00:00 2001 From: Tomas Hubelbauer Date: Sun, 13 Oct 2024 14:01:33 +0200 Subject: [PATCH] Do not loop in `onEndTag` as it does multiple calls itself My loop was skipping ahead and the subsequent calls to `onEndTag` were breaking the state. --- index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.ts b/index.ts index 592f558..570796f 100644 --- a/index.ts +++ b/index.ts @@ -168,16 +168,14 @@ export default class DOMParser { element.onEndTag((tag) => { // Handle an unclosed element being followed by a closing tag for another element - // Keep closing the element chain as void elements until we find the matching tag - while (document.activeElement?.parentElement && tag.name !== document.activeElement.tagName) { + if (document.activeElement?.parentElement && tag.name !== document.activeElement.tagName) { // Mark as void only if there are no children, otherwise it is a // case of an element with no closing tag closed by another // element's opening tag via `autoClosingTags` document.activeElement.isVoid = document.activeElement.children.length === 0; - document.activeElement = document.activeElement.parentElement; } - document.activeElement = document.activeElement.parentElement; + document.activeElement = document.activeElement?.parentElement; }); }, comments(comment) {