From b3da7c29e95ab148ba620194241f880763182fb2 Mon Sep 17 00:00:00 2001 From: Jean Date: Sat, 4 Jul 2026 06:06:51 +0000 Subject: [PATCH] sandbox: measure a wrapper sizer so a plugin restyling its root can't collapse the frame --- public/plugin-sandbox.html | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/public/plugin-sandbox.html b/public/plugin-sandbox.html index fe89d75..e934369 100644 --- a/public/plugin-sandbox.html +++ b/public/plugin-sandbox.html @@ -76,14 +76,22 @@ // Populate this iframe's own DOM, then claim a UI slot in the app shell. // Height is reported back so the host can size the frame to the content. ui: function (slot, build) { - try { build(document.body); } catch (e) { rpc('log', 'ui build threw: ' + e); } + // Outer sizer stays inline-block so it shrink-wraps to content; the plugin + // only gets `inner` and may style it freely (even display:flex) without + // breaking measurement. + var outer = document.createElement('div'); + outer.style.cssText = 'display:inline-block'; + var inner = document.createElement('div'); + outer.appendChild(inner); + document.body.appendChild(outer); + try { build(inner); } catch (e) { rpc('log', 'ui build threw: ' + e); } rpc('ui.claim', slot); var report = function () { - var r = document.body.getBoundingClientRect(); + var r = outer.getBoundingClientRect(); rpc('ui.resize', Math.ceil(r.width), Math.ceil(r.height)); }; report(); - if (window.ResizeObserver) new ResizeObserver(report).observe(document.body); + if (window.ResizeObserver) new ResizeObserver(report).observe(outer); }, }; }