From ec9a2d815519d23154677f3b385c1a4d86111043 Mon Sep 17 00:00:00 2001 From: egrs Date: Sun, 8 Mar 2026 15:44:07 +0100 Subject: [PATCH] execute dynamically inserted inline script elements Scripts created via createElement('script') with inline content (textContent, text, or innerHTML) and inserted into the DOM now execute per the HTML spec. Previously all dynamically inserted scripts without a src attribute were skipped, breaking most JS framework hydration patterns. --- src/browser/Page.zig | 9 ++-- .../element/html/script/dynamic_inline.html | 54 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 src/browser/tests/element/html/script/dynamic_inline.html diff --git a/src/browser/Page.zig b/src/browser/Page.zig index dedb2a6e..8a98aaa0 100644 --- a/src/browser/Page.zig +++ b/src/browser/Page.zig @@ -2908,9 +2908,12 @@ fn nodeIsReady(self: *Page, comptime from_parser: bool, node: *Node) !void { } if (node.is(Element.Html.Script)) |script| { if ((comptime from_parser == false) and script._src.len == 0) { - // script was added via JavaScript, but without a src, don't try - // to execute it (we'll execute it if/when the src is set) - return; + // Script was added via JavaScript without a src attribute. + // Only skip if it has no inline content either — scripts with + // textContent/text should still execute per spec. + if (script.asConstElement().asConstNode().firstChild() == null) { + return; + } } self.scriptAddedCallback(from_parser, script) catch |err| { diff --git a/src/browser/tests/element/html/script/dynamic_inline.html b/src/browser/tests/element/html/script/dynamic_inline.html new file mode 100644 index 00000000..d5cb60f2 --- /dev/null +++ b/src/browser/tests/element/html/script/dynamic_inline.html @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + +