From 8eeb34dba8a8d78bdfa2f06ff1294c6869d2437b Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Tue, 10 Mar 2026 13:42:54 +0800 Subject: [PATCH] Node matching using tag name string comparison on non-HTML nodes NodeLive (used by, e.g. getElementsByTagName) needs to revert to the non- optimized string-comparison for non-HTML tags. This should help fix https://github.com/lightpanda-io/browser/issues/1214 --- src/browser/tests/domparser.html | 22 ++++++++++++++++++++ src/browser/webapi/collections/node_live.zig | 9 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/browser/tests/domparser.html b/src/browser/tests/domparser.html index 24d34e89..7930ec87 100644 --- a/src/browser/tests/domparser.html +++ b/src/browser/tests/domparser.html @@ -397,3 +397,25 @@ } } + + diff --git a/src/browser/webapi/collections/node_live.zig b/src/browser/webapi/collections/node_live.zig index 65fdfbf7..a55420e7 100644 --- a/src/browser/webapi/collections/node_live.zig +++ b/src/browser/webapi/collections/node_live.zig @@ -219,7 +219,14 @@ pub fn NodeLive(comptime mode: Mode) type { switch (mode) { .tag => { const el = node.is(Element) orelse return false; - return el.getTag() == self._filter; + // For HTML namespace elements, we can use the optimized tag comparison. + // For other namespaces (XML, SVG custom elements, etc.), fall back to string comparison. + if (el._namespace == .html) { + return el.getTag() == self._filter; + } + // For non-HTML elements, compare by tag name string + const element_tag = el.getTagNameLower(); + return std.mem.eql(u8, element_tag, @tagName(self._filter)); }, .tag_name => { // If we're in `tag_name` mode, then the tag_name isn't