Skip to content

fix(widgets): persist and synchronize form inputs - #863

Open
mahruschow wants to merge 3 commits into
mainfrom
fix/thinkex-758
Open

mahruschow wants to merge 3 commits into
mainfrom
fix/thinkex-758

Conversation

@mahruschow

@mahruschow mahruschow commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #758.

Each document widget keeps supported form values in its own Yjs map. Collaborators see field updates in their existing iframe. Reopening the document restores values through the document session. Writes require edit access. Password and file inputs are excluded.

The sandbox uses a per-document message port. Updates to separate fields merge independently. Controls without IDs fall back to their position, so generated widgets should use stable IDs when they reorder controls.

Verified in Chromium using three sandboxed frames backed by separate synchronized Yjs documents. Concurrent edits to different fields, dependent output, read-only access, and restoration from an encoded Yjs snapshot passed. The iframe regression test exercises form reset, same-name radio groups in separate forms, and dynamic controls. All 436 Node tests, TypeScript, formatting and lint passed. The Worker suite also passed locally (31 tests).

@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87009bbf-d31d-44e2-925a-3aa0543a2534
Commits

Reviewing files that changed from the base of the PR and between 14150c2 and 3dadae8.

Files selected for processing: 9

  • src/features/workspaces/components/document-editor/DocumentEditorSurface.tsx
  • src/features/workspaces/components/widget/WorkspaceWidgetSandbox.test.tsx
  • src/features/workspaces/components/widget/WorkspaceWidgetSandbox.tsx
  • src/features/workspaces/components/widget/widget-inputs.js
  • src/features/workspaces/components/widget/widget-inputs.test.ts
  • src/features/workspaces/components/widget/workspace-widget-sandbox-document.ts
  • src/features/workspaces/documents/document-ai-html.ts
  • src/features/workspaces/documents/document-widget-node.tsx
  • src/features/workspaces/documents/tiptap-schema.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

React Doctor found 1 new issue in 1 file · 1 warning · score 92 / 100 (Great) · 0 fixed · vs main

1 warning

src/features/workspaces/documents/document-widget-node.tsx

  • ⚠️ L67 Data passed to parent via effect no-pass-data-to-parent

Reviewed by React Doctor for commit 3dadae8. See inline comments for fixes.

@greptile-apps

greptile-apps Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect form state across document-widget collaboration and reopening.

The PR appears safe to merge, with non-blocking fixes for resets, separate radio groups, and form-script tests.

Findings

  1. P2 Reset answers return ▶
  2. P2 Separate forms share radio answers ▶
  3. P2 Form script remains untested ▶

Summary

The PR saves widget form values in per-widget Yjs maps and sends collaborator updates into the existing iframe.

  • Document widgets restore and share supported form values.

Reviews (1) · Last reviewed commit: "fix(widgets): persist shared form inputs..." · Reviewed by Greptile

Comment on lines +74 to +75
document.addEventListener("input", capture, true);
document.addEventListener("change", capture, true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reset answers return

Resetting a form does not save its cleared values. capture listens only for input and change, but a reset fires neither. Reopening the widget restores the old answers, and an unrelated collaborator update can bring them back immediately. Listen for reset and capture the controls after the browser applies their defaults.

)
)
return null;
if (control.type === "radio" && control.name) return "radio:name:" + control.name;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Separate forms share radio answers

Two forms can each have a radio group named choice, but keyFor gives both groups the same saved key, even when their controls have stable IDs. Selecting an answer in one form overwrites the other's saved answer. Restoring then applies that answer to both forms. Include the owning form's identity in the group key.

Comment on lines +93 to +99
window.dispatchEvent(
new MessageEvent("message", {
origin: "null",
source: iframe.contentWindow,
ports: [channel.port2],
data: { kind: "connect-inputs", sessionId: 1, source: WIDGET_SANDBOX_FRAME_SOURCE },
}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Form script remains untested

The new test sends connect-inputs itself and checks the host's map, so it never runs widget-inputs.js. Bugs in control keys, event capture, restoration, and dynamically added controls can pass this test. Add automated tests that execute the iframe script against real controls and check both saved values and restored controls.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

const pos = getPos();
const current = typeof pos === "number" ? editor.state.doc.nodeAt(pos) : null;
if (current?.type === node.type && !current.attrs[tiptapDocumentAiRefAttribute]) {
updateAttributes({ [tiptapDocumentAiRefAttribute]: createDocumentBlockId() });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React Doctor · react-doctor/no-pass-data-to-parent (warning)

Handing data back to a parent from a useEffect costs your users an extra render.

Fix → Fetch the data in the parent and pass it down as a prop (or return it from the hook), instead of handing it back up through a prop callback in a useEffect. See https://react.dev/learn/you-might-not-need-an-effect#passing-data-to-the-parent

Docs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 issues 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. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/features/workspaces/components/widget/workspace-widget-sandbox-document.ts">

<violation number="1" location="src/features/workspaces/components/widget/workspace-widget-sandbox-document.ts:308">
P2: Custom agent: **Flag AI Slop and Fabricated Changes**

The `shareInputs` script-injection path is not exercised by tests: the Yjs test manually sends port messages without running this script or testing form capture and restoration. Add a regression test that exercises the generated script against form controls.</violation>
</file>

<file name="src/features/workspaces/documents/document-widget-node.tsx">

<violation number="1" location="src/features/workspaces/documents/document-widget-node.tsx:62">
P2: Custom agent: **Flag AI Slop and Fabricated Changes**

The sandbox test supplies `fields` directly, so it does not cover this effect assigning a missing `aiRef` or the view wiring that ID to the document's Yjs map. Add a regression test for a ref-less editable widget; this wiring is required for document-level persistence.</violation>

<violation number="2" location="src/features/workspaces/documents/document-widget-node.tsx:67">
P2: Concurrent editors can lose widget inputs while assigning an ID to the same unassigned widget. Each client generates a different ID and writes to its own Yjs map before the shared attribute converges, orphaning the losing map; assign IDs through a shared operation or merge the maps on conflict.</violation>

<violation number="3" location="src/features/workspaces/documents/document-widget-node.tsx:69">
P2: This effect checks `editor.isEditable` but does not depend on it. If a widget mounts while the editor is read-only (e.g. during edit review), it never gets an `aiRef` after editing resumes, so its values silently stop persisting. Add editability to the dependencies.</violation>
</file>

<file name="src/features/workspaces/components/widget/widget-inputs.js">

<violation number="1" location="src/features/workspaces/components/widget/widget-inputs.js:13">
P2: The whitelist silently drops common editable input types such as `email`, `url`, `tel`, `month`, `week`, and `datetime-local`. Add these types so only password and file inputs remain excluded.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

window.addEventListener("load",measure);
measure();
post({kind:"ready"});
${shareInputs ? widgetInputsScript : ""}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Custom agent: Flag AI Slop and Fabricated Changes

The shareInputs script-injection path is not exercised by tests: the Yjs test manually sends port messages without running this script or testing form capture and restoration. Add a regression test that exercises the generated script against form controls.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/components/widget/workspace-widget-sandbox-document.ts, line 308:

<comment>The `shareInputs` script-injection path is not exercised by tests: the Yjs test manually sends port messages without running this script or testing form capture and restoration. Add a regression test that exercises the generated script against form controls.</comment>

<file context>
@@ -301,6 +305,7 @@ textarea{resize:vertical;}
     window.addEventListener("load",measure);
     measure();
     post({kind:"ready"});
+    ${shareInputs ? widgetInputsScript : ""}
   },{once:true});
 })();
</file context>

const ydoc = use(WidgetDocumentContext);
const blockId = node.attrs[tiptapDocumentAiRefAttribute];
// Pasted blocks and new documents can be opened before the first AI read assigns refs.
useEffect(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Custom agent: Flag AI Slop and Fabricated Changes

The sandbox test supplies fields directly, so it does not cover this effect assigning a missing aiRef or the view wiring that ID to the document's Yjs map. Add a regression test for a ref-less editable widget; this wiring is required for document-level persistence.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/documents/document-widget-node.tsx, line 62:

<comment>The sandbox test supplies `fields` directly, so it does not cover this effect assigning a missing `aiRef` or the view wiring that ID to the document's Yjs map. Add a regression test for a ref-less editable widget; this wiring is required for document-level persistence.</comment>

<file context>
@@ -39,10 +46,31 @@ export function DocumentWidgetActionProvider({
+	const ydoc = use(WidgetDocumentContext);
+	const blockId = node.attrs[tiptapDocumentAiRefAttribute];
+	// Pasted blocks and new documents can be opened before the first AI read assigns refs.
+	useEffect(() => {
+		if (!ydoc || blockId || !editor.isEditable) return;
+		const pos = getPos();
</file context>

if (current?.type === node.type && !current.attrs[tiptapDocumentAiRefAttribute]) {
updateAttributes({ [tiptapDocumentAiRefAttribute]: createDocumentBlockId() });
}
}, [blockId, editor, getPos, node.type, updateAttributes, ydoc]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This effect checks editor.isEditable but does not depend on it. If a widget mounts while the editor is read-only (e.g. during edit review), it never gets an aiRef after editing resumes, so its values silently stop persisting. Add editability to the dependencies.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/documents/document-widget-node.tsx, line 69:

<comment>This effect checks `editor.isEditable` but does not depend on it. If a widget mounts while the editor is read-only (e.g. during edit review), it never gets an `aiRef` after editing resumes, so its values silently stop persisting. Add editability to the dependencies.</comment>

<file context>
@@ -39,10 +46,31 @@ export function DocumentWidgetActionProvider({
+		if (current?.type === node.type && !current.attrs[tiptapDocumentAiRefAttribute]) {
+			updateAttributes({ [tiptapDocumentAiRefAttribute]: createDocumentBlockId() });
+		}
+	}, [blockId, editor, getPos, node.type, updateAttributes, ydoc]);
+	const fields =
+		ydoc && typeof blockId === "string"
</file context>
Suggested change
}, [blockId, editor, getPos, node.type, updateAttributes, ydoc]);
}, [blockId, editor, editor.isEditable, getPos, node.type, updateAttributes, ydoc]);

const pos = getPos();
const current = typeof pos === "number" ? editor.state.doc.nodeAt(pos) : null;
if (current?.type === node.type && !current.attrs[tiptapDocumentAiRefAttribute]) {
updateAttributes({ [tiptapDocumentAiRefAttribute]: createDocumentBlockId() });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Concurrent editors can lose widget inputs while assigning an ID to the same unassigned widget. Each client generates a different ID and writes to its own Yjs map before the shared attribute converges, orphaning the losing map; assign IDs through a shared operation or merge the maps on conflict.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/documents/document-widget-node.tsx, line 67:

<comment>Concurrent editors can lose widget inputs while assigning an ID to the same unassigned widget. Each client generates a different ID and writes to its own Yjs map before the shared attribute converges, orphaning the losing map; assign IDs through a shared operation or merge the maps on conflict.</comment>

<file context>
@@ -39,10 +46,31 @@ export function DocumentWidgetActionProvider({
+		const pos = getPos();
+		const current = typeof pos === "number" ? editor.state.doc.nodeAt(pos) : null;
+		if (current?.type === node.type && !current.attrs[tiptapDocumentAiRefAttribute]) {
+			updateAttributes({ [tiptapDocumentAiRefAttribute]: createDocumentBlockId() });
+		}
+	}, [blockId, editor, getPos, node.type, updateAttributes, ydoc]);
</file context>

function keyFor(control, index) {
if (
control instanceof HTMLInputElement &&
!["text", "search", "number", "range", "checkbox", "radio", "color", "date", "time"].includes(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The whitelist silently drops common editable input types such as email, url, tel, month, week, and datetime-local. Add these types so only password and file inputs remain excluded.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/components/widget/widget-inputs.js, line 12:

<comment>The whitelist silently drops common editable input types such as `email`, `url`, `tel`, `month`, `week`, and `datetime-local`. Add these types so only password and file inputs remain excluded.</comment>

<file context>
@@ -0,0 +1,87 @@
+	function keyFor(control, index) {
+		if (
+			control instanceof HTMLInputElement &&
+			!["text", "search", "number", "range", "checkbox", "radio", "color", "date", "time"].includes(
+				control.type,
+			)
</file context>
Suggested change
!["text", "search", "number", "range", "checkbox", "radio", "color", "date", "time"].includes(
!["text", "search", "email", "url", "tel", "number", "range", "checkbox", "radio", "color", "date", "month", "week", "time", "datetime-local"].includes(

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 existing issues remain and 4 new issues found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/features/workspaces/components/widget/widget-inputs.js">

<violation number="1" location="src/features/workspaces/components/widget/widget-inputs.js:47">
P2: Values over 8192 characters are dropped silently here. The field keeps the long text, but the saved copy and the host keep the old value, so collaborators and reopened documents show stale data. Reject or truncate the value explicitly, or sync it through a path that does not depend on this limit.</violation>
</file>

<file name="src/features/workspaces/components/widget/widget-inputs.test.ts">

<violation number="1" location="src/features/workspaces/components/widget/widget-inputs.test.ts:12">
P3: The `parent` mock discards the handshake payload, so this test never checks `source`, `kind`, or `sessionId`. Record `_data` and assert it equals `{ source: "thinkex-widget-frame", sessionId: 1, kind: "connect-inputs" }`, since the real parent rejects any other shape.</violation>
</file>

<file name="src/features/workspaces/components/widget/WorkspaceWidgetSandbox.tsx">

<violation number="1" location="src/features/workspaces/components/widget/WorkspaceWidgetSandbox.tsx:242">
P2: The port handler applies every incoming field write with no throttle. A widget can flood the Yjs document with updates, each up to 8 KB, and the 128-key cap does not bound how many updates it sends. Consider coalescing writes per key (for example, debouncing or batching them into one transaction per tick) before applying them.</violation>
</file>

<file name="src/features/workspaces/documents/document-widget-node.tsx">

<violation number="1" location="src/features/workspaces/documents/document-widget-node.tsx:72">
P3: Deleting a widget leaves its `widget-inputs:<blockId>` map in the Yjs document, with the entered values still stored. Consider clearing the map when the node is removed, or document that field values are retained by design.</violation>
</file>

Requires human review: Auto-approval blocked because this review re-detected 2 unresolved issues already reported by Cubic.

View guided diff | Re-trigger cubic

}

function save(key, value) {
if (!key || key.length > 200 || value.length > 8192 || saved.get(key) === value) return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Values over 8192 characters are dropped silently here. The field keeps the long text, but the saved copy and the host keep the old value, so collaborators and reopened documents show stale data. Reject or truncate the value explicitly, or sync it through a path that does not depend on this limit.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/components/widget/widget-inputs.js, line 47:

<comment>Values over 8192 characters are dropped silently here. The field keeps the long text, but the saved copy and the host keep the old value, so collaborators and reopened documents show stale data. Reject or truncate the value explicitly, or sync it through a path that does not depend on this limit.</comment>

<file context>
@@ -0,0 +1,132 @@
+	}
+
+	function save(key, value) {
+		if (!key || key.length > 200 || value.length > 8192 || saved.get(key) === value) return;
+		saved.set(key, value);
+		notified.set(key, value);
</file context>

fields.get(data.key) === data.value
)
return;
fields.doc?.transact(() => fields.set(data.key, data.value), port);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The port handler applies every incoming field write with no throttle. A widget can flood the Yjs document with updates, each up to 8 KB, and the 128-key cap does not bound how many updates it sends. Consider coalescing writes per key (for example, debouncing or batching them into one transaction per tick) before applying them.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/components/widget/WorkspaceWidgetSandbox.tsx, line 242:

<comment>The port handler applies every incoming field write with no throttle. A widget can flood the Yjs document with updates, each up to 8 KB, and the 128-key cap does not bound how many updates it sends. Consider coalescing writes per key (for example, debouncing or batching them into one transaction per tick) before applying them.</comment>

<file context>
@@ -182,6 +219,41 @@ export function WorkspaceWidgetSandbox({
+			fields.get(data.key) === data.value
+		)
+			return;
+		fields.doc?.transact(() => fields.set(data.key, data.value), port);
+	};
+	const onChange = (change: Y.YMapEvent<string>) => {
</file context>

const received = new Map<string, string>();
let port!: MessagePort;
const parent = {
postMessage(_data: unknown, _target: string, ports: MessagePort[]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The parent mock discards the handshake payload, so this test never checks source, kind, or sessionId. Record _data and assert it equals { source: "thinkex-widget-frame", sessionId: 1, kind: "connect-inputs" }, since the real parent rejects any other shape.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/components/widget/widget-inputs.test.ts, line 12:

<comment>The `parent` mock discards the handshake payload, so this test never checks `source`, `kind`, or `sessionId`. Record `_data` and assert it equals `{ source: "thinkex-widget-frame", sessionId: 1, kind: "connect-inputs" }`, since the real parent rejects any other shape.</comment>

<file context>
@@ -0,0 +1,49 @@
+	const received = new Map<string, string>();
+	let port!: MessagePort;
+	const parent = {
+		postMessage(_data: unknown, _target: string, ports: MessagePort[]) {
+			port = ports[0]!;
+			port.onmessage = ({ data }) => received.set(data.key, data.value);
</file context>

}, [blockId, editor, getPos, node.type, updateAttributes, ydoc]);
const fields =
ydoc && typeof blockId === "string"
? ydoc.getMap<string>(`widget-inputs:${blockId}`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: Deleting a widget leaves its widget-inputs:<blockId> map in the Yjs document, with the entered values still stored. Consider clearing the map when the node is removed, or document that field values are retained by design.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/documents/document-widget-node.tsx, line 72:

<comment>Deleting a widget leaves its `widget-inputs:<blockId>` map in the Yjs document, with the entered values still stored. Consider clearing the map when the node is removed, or document that field values are retained by design.</comment>

<file context>
@@ -39,10 +46,31 @@ export function DocumentWidgetActionProvider({
+	}, [blockId, editor, getPos, node.type, updateAttributes, ydoc]);
+	const fields =
+		ydoc && typeof blockId === "string"
+			? ydoc.getMap<string>(`widget-inputs:${blockId}`)
+			: undefined;
 	const label = title || "Widget";
</file context>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues 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. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/features/workspaces/components/widget/WorkspaceWidgetSandbox.tsx">

<violation number="1" location="src/features/workspaces/components/widget/WorkspaceWidgetSandbox.tsx:128">
P2: Changing `fields` or `canWriteFields` tears down the live input port here, but the frame only handshakes once per srcDoc, so sync silently stops. Either re-send connect-inputs on reconnect, or move the port teardown into a mount-only effect so the channel survives prop changes.</violation>
</file>

<file name="src/features/workspaces/documents/document-widget-node.tsx">

<violation number="1" location="src/features/workspaces/documents/document-widget-node.tsx:100">
P2: Keying the sandbox on `editor.isEditable` remounts every widget iframe when an AI edit review opens and closes, which discards each widget's in-frame state. Writability needs to reach the existing frame without a remount, for example by reading `canWriteFields` through a ref in `WorkspaceWidgetSandbox`.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

window.removeEventListener("message", connect);
disconnect?.();
};
}, [fields, canWriteFields, html]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Changing fields or canWriteFields tears down the live input port here, but the frame only handshakes once per srcDoc, so sync silently stops. Either re-send connect-inputs on reconnect, or move the port teardown into a mount-only effect so the channel survives prop changes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/components/widget/WorkspaceWidgetSandbox.tsx, line 128:

<comment>Changing `fields` or `canWriteFields` tears down the live input port here, but the frame only handshakes once per srcDoc, so sync silently stops. Either re-send connect-inputs on reconnect, or move the port teardown into a mount-only effect so the channel survives prop changes.</comment>

<file context>
@@ -88,7 +95,37 @@ export function WorkspaceWidgetSandbox({
+			window.removeEventListener("message", connect);
+			disconnect?.();
+		};
+	}, [fields, canWriteFields, html]);
 
 	useEffect(() => {
</file context>

</CodeBlockTitle>
</CodeBlockHeader>
<WorkspaceWidgetSandbox
key={`${blockId}:${editor.isEditable}`}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Keying the sandbox on editor.isEditable remounts every widget iframe when an AI edit review opens and closes, which discards each widget's in-frame state. Writability needs to reach the existing frame without a remount, for example by reading canWriteFields through a ref in WorkspaceWidgetSandbox.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/features/workspaces/documents/document-widget-node.tsx, line 100:

<comment>Keying the sandbox on `editor.isEditable` remounts every widget iframe when an AI edit review opens and closes, which discards each widget's in-frame state. Writability needs to reach the existing frame without a remount, for example by reading `canWriteFields` through a ref in `WorkspaceWidgetSandbox`.</comment>

<file context>
@@ -69,6 +97,9 @@ export function DocumentWidgetView({ node, selected }: NodeViewProps) {
 				</CodeBlockTitle>
 			</CodeBlockHeader>
 			<WorkspaceWidgetSandbox
+				key={`${blockId}:${editor.isEditable}`}
+				fields={fields}
+				canWriteFields={editor.isEditable}
</file context>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Widgets Clearing input

1 participant