From 1b8813b54f54f407e9198e2b2fa1fa4b22584118 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 24 Nov 2026 15:11:24 +0530 Subject: [PATCH 1/2] fix: render block charts inside the editor iframe --- classes/Visualizer/D3Renderer/src/index.js | 20 ++-- .../tests/container-document.test.js | 92 +++++++++++++++++++ .../Gutenberg/src/Components/ChartRender.js | 11 ++- .../Gutenberg/src/Components/ChartSelect.js | 15 ++- .../Gutenberg/src/Components/Charts.js | 11 ++- .../Gutenberg/src/Components/DataTable.js | 12 ++- .../Gutenberg/src/Components/GoogleChart.js | 46 ++++++++++ tests/e2e/specs/gutenberg-editor.spec.js | 37 +++++++- 8 files changed, 220 insertions(+), 24 deletions(-) create mode 100644 classes/Visualizer/D3Renderer/tests/container-document.test.js create mode 100644 classes/Visualizer/Gutenberg/src/Components/GoogleChart.js diff --git a/classes/Visualizer/D3Renderer/src/index.js b/classes/Visualizer/D3Renderer/src/index.js index 56feb4728..6cba2190c 100644 --- a/classes/Visualizer/D3Renderer/src/index.js +++ b/classes/Visualizer/D3Renderer/src/index.js @@ -45,13 +45,17 @@ function downloadDataUrl( dataUrl, name ) { /** * Render a single D3 chart into its container element via a sandboxed iframe. * - * @param {string} id - DOM element ID of the container - * @param {object} chart - chart entry from visualizer.charts + * @param {string} id - DOM element ID of the container + * @param {object} chart - chart entry from visualizer.charts + * @param {?HTMLElement} [element] - container element, needed when it lives in another document such as the editor iframe */ -function renderD3Chart( id, chart ) { - const container = document.getElementById( id ); +function renderD3Chart( id, chart, element ) { + const container = element || document.getElementById( id ); if ( ! container ) return; + // The sandbox posts to its parent window, which is the container's window. + const containerWindow = container.ownerDocument.defaultView; + const code = typeof chart.code === 'string' ? chart.code : null; if ( ! code ) { @@ -83,7 +87,7 @@ function renderD3Chart( id, chart ) { '
' + '