From 2fd2be0e515a46901af9fa091e3d78f8d489cdf1 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 20 May 2026 10:31:28 +0800 Subject: [PATCH] Small largely stylistic tweaks Trim down a lot of the comments. Inline remarks in some cases rather than a large function header. Removing the `errdefer headers.deinit();` is unfortunate but currently necessary to avoid a potential double-free if the request gets far enough that http_client frees it and still returns an error. This is a known issue that needs to be fixed separately and that impacts multiple call-sites. My "fix" introduces a possible (very small) memory leak versus a possible crash. --- src/browser/Frame.zig | 89 +++++++++++------------- src/browser/webapi/element/html/Link.zig | 6 +- src/help.zon | 6 +- 3 files changed, 44 insertions(+), 57 deletions(-) diff --git a/src/browser/Frame.zig b/src/browser/Frame.zig index 39b21e6a..f037dfb4 100644 --- a/src/browser/Frame.zig +++ b/src/browser/Frame.zig @@ -1687,47 +1687,41 @@ pub fn queueLoad(self: *Frame, html: *Element.Html) !void { // splitting by route anyway). const MAX_STYLESHEET_BYTES: usize = 2 * 1024 * 1024; -// Synchronously fetch and parse an external ``. Opt-in -// behind `session.load_external_stylesheets` — scrapers/crawlers that don't -// need accurate visibility checks still get the cheap no-fetch path via -// `Link.linkAddedCallback`. Mirrors `ScriptManager.addFromElement`'s use of -// `syncRequest`: stylesheets are render-blocking in real browsers, so a -// synchronous fetch from inside the parser callback matches expected -// document-load ordering without manual `_pending_loads` bookkeeping. -pub fn loadExternalStylesheet(self: *Frame, link: *Element.Html.Link) !void { - if (self.isGoingAway()) return; +// Synchronously fetch and parse an external ``. +// href is passed in as an optimization since the [currently] only callsite has +// it, so why look it up again? +pub fn loadExternalStylesheet(self: *Frame, link: *Element.Html.Link, href: []const u8) !void { + if (self.isGoingAway() or href.len == 0) { + return; + } - // Fragment-parsed links (innerHTML / outerHTML / DOMParser / - // Range.createContextualFragment /