Skip to content

Commit 177e557

Browse files
committed
revert to default simplifiedElementCheck: false to prevent class removal issues.
1 parent f6e06ab commit 177e557

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

browser/diffDOM.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser/diffDOM.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/diffDOM/helpers.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ export function checkElementType(
4343

4444
// Simplified check for primitive virtual DOMs without ownerDocument
4545
if (simplifiedCheck) {
46-
return elementTypeNames.some((elementTypeName) => {
46+
const simplifiedResult = elementTypeNames.some((elementTypeName) => {
4747
// Special case for basic element types
4848
if (elementTypeName === "Element") {
49+
// Enhanced check that handles both virtual DOM objects and real DOM elements
4950
return (
5051
element.nodeType === 1 ||
5152
(typeof element.nodeName === "string" &&
5253
element.nodeName !== "#text" &&
53-
element.nodeName !== "#comment")
54+
element.nodeName !== "#comment") ||
55+
// Additional check for real DOM elements that might not have nodeType
56+
(element.tagName && typeof element.tagName === "string") ||
57+
// Check if it has DOM element-like properties (fallback)
58+
(element.setAttribute && typeof element.setAttribute === "function")
5459
)
5560
}
5661
if (elementTypeName === "Text") {
@@ -60,20 +65,40 @@ export function checkElementType(
6065
return element.nodeType === 8 || element.nodeName === "#comment"
6166
}
6267

63-
// For HTML element types, check nodeName
68+
// For HTML element types, check nodeName or tagName
6469
if (
6570
elementTypeName.startsWith("HTML") &&
6671
elementTypeName.endsWith("Element")
6772
) {
6873
const tagName = elementTypeName.slice(4, -7).toLowerCase()
6974
return (
70-
element.nodeName &&
71-
element.nodeName.toLowerCase() === tagName
75+
(element.nodeName &&
76+
element.nodeName.toLowerCase() === tagName) ||
77+
(element.tagName &&
78+
element.tagName.toLowerCase() === tagName)
7279
)
7380
}
7481

7582
return false
7683
})
84+
85+
// If simplified check succeeds, return true
86+
if (simplifiedResult) {
87+
return true
88+
}
89+
90+
// Fallback to DOM-based check if simplified check fails and element has ownerDocument
91+
if (element.ownerDocument) {
92+
return elementTypeNames.some(
93+
(elementTypeName) =>
94+
typeof element?.ownerDocument?.defaultView?.[elementTypeName] ===
95+
"function" &&
96+
element instanceof
97+
element.ownerDocument.defaultView[elementTypeName],
98+
)
99+
}
100+
101+
return false
77102
}
78103

79104
// DOM-based check
@@ -86,4 +111,4 @@ export function checkElementType(
86111
element instanceof
87112
element.ownerDocument.defaultView[elementTypeName],
88113
)
89-
}
114+
}

src/diffDOM/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const DEFAULT_OPTIONS = {
1818
maxDepth: false, // False or a numeral. If set to a numeral, limits the level of depth that the the diff mechanism looks for differences. If false, goes through the entire tree.
1919
maxChildCount: 50, // False or a numeral. If set to a numeral, only does a simplified form of diffing of contents so that the number of diffs cannot be higher than the number of child nodes.
2020
valueDiffing: true, // Whether to take into consideration the values of forms that differ from auto assigned values (when a user fills out a form).
21-
simplifiedElementCheck: true, // Whether to use simplified element type checking for primitive virtual DOMs without ownerDocument
21+
simplifiedElementCheck: false, // Whether to use simplified element type checking for primitive virtual DOMs without ownerDocument
2222
// syntax: textDiff: function (node, currentValue, expectedValue, newValue)
2323
textDiff(
2424
node: textNodeType,

0 commit comments

Comments
 (0)