feat: hydrate islands from JSON payloads#9987
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="marimo/_islands/_island_generator.py">
<violation number="1" location="marimo/_islands/_island_generator.py:569">
P2: Default-on JSON payload duplicates island data already present in DOM, causing page-size and performance regressions for large outputs.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Pull request overview
Adds an optional JSON “islands payload” export path so the frontend can hydrate island apps from structured data (cells/code/output metadata) instead of reconstructing everything from DOM attributes and encoded code blocks. This reduces the exporter/runtime contract surface for static HTML generators while preserving DOM parsing as a fallback.
Changes:
- Python:
MarimoIslandGeneratorcan emit an inert<script type="application/vnd.marimo.islands+json">…</script>payload (opt-in viainclude_payload) with per-cell code/output metadata and HTML-sensitive escaping. - Frontend: island parsing can consume schema v1 payloads to build “payload-backed” apps (with DOM anchors still used for visible slots), falling back to DOM parsing when payloads aren’t present/valid.
- Tests/docs: adds payload-focused tests, an HTML snapshot containing the payload, and documentation describing the payload contract.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
marimo/_islands/_island_generator.py |
Adds payload schema/constants and payload/script rendering with JSON escaping; threads include_payload through HTML/body renderers. |
tests/_islands/test_island_generator.py |
Adds unit tests for payload generation, option behavior, and script escaping. |
tests/_islands/snapshots/html-payload.txt |
Snapshot of HTML output including the payload script tag. |
frontend/src/core/islands/constants.ts |
Defines the payload script MIME type constant. |
frontend/src/core/islands/parse.ts |
Adds payload parsing/validation + payload-backed hydration path and disabled-cell support in synthesized marimo files. |
frontend/src/core/islands/bridge.ts |
Ensures payload-backed apps don’t get overridden by full-notebook export context. |
frontend/src/core/islands/__tests__/test-utils.tsx |
Extends test helpers to support data-cell-id. |
frontend/src/core/islands/__tests__/parse.test.ts |
Adds extensive tests for payload parsing/materialization and disabled cell synthesis. |
frontend/src/core/islands/__tests__/bridge.test.ts |
Tests that export-context notebook code is ignored for payload-backed apps. |
docs/guides/exporting/webassembly_html.md |
Documents island payloads, escaping behavior, and post-processing guidance. |
a448b82 to
00020df
Compare
|
rebased this to resolve the merge conflict but now CI seems to fail due to fcf95a2 (?) |
|
@peter-gy maybe there is a cycle or something off about the imports |
13bd507 to
5f21379
Compare
|
Had to bump ruff to Looks like this CI failure did not come up in other commits as other gh flows did not reach the branch where |
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.12-dev11 |
Adds JSON payloads to island exports. The islands runtime can hydrate from a structured payload instead of recovering source and metadata from each island's DOM. This reduces the island-contract logic we need to maintain in static exporters like https://github.com/marimo-team/quarto-marimo and https://github.com/marimo-team/jupyter-book-marimo.
What changed
MarimoIslandGeneratornow emits a JSON script tag on opt-in:code,outputHtml,outputMimetype,reactive,displayCode, anddisplayOutput.{ "cellId": "1faffc38-d97b-492e-9ffc-7c77d08d0d8fMJUe", "code": "mo.md(r\"\"\"\nI am static markdown.\n\"\"\")", "outputHtml": "<marimo-mime-renderer data-mime='"text/markdown"' data-data='"\u003cspan class=\"markdown prose dark:prose-invert contents\"\u003e\u003cspan class=\"paragraph\"\u003eI am static markdown.\u003c/span\u003e\u003c/span\u003e"'></marimo-mime-renderer>", "outputMimetype": "text/markdown", "reactive": true, "displayCode": false, "displayOutput": true }Follow-ups
outputHtmlcan be potentially huge. we could consider emitting a base64-encoded string inside<script type="application/vnd.marimo.islands+jsonb64">if this becomes an issue. Quarto does the same for their ObservableJS support.MarimoIslandGenerator.from_irAPI which would accept aNotebookSerializationobjectDemo