Skip to content

Lightpanda: the headless browser designed for AI and automation

webapi: enable [CEReactions] for `Element.style`

Halil Durak12a1c1d1889d
diff --git a/src/browser/tests/custom_elements/attribute_changed.html b/src/browser/tests/custom_elements/attribute_changed.html
index 2840e9157..d5f37886f 100644
--- a/src/browser/tests/custom_elements/attribute_changed.html
+++ b/src/browser/tests/custom_elements/attribute_changed.html
@@ -198,6 +198,41 @@
el.style.removeProperty('width');
testing.expectEqual(5, calls.length);
testing.expectEqual(el.getAttribute('style'), calls[4]);
+
+ // Element.style is [PutForwards=cssText]
+ el.style = 'color: green;';
+ testing.expectEqual(6, calls.length);
+ testing.expectEqual('color: green;', calls[5]);
+}
+
+{
+ // Polymer reflects an attribute change back through `this.style = value`.
+ // Delivered late, each callback carried a stale value and the element
+ // ping-ponged between two styles forever.
+ let count = 0;
+
+ class StyleReflector extends HTMLElement {
+ static get observedAttributes() {
+ return ['style'];
+ }
+
+ attributeChangedCallback(name, oldValue, newValue) {
+ if (++count > 50) {
+ return;
+ }
+ if (oldValue !== newValue) {
+ this.style = newValue;
+ }
+ }
+ }
+
+ customElements.define('style-reflector', StyleReflector);
+ const el = document.createElement('style-reflector');
+ el.setAttribute('style', 'transform: rotate(180deg);');
+ el.style.opacity = '0.3';
+
+ testing.expectEqual(4, count);
+ testing.expectEqual('transform: rotate(180deg); opacity: 0.3;', el.getAttribute('style'));
}
</script>
diff --git a/src/browser/webapi/Element.zig b/src/browser/webapi/Element.zig
index 6d67021e0..5f61912da 100644
--- a/src/browser/webapi/Element.zig
+++ b/src/browser/webapi/Element.zig
@@ -3089,7 +3089,7 @@ pub const JsApi = struct {
pub const classList = bridge.accessor(Element.getClassList, Element.setClassList, .{ .ce_reactions = true });
pub const part = bridge.accessor(Element.getPartList, Element.setPartList, .{ .ce_reactions = true });
pub const dataset = bridge.accessor(Element.getDataset, null, .{});
- pub const style = bridge.accessor(Element.getOrCreateStyle, Element.setStyle, .{});
+ pub const style = bridge.accessor(Element.getOrCreateStyle, Element.setStyle, .{ .ce_reactions = true });
pub const attributes = bridge.accessor(Element.getAttributeNamedNodeMap, null, .{});
pub const hasAttribute = bridge.function(Element.hasAttribute, .{});
pub const hasAttributeNS = bridge.function(Element.hasAttributeNS, .{});