Repository navigation
Render the AI builder preview in the sandboxed frame - #1427
vytisbulkevicius wants to merge 37 commits into
Conversation
The builder preview and its code check now use the same sandboxed frame as the front end and the block editor. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
… checks Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The sandboxed preview works on the library page, but the block editor builder cannot render, and a save check can restore old data.
Validation details
- Files reviewed: 4/4 changed files.
- The new Playwright case passed at HEAD
cd /workspace/head && sandbox-doctor.sh --plugin visualizer 2>&1 | grep -vE '^\s*$' | tail -8; export WP_BASE_URL=http:/…(run R9, exit 0) and failed with pr-base codecd /var/www/html && ln -sfn /workspace/base wp-content/plugins/visualizer && wp plugin deactivate visualizer >/dev/null …(run R10, exit 0). - Block editor
vizAIBuilderlacksiframeJsUrl, and the builder showed the renderer errorcat > /workspace/checks/C12/open.js <<'EOF' const { chromium } = require( 'playwright' ); const fs = require( 'fs' ); co…(run R13, exit 0). - Every other place that runs saved D3 code uses the sandboxed renderer frame.
- The source check, the
#chartcontainer and the ready message of the frame match the builder.
Untested areas
- Pro plugin hooks that receive chart code were not checked. Their source is not available.
- The PHPUnit and Jest suites were not run.
- The block Edit control was not clicked. The run called the function the control calls.
- The variant pass did not settle these places, where the fixed cause may still reach:
classes/Visualizer/Module/Chart.php:82-92,426-437,876-884,978-982,1541-1567— unverified: Whole chart records containing code reach Pro sidebar/resource hooks and the legacy Pro resource loader. Pro implementation and version are unavailable; whether those consumers exe…
🤖 Automated review · run code-review-agent_6b0b41f36e9e62.82123300.
🤖 Review agent — review posted ✅ on a9411487 · changes requested · 3 findings · 21 min
Run code-review-agent_6b0b41f36e9e62.82123300 · trail
…rseded code checks The block editor localized vizAIBuilder without iframeJsUrl, so the builder opened from a Visualizer block could not render or save code. New data now drops a pending code save check, and a saved code drops a pending data check. Adds E2E cases for the block editor preview, the error the chart code throws and both superseded checks.
…ript A generated or fixed chart now drops a pending data check of the code it replaces, and the data a generated chart brings is checked with the generated code. The address of the sandboxed frame script carries the plugin version, so a browser does not answer the builder with the script of an older version that never reports its render result.
…a with repaired code Data that comes with a generated chart goes to the preview without a hidden check, so a generated chart that fails is reported there and repaired. When a repair replaces the chart code, data whose check was pending is checked again with the repaired code. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…epaired code The preview reports a failure of the repaired code with that data, so the error and the Fix control stay. The repair test waits for both jobs. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The three earlier findings are fixed, but data that reaches the builder during a repair or a generation can still miss the preview.
Validation details
- Files reviewed: 8/8 changed files.
- The repair order where the data check fails first was reproduced in the sandbox at
068cfa1:cd /workspace/checks/C7 && python3 - <<'EOF' import re p='specs/c7-order.spec.js' s=open(p).read() old="if ( body.includ…printedC7-A RESULT: preview=rows: 1 warning_shown=true(run R9). - The block editor case passed at HEAD
cd /workspace/checks/C7 && export WP_BASE_URL=http://localhost:8080 WP_USERNAME=admin WP_PASSWORD=admin STORAGE_STATE_PA…(run R14, exit 0). - Every page that loads the frame script uses the versioned address. No builder path runs chart code outside the sandbox.
Untested areas
- The new cases were not run with each fix reverted. At
pr-basethey fail because the sandbox preview is missing. - The output of the external chart generator was not captured.
- The block Edit control was not clicked. The PHPUnit suite was not run.
- Pro plugin hooks that receive chart code remain unchecked. Their source is not available.
🤖 Automated review · run code-review-agent_6b0f1e508a4217.85342430.
🤖 Review agent — review posted ✅ on 068cfa11 · changes requested · 3 findings · 30 min
Run code-review-agent_6b0f1e508a4217.85342430 · trail
…code Data whose check failed, or whose column headers changed, goes to the preview when a repair or a generation replaces the chart code. Data that a generated chart brings is shown with any column headers. The spec opens a saved chart through one helper. Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…at arrives during a generation Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The three earlier findings are fixed, but data that arrives during a generation can still miss the preview, and a late preview error can overwrite a generated chart.
classes/Visualizer/ChartBuilder/src/AIBuilder/DataSource.js:216-238—noteNot blocking: another place of the cause this PR fixes, in a file the PR does not change. Overlapping uploads apply in the order their responses arrive. When the user edits the CSV again while the first upload runs, two uploads are in flight. Nothing ties a response to the newest request beforeonDataReady(). When the older response arrives last,handleDataReady()gives it the newest check token, and it replaces the newer data. Invalidate a running upload whenever the input changes, also when the input returns to the last uploaded CSV. Apply only a response that matches the current input. Add a case toai-builder.spec.jsthat holds two uploads, releases them in reverse order, and expects the newer rows.
Validation details
- Files reviewed: 2/2 files changed since the prior review, and 8/8 files of the PR.
- The passed-check order during a generation was run in the sandbox at
91884d5:cd /workspace/checks/C2 && ln -sfn /workspace/head/node_modules node_modules && export WP_BASE_URL=http://localhost:8080…printedC2 RESULT preview=rows: 1(run R9). - The existing case for data that arrives during a generation passed
cd /workspace/checks/C2 && export WP_BASE_URL=http://localhost:8080 WP_USERNAME=admin WP_PASSWORD=admin STORAGE_STATE_PA…(run R10, exit 0). - A late preview error during a generation started a repair that replaced the generated code
cd /workspace/checks/C5 && python3 - <<'EOF' p='specs/ai-builder-c5.spec.js' s=open(p).read() s=s.replace("const BUSY_CO…(run R20, exit 0).
Untested areas
- The new cases were not run with each fix reverted.
- The late-error case ran only with the generation finishing first.
- The output of the external chart generator was mocked. The PHPUnit suite was not run.
- Pro plugin hooks that receive chart code remain unchecked. Their source is not available.
- The variant pass did not settle these places, where the fixed cause may still reach:
classes/Visualizer/Module/Chart.php:82-92,426-437,876-884,978-982,1541-1571— unverified: Whole records containing D3 code reach Pro sidebar/resource hooks. Pro implementation source is unavailable, so whether those consumers execute code or asynchronously apply stale c…
🤖 Automated review · run code-review-agent_6b0fb36b2fb680.63507608.
🤖 Review agent — review posted ✅ on 91884d51 · changes requested · 3 findings · 25 min
Run code-review-agent_6b0fb36b2fb680.63507608 · trail
…its render Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
|
Review note F10 (overlapping uploads in |
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The three earlier findings are fixed, but late responses can still undo user actions in the builder: an edit-mode load and a Publish response.
classes/Visualizer/ChartBuilder/src/AIBuilder/DataSource.js:216-238—noteNot blocking: another place of the cause this PR fixes, in a file the PR does not change. Overlapping CSV, file and URL uploads still apply in the order their responses arrive (lines 216-268). Nothing ties a response to the newest request beforeonDataReady(). An older response that arrives last gets the newest check token inhandleDataReady()and is stored inlatestDataRef(index.js:376-379). It replaces the newer rows. Give the uploads one shared request-generation guard, and apply only the response of the newest input. Add cases toai-builder.spec.jsthat hold two CSV, file or URL uploads, release them in reverse order, and expect the newer rows.classes/Visualizer/ChartBuilder/src/AIBuilder/index.js:252-287—correctnessActions taken before an existing chart finishes loading are undone by the load. Edit mode setschartIdbeforefetchChart()resolves, and Edit code and Generate stay enabled. When the user saves code in the editor first, the late load replaces it withexisting.code(lines 273-275). When the user generates first, the fallback at lines 479-481 uses the empty arrays captured at the click. The generated chart then shows without the loaded rows. Block editing and generating until the load completes. Add a case toai-builder.spec.jsthat holds the chart fetch, saves code or generates, releases the fetch, and expects the newer code and the loaded rows.classes/Visualizer/ChartBuilder/src/AIBuilder/index.js:570-582—correctnessA late Publish response marks the chart as published after the editor replaced its code.handleSave()sendscodefrom the click and then setsshortcodewithout a check (lines 575-576). Edit code stays enabled while publishing (line 927). The user can save new code before the response arrives. The shortcode then shows and Publish chart hides (line 1049), while the stored chart keeps the older code. Lock code changes while publishing, or show the shortcode only when the published code is still the current code. Add a case toai-builder.spec.jsthat holds the save request, saves new code, releases the request, and expects Publish to stay available.
Validation details
- Files reviewed: 8/8 changed files. Two PR files changed since the prior review. The other changed files came from the merged development branch.
- The fixes for the three earlier threads were confirmed from source. No Playwright or PHPUnit case was run.
- Every requirement in the PR body was checked against the source and met.
- The upload-order finding reuses the evidence of run code-review-agent_6b0fb36b2fb680.63507608, not rerun.
Untested areas
- The new cases were not run, with or without their fixes.
- The QA step for a library without an AI chart was not run.
- Pro plugin hooks that receive chart data remain unchecked. Their source is not available.
- The variant pass did not settle these places, where the fixed cause may still reach:
classes/Visualizer/Module/Chart.php:1223-1228— unverified: Pro table/excel handling delegates to visualizer_pro_handle_chart_data; its implementation is unavailable, so freshness behavior remains unknown.
🤖 Automated review · run code-review-agent_6b0fe471644f18.81741555.
🤖 Review agent — review posted ✅ on ca376315 · changes requested · 2 findings · 15 min
Run code-review-agent_6b0fe471644f18.81741555 · trail
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
|
Review of ca37631:
|
…is open Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
|
Review of 4da8b32:
Known and not changed: when the first preview error of a chart arrives during a Publish that then fails, no automatic repair starts and Fix is not offered until the code or the data changes. |
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The earlier findings are fixed, but late uploads, imports and requests that survive a close can still replace the newest chart data.
Validation details
- Files reviewed: 3/3 files changed since the prior review. The other 5 changed files are unchanged since then.
- The six new Playwright cases pass at HEAD in the sandbox site:
cd /workspace/head && set -o pipefail; WP_BASE_URL=http://localhost:8080 WP_USERNAME=admin WP_PASSWORD=admin timeout 900…printed6 passed (6.2m)(run R9). - Repair during Publish chart, overlapping uploads, the generation upload after a close and the generated CSV skip are fixed.
- The builder mounts in its own root without
StrictMode, so theopenRefcleanup does not run while it is open.
Untested areas
- The six cases also fail at pr-base and at
4da8b32. Most fail before their own assertion, so these runs do not show that each fix is needed. - The new findings were traced in the source only. No case was run for them.
- The unchanged PHP files and
iframe.jswere not read again in this run.
🤖 Automated review · run code-review-agent_6b103a8e593fc9.07916110.
🤖 Review agent — review posted ✅ on 74916fe9 · changes requested · 3 findings · 24 min
Run code-review-agent_6b103a8e593fc9.07916110 · trail
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The three earlier findings are fixed, but a reopened builder shows older rows, and Publish from a second tab can replace newer code.
Validation details
- Files reviewed: 4/4 files changed since the prior review. The other 6 changed files are unchanged since then.
- A held-upload reopen case ran in the sandbox site (WordPress 7.1.5, PHP 8.3.37):
cd /workspace/checks/R1 && rm -rf test-results/*; set -o pipefail; NODE_PATH=/workspace/head/node_modules WP_BASE_URL=ht…printed1 passed(run R8). The reopened preview keptrows: 1, and a reload showedrows: 2. - A reopen after a finished upload ran too: `set -e; cd /workspace/checks/R1; F=specs/ai-builder.spec.js; head -n -1 $F > specs/tmp.js; cat >> specs/tmp.js <<'EOF'
…printed1 passed(run R10). The reopened preview showedrows: 1`.
- Run R9 of code-review-agent_6b103a8e593fc9.07916110 passed six cases at
74916fe. It was not rerun.
Untested areas
- The new cases of this round were not run. Their fixes were checked in the source.
- The two-tab Publish race was traced in the source only.
iframe.jsand the PHP files were not read again. They are unchanged since the prior review.
🤖 Automated review · run code-review-agent_6b1049a5db0575.02480147.
🤖 Review agent — review posted ✅ on 53970514 · changes requested · 2 findings · 29 min
Run code-review-agent_6b1049a5db0575.02480147 · trail
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The reopen fix works, but the library page now fails to open URL-imported charts, and older rows can still replace newer edits.
Validation details
- Files reviewed: 2/2 files changed since the prior review. The other 8 changed files are unchanged since then.
- Sandbox site, WordPress 7.1.5, PHP 8.3.37: the three changed cases pass at
6049f16[R10]. With theindex.jsof53970514, the two reopen cases fail:set -o pipefail; cd /workspace/head && git -C /repo show 53970514f65a8191dd8af9a8b14fe6d8ca4bd338:classes/Visualizer/Cha…printedReceived(run R12). - A URL-imported chart opened from the library shows
(t || []).map is not a functionat HEAD [R18]. The same chart showsrows: 2with theindex.jsof53970514[R20].
Untested areas
- The data shape of JSON, database and third-party sources in the chart load was not traced.
- The editor remount and the generation order were traced in the source only.
- The variant pass did not settle these places, where the fixed cause may still reach:
- not reached: Classic renderer consumers in js/preview.js, js/render-chartjs.js, js/render-datatables.js and js/render-google.js
- not reached: existing review replies truncated in threads.md were not recovered
🤖 Automated review · run code-review-agent_6b1060e40fe258.53317730.
🤖 Review agent — review posted ✅ on 6049f16b · changes requested · 3 findings · 22 min
Run code-review-agent_6b1060e40fe258.53317730 · trail
…or mounted Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The two fixes of the last round work, but a generation can still replace an edit that waits to upload; see the open thread.
Validation details
- Files reviewed: 4/4 files changed since the prior review. The other 6 changed files are unchanged since then.
- Sandbox site, WordPress 7.1.5, PHP 8.3.37. A URL-imported chart opened from the library shows
cd /repo && git archive HEAD classes/Visualizer/ChartBuilder/src/AIBuilder/index.js classes/Visualizer/Module/AIBuilder.…printedrowsText ['rows: 2'](run R15). - The new data editor case passes at HEAD:
cat > /workspace/pw.c3b.config.js <<'EOF' // C3 (b): the new HEAD case of tests/e2e/specs/ai-builder.spec.js on the sand…printed1 passed(run R13). With the code of6049f16, it fails attoHaveValue[R14]. - The new PHPUnit case passes at HEAD:
cd /workspace/head && grep -n "WP_TESTS_DIR\|plugins/\|PLUGIN\|require.*index.php\|visualizer" tests/bootstrap.php 2>/de…printedOK (1 test, 2 assertions)(run R16). It fails with the pr-base code [R17].
Untested areas
- Source handlers of the Pro plugin and of other plugins are not in the checkout. Their rows in the chart load were not traced.
- The Pro spreadsheet grid was not checked while it is hidden behind the code editor.
- The standards pass was skipped. This is the ninth review of the PR.
- The variant pass did not settle these places, where the fixed cause may still reach:
- not reached: Wizard’s direct decoder beyond its fixed local CSV source (classes/Visualizer/Module/Wizard.php:217-246)
🤖 Automated review · run code-review-agent_6b10723894f945.38328578.
🤖 Review agent — review posted ✅ on 8054e9b8 · changes requested · 0 findings · 15 min
Run code-review-agent_6b10723894f945.38328578 · trail
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…new chart Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The fix keeps an edit on a saved chart, but a new chart's first edit and a failed upload are still replaced by generated data.
Validation details
- Files reviewed: 2/2 files changed since the prior review. The other 8 changed files are unchanged since then. One question row was not settled: handleDataReady() signature and return changed.
- Sandbox site, WordPress 7.1.5, PHP 8.3.37. The three changed cases pass at HEAD [R11]. With the
8054e9bcode, the case for a kept edit fails [R10]. - A new chart whose pasted rows waited behind the sample upload ended with
python3 - <<'PY' from pathlib import Path p=Path('/workspace/checks/C2/ai-builder.spec.js') s=p.read_text().replace("pre…printed"uploads":3,"previewRows":"rows: 3"(run R15).
Untested areas
- The failed-upload case is traced in source only. It was not run.
- The question row "handleDataReady() signature and return changed" stays unchecked. Its code is unchanged since the prior review.
- The standards pass was skipped. This is the tenth review of the PR.
- Source handlers and the spreadsheet grid of the Pro plugin are not in the checkout.
🤖 Automated review · run code-review-agent_6b127cb396a8d0.05688838.
🤖 Review agent — review posted ✅ on 6b00350d · changes requested · 1 finding · 16 min
Run code-review-agent_6b127cb396a8d0.05688838 · trail
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
Both earlier edit fixes work, but a Pro import on a new chart can still be replaced by generated data.
Validation details
- Files reviewed: 3/3 files changed since the prior review. The other 7 changed files are unchanged since then. One question row was not settled: Usage logger crashes when chart settings meta is a string.
- Sandbox site, WordPress 7.1.5, PHP 8.3.37. The five generation and edit cases pass at HEAD:
cd /workspace/checks/R1 && set -o pipefail; timeout 600 node head/node_modules/@playwright/test/cli.js test -c pw.r1.con…printed5 passed (25.4s)(run R11) - A URL import on a new chart, with Generate clicked before any upload answered, ended with
mkdir -p /workspace/checks/R2 && cd /workspace/checks/R2 && cat > pw.r2.config.js <<'EOF' // R2 runner: scratch spec und…printedR2 final preview .rows: ["rows: 3"](run R17)
Untested areas
- The File import path was traced in source only. Playwright cannot match a file request.
- The question row "Usage logger crashes when chart settings meta is a string" stays unchecked. Its code is unchanged since an earlier review.
- The Pro plugin source is not in the checkout.
🤖 Automated review · run code-review-agent_6b1287d3d82084.22438223.
🤖 Review agent — review posted ✅ on 15b88e9e · changes requested · 1 finding · 25 min
Run code-review-agent_6b1287d3d82084.22438223 · trail
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes requested
The import fix works, but an edit can still be lost on Publish and Done, and a generation in another tab can replace newer rows.
Validation details
- Files reviewed: 3/3 files changed since the prior review. The other 7 changed files are unchanged since then.
- Sandbox site, WordPress 7.1.5, PHP 8.3.37. The three new cases pass:
cd /workspace/checks/C1 && set -o pipefail; export C1_GREP='keeps text restored while the upload of an edit waits|keeps …printed3 passed(run R6) - The earlier import scenario keeps the imported rows at this head:
cd /workspace/checks/C1/r2 && set -o pipefail; timeout 280 node /workspace/checks/C1/head/node_modules/@playwright/test/…printedR2 uploads total: 1(run R8) - The generation and upload cases of the spec pass except one sandbox fixture failure:
cd /workspace/checks/C1 && export C1_GREP='^(?!.*(keeps text restored while the upload of an edit waits|keeps an import …(run R7, exit 0)
Untested areas
- An open spreadsheet cell editor at the Generate click was not traced. Its grid ships with the Pro plugin.
- Closing the builder while a second edit waits in the upload queue was not checked.
- The block editor case could not run. The sandbox nonce request returned 400.
- No base-branch runs of the new cases were made.
- The variant pass did not settle these places, where the fixed cause may still reach:
- not reached: Complete registration/configuration traces for competing classic-editor, abilities and background-refresh writers: classes/Visualizer/Module/Chart.php:254-278,1417-1438,1693-1718
- not reached: classes/Visualizer/Module/Abilities.php:1255-1265
- not reached: classes/Visualizer/Module/Setup.php:415-463
🤖 Automated review · run code-review-agent_6b129763a6b800.89773291.
🤖 Review agent — review posted ✅ on 6fc2e8fa · changes requested · 2 findings · 45 min
Run code-review-agent_6b129763a6b800.89773291 · trail
| const t = setTimeout( () => { | ||
| const userData = ! isSample( trimmed ); | ||
| lastCsvRef.current = trimmed; | ||
| runUpload( () => uploadCsvString( chartId, uploadNonce, trimmed ).catch( ( e ) => { | ||
| // The server does not hold this text, so the editor can upload it again. | ||
| if ( lastCsvRef.current === trimmed ) lastCsvRef.current = null; | ||
| throw e; | ||
| } ), ( r ) => { | ||
| appliedCsvRef.current = trimmed; | ||
| onDataReady( r.series, r.data ); | ||
| lastCsvRef.current = trimmed; | ||
| } catch ( e ) { setError( e.message ); } | ||
| finally { setLoading( false ); } | ||
| }, userData ); | ||
| }, 700 ); | ||
| return () => clearTimeout( t ); |
There was a problem hiding this comment.
correctness A data edit is lost when the user publishes and closes the builder within 700 ms of typing. The edit uploads only when the debounce fires (DataSource.js:245-256). Publish saves only the title and code (index.js:588) and does not wait for the edit. When Publish answers first, Done closes the builder and return () => clearTimeout( t ) cancels the upload. The published chart keeps the older rows, and the reopened builder shows them. This path was already in the code the earlier review saw. Fix: report Publish as done only when the server holds the editor's data: wait for a pending edit and its queued upload, and report an edit whose upload failed. Add an ai-builder.spec.js case that edits, publishes, clicks Done at once, reopens and expects the edit.
| setInitialCsvText( trimmedCsv ); | ||
| handleDataReady( parsed.series, parsed.data ); | ||
| // The data of the job waits for the uploads of the data source. A data change that the job did not get stays. | ||
| const parsed = await queueWrite( () => openRef.current && ! owedAtClick && uploadCsvString( chartId, uploadNonce, trimmedCsv ) ); |
There was a problem hiding this comment.
correctness A generation in one tab replaces a newer data edit made in another tab of the same chart. owedAtClick reads only the data source of this page (index.js:432,476), and the write queue is page-local (api.js:32-46). Open one chart in tabs A and B. Click Generate in A, then edit the rows in B. When A's job returns data_csv, A uploads it after B's edit, and the chart loses B's rows. This path was already in the code the earlier review saw. Fix: refuse a data write whose base is older than the chart's current data, and tell the user the generated data was not applied. Add a two-page case to ai-builder.spec.js.
The AI Chart Builder drew its preview directly in the admin page, while the front end and the block editor draw D3 charts in a sandboxed frame. The builder now uses the same frame for the preview and for its code check.
What changed
Builder preview — chart code runs in the sandboxed D3 frame (
sandbox="allow-scripts"), not in the admin page. The builder no longer bundles its own copy of D3 and TopoJSON.Code check — the check that runs before a chart is shown or saved uses a hidden sandboxed frame and waits for its result. A chart that gives no result in 10 seconds counts as failed.
Builder settings — the builder gets the address of the frame script in its own settings (
vizAIBuilder.iframeJsUrl), on the library page and in the block editor. The preview does not depend on a D3 chart in the library.Frame script address — every page that loads the frame script gets its address from
Visualizer_Module::d3_iframe_js_url(), which adds the plugin version (?ver=). A browser does not answer with the script of an older version, which never reports its render result.Older check results — a check result is ignored when it no longer applies:
D3 frame — after each render it reports the result to its parent as
{ type: 'render-result', error }.Note
Tracked in Codeinwp/visualizer-pro#658.
Tests
New Playwright cases in
tests/e2e/specs/ai-builder.spec.js:Chart error: <message>;Each case fails with its fix reverted.
Two more cases cover the locks: the prompt is disabled until the saved chart loads, and Edit code does not open while the chart is published.
Four more cases cover the order of the requests: no repair during a publish, one upload at a time, no upload of a generation after the builder closes, and an edit after a generation that returned the data of the editor.
More cases cover the upload queue and the data source: an upload after the code editor closed, a data change that a generation did not get (an edit on a saved chart and on a new chart, an edit with a failed upload, text restored during an upload, an import on a new chart), the data of a generation after the user removed an edit, after a failed import or before the sample data loaded, text restored during an upload, the saved text after an import, the lock during an import, Publish chart behind an upload, a reopened builder that shows the rows of the last upload, and the data editor after Edit code closes. A PHPUnit case covers the rows of a remote file in the load.
The File import and the Spreadsheet source have no case. Playwright cannot match a request that carries a file, and the grid library of the Spreadsheet ships with the Pro plugin.
QA
On a site with no AI chart in the library, go to
WP Admin → Visualizer → Chart Library. Click Add New Chart, select the AI builder, add data and generate a chart.Expect: the preview shows the chart, and the chart saves.
In the library, click the edit control of that chart.
Expect: the builder opens and the preview shows the saved chart.
In the builder, ask for a change to the chart (for example, another colour).
Expect: the preview updates, and a chart with broken code shows an error message, not an empty preview.
In a post, add a Visualizer block with that chart and click its edit control.
Expect: the builder opens and the preview shows the chart. In Edit code, change the code and click Save: the preview shows the change.
Review responses
Answers to the points of the review of
a941148that have no inline thread:Module/Chart.php) — this PR does not change what reaches those hooks. Whether a Pro consumer runs chart code is a question for the Pro plugin, so it is out of scope here.window.vizOpenAIBuilderEdit, the function the control calls, as the review run did. The case covers the missing setting, which is what broke the block editor.