Skip to content

Commit de83521

Browse files
committed
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.
1 parent 99f8fe1 commit de83521

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/browser/ScriptManager.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ pub fn getAsyncModule(self: *ScriptManager, url: [:0]const u8, cb: AsyncModule.C
384384
pub fn staticScriptsDone(self: *ScriptManager) void {
385385
std.debug.assert(self.static_scripts_done == false);
386386
self.static_scripts_done = true;
387+
self.evaluate();
387388
}
388389

389390
// try to evaluate completed scripts (in order). This is called whenever a script
@@ -450,6 +451,12 @@ pub fn isDone(self: *const ScriptManager) bool {
450451
self.deferreds.first == null; // and there are no more <script defer src=> to wait for
451452
}
452453

454+
fn asyncScriptIsDone(self: *ScriptManager) void {
455+
if (self.isDone()) {
456+
self.page.documentIsComplete();
457+
}
458+
}
459+
453460
fn startCallback(transfer: *Http.Transfer) !void {
454461
const script: *PendingScript = @ptrCast(@alignCast(transfer.ctx));
455462
script.startCallback(transfer) catch |err| {
@@ -597,6 +604,7 @@ pub const PendingScript = struct {
597604
// async script can be evaluated immediately
598605
defer self.deinit();
599606
self.script.eval(manager.page);
607+
manager.asyncScriptIsDone();
600608
}
601609

602610
fn errorCallback(self: *PendingScript, err: anyerror) void {

0 commit comments

Comments
 (0)