dispatch a load event when href set for Link element

Also add `lazy-href-set` test.
This commit is contained in:
Halil Durak
2026-02-25 16:10:00 +03:00
parent bc6be22cb4
commit 3f94fd90dd
2 changed files with 21 additions and 1 deletions

View File

@@ -69,3 +69,18 @@
testing.eventually(() => testing.expectEqual(false, fired));
}
</script>
<script id="lazy-href-set">
{
let result = false;
const link = document.createElement("link");
link.rel = "stylesheet";
link.onload = () => result = true;
// Append to DOM,
document.head.appendChild(link);
// then set href.
link.href = 'https://lightpanda.io/opensource-browser/15';
testing.eventually(() => testing.expectEqual(true, result));
}
</script>

View File

@@ -50,7 +50,12 @@ pub fn getHref(self: *Link, page: *Page) ![]const u8 {
}
pub fn setHref(self: *Link, value: []const u8, page: *Page) !void {
try self.asElement().setAttributeSafe(comptime .wrap("href"), .wrap(value), page);
const element = self.asElement();
try element.setAttributeSafe(comptime .wrap("href"), .wrap(value), page);
if (element.asNode().isConnected()) {
try page.linkAddedCallback(self);
}
}
pub fn getRel(self: *Link) []const u8 {