properly add lengthComputable flag to XHR sync path

This commit is contained in:
Muki Kiboigo committed 2026-08-25 17:43:04 -07:00
1 parent 8bd0febda6
commit 68af3a264d
3 files changed
+9 -3

No files matched your search

@@ -62,6 +62,7 @@ fn initWithTrusted(arena: *lp.Arena, typ: String, _opts: ?Options, trusted: bool
._proto = undefined,
._total = opts.total,
._loaded = opts.loaded,
._length_computable = opts.lengthComputable,
},
);
+2 -2
View File
@@ -348,8 +348,8 @@ pub fn send(self: *XMLHttpRequest, body_: ?BodyInit, exec_: *const Execution) !v
try self.stateChanged(.done, exec);
const loaded = self._response_data.items.len;
try self._proto.dispatch(.load, .{ .total = loaded, .loaded = loaded }, exec);
try self._proto.dispatch(.load_end, .{ .total = loaded, .loaded = loaded }, exec);
try self._proto.dispatch(.load, .{ .total = loaded, .loaded = loaded, .length_computable = true }, exec);
try self._proto.dispatch(.load_end, .{ .total = loaded, .loaded = loaded, .length_computable = true }, exec);
log.info(.http, "request complete", .{
.source = "xhr",
@@ -74,7 +74,11 @@ pub fn dispatch(self: *XMLHttpRequestEventTarget, comptime event_type: DispatchT
const progress = progress_ orelse Progress{};
const event = (try ProgressEvent.initTrusted(
comptime .wrap(typ),
.{ .total = progress.total, .loaded = progress.loaded },
.{
.total = progress.total,
.loaded = progress.loaded,
.lengthComputable = progress.length_computable,
},
exec.page,
)).asEvent();
@@ -173,6 +177,7 @@ const DispatchType = enum {
const Progress = struct {
loaded: usize = 0,
total: usize = 0,
length_computable: bool = false,
};
pub const JsApi = struct {