mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-21 20:24:42 +00:00
Expand rel's that trigger a link's onload
Was only "stylesheet", not also includes "preload" and "modulepreload"
This commit is contained in:
@@ -84,3 +84,24 @@
|
|||||||
testing.eventually(() => testing.expectEqual(true, result));
|
testing.eventually(() => testing.expectEqual(true, result));
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id="refs">
|
||||||
|
{
|
||||||
|
const rels = ['stylesheet', 'preload', 'modulepreload'];
|
||||||
|
const results = rels.map(() => false);
|
||||||
|
rels.forEach((rel, i) => {
|
||||||
|
let link = document.createElement('link')
|
||||||
|
link.rel = rel;
|
||||||
|
link.href = '/nope';
|
||||||
|
link.onload = () => results[i] = true;
|
||||||
|
document.documentElement.appendChild(link);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
testing.eventually(() => {
|
||||||
|
results.forEach((r) => {
|
||||||
|
testing.expectEqual(true, r);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|||||||
@@ -93,13 +93,21 @@ pub fn linkAddedCallback(self: *Link, page: *Page) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const element = self.asElement();
|
const element = self.asElement();
|
||||||
// Exit if rel not set.
|
|
||||||
const rel = element.getAttributeSafe(comptime .wrap("rel")) orelse return;
|
const rel = element.getAttributeSafe(comptime .wrap("rel")) orelse return;
|
||||||
// Exit if rel is not stylesheet.
|
const loadable_rels = std.StaticStringMap(void).initComptime(.{
|
||||||
if (!std.mem.eql(u8, rel, "stylesheet")) return;
|
.{ "stylesheet", {} },
|
||||||
// Exit if href not set.
|
.{ "preload", {} },
|
||||||
|
.{ "modulepreload", {} },
|
||||||
|
});
|
||||||
|
if (loadable_rels.has(rel) == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const href = element.getAttributeSafe(comptime .wrap("href")) orelse return;
|
const href = element.getAttributeSafe(comptime .wrap("href")) orelse return;
|
||||||
if (href.len == 0) return;
|
if (href.len == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try page._to_load.append(page.arena, self._proto);
|
try page._to_load.append(page.arena, self._proto);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user