Fire page lifecycle events when all scripts are either inline or async

This is how, for example, scripts on lightpanda.io are. Though fixing this
doesn't really change anything, it's good to make sure these events are firing
correctly.
This commit is contained in:
Karl Seguin
2025-10-13 21:53:58 +08:00
parent 99f8fe1592
commit de83521e08

View File

@@ -384,6 +384,7 @@ pub fn getAsyncModule(self: *ScriptManager, url: [:0]const u8, cb: AsyncModule.C
pub fn staticScriptsDone(self: *ScriptManager) void {
std.debug.assert(self.static_scripts_done == false);
self.static_scripts_done = true;
self.evaluate();
}
// try to evaluate completed scripts (in order). This is called whenever a script
@@ -450,6 +451,12 @@ pub fn isDone(self: *const ScriptManager) bool {
self.deferreds.first == null; // and there are no more <script defer src=> to wait for
}
fn asyncScriptIsDone(self: *ScriptManager) void {
if (self.isDone()) {
self.page.documentIsComplete();
}
}
fn startCallback(transfer: *Http.Transfer) !void {
const script: *PendingScript = @ptrCast(@alignCast(transfer.ctx));
script.startCallback(transfer) catch |err| {
@@ -597,6 +604,7 @@ pub const PendingScript = struct {
// async script can be evaluated immediately
defer self.deinit();
self.script.eval(manager.page);
manager.asyncScriptIsDone();
}
fn errorCallback(self: *PendingScript, err: anyerror) void {