From 38b008976dd0da9f847d66f39840aee7d3d3c266 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Mon, 6 Jul 2026 18:18:46 +0800 Subject: [PATCH] fix, render: CSS getPropertyValue special width/height handling When CSSStyleDeclaration.getPropertyValue is called for width or height, and the inline style isn't found, return the elements actual width/height. Without this we return "" which is wrong and can cause script error/hangs. --- .../webapi/css/CSSStyleDeclaration.zig | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/browser/webapi/css/CSSStyleDeclaration.zig b/src/browser/webapi/css/CSSStyleDeclaration.zig index c0f2f7f49..5a6c0b9d8 100644 --- a/src/browser/webapi/css/CSSStyleDeclaration.zig +++ b/src/browser/webapi/css/CSSStyleDeclaration.zig @@ -99,7 +99,20 @@ pub fn getPropertyValue(self: *const CSSStyleDeclaration, property_name: []const if (self._element) |element| { // Resolve inline `style=` declarations through the element's // parsed inline style, so computed values match `el.style`. - if (frame._style_manager.inlineStyleValue(element, wrapped)) |value| return value; + if (frame._style_manager.inlineStyleValue(element, wrapped)) |value| { + return value; + } + + // Computed width/height must agree with the synthetic layout + // metrics (offsetWidth/getBoundingClientRect). Returning "" + // makes measurement code see contradictory sizes — jQuery's + // "shrink text until it fits" loops then never terminate. + if (wrapped.eql(comptime .wrap("width"))) { + return resolvedDimension(element, .width, frame); + } + if (wrapped.eql(comptime .wrap("height"))) { + return resolvedDimension(element, .height, frame); + } } return getDefaultPropertyValue(self, wrapped); } @@ -108,6 +121,18 @@ pub fn getPropertyValue(self: *const CSSStyleDeclaration, property_name: []const return prop._value.str(); } +fn resolvedDimension(element: *Element, dimension: enum { width, height }, frame: *Frame) []const u8 { + if (!element.checkVisibilityCached(null, frame)) { + return "auto"; + } + const dims = element.getElementDimensions(frame); + const value = switch (dimension) { + .width => dims.width, + .height => dims.height, + }; + return std.fmt.allocPrint(frame.local_arena, "{d}px", .{value}) catch "auto"; +} + pub fn getPropertyPriority(self: *const CSSStyleDeclaration, property_name: []const u8, frame: *Frame) []const u8 { const normalized = normalizePropertyName(property_name, &frame.buf); const prop = self.findProperty(.wrap(normalized)) orelse return "";