Skip to content

fix(lit): add updateBoundData helper and use it in interactive v0.8 widgets#1260

Open
ppazosp wants to merge 2 commits intogoogle:mainfrom
ppazosp:fix/1023-requestUpdate
Open

fix(lit): add updateBoundData helper and use it in interactive v0.8 widgets#1260
ppazosp wants to merge 2 commits intogoogle:mainfrom
ppazosp:fix/1023-requestUpdate

Conversation

@ppazosp
Copy link
Copy Markdown
Contributor

@ppazosp ppazosp commented Apr 22, 2026

Supersedes #1022 and #1034, which were closed after I accidentally deleted my fork. This PR merges both into a single clean branch rebased on current main.

Description

Adds a updateBoundData() helper to the Root base class that encapsulates the setData() + requestUpdate() pattern, and wires up all interactive v0.8 widgets (Slider, TextField, DateTimeInput, CheckBox) to use it.

Root cause: these components call processor.setData() to update the data model, but never requestUpdate(), so the signal change from SignalMap.set() is not picked up by SignalWatcher and render() is never called again. Other components bound to the same data path will not reflect the new value. Visible in Slider (the <span> showing the current value stays stuck), latent in the others because native <input> elements display typed characters regardless of Lit re-renders.

Fix: Centralize the setData() + requestUpdate() pattern in Root.updateBoundData() and migrate all four components to use it. Consistent with the existing pattern in MultipleChoice (multiple-choice.ts:308).

Also removes an unused Types import from the Slider.

Closes #597
Fixes #1023

Pre-launch Checklist

ppazosp added 2 commits April 22, 2026 18:28
Add `updateBoundData()` helper to Root base class that encapsulates
the setData + requestUpdate pattern. Refactor Slider to use it.

Closes google#597
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Checkbox, DateTimeInput, Slider, and TextField components to utilize a new shared updateBoundData helper method in the Root class, streamlining data updates and ensuring consistent calls to requestUpdate(). Feedback suggests enhancing the updateBoundData method with a check for this.component to avoid unnecessary processing and redundant updates when the component is not fully initialized.

Comment on lines +79 to +90
protected updateBoundData(relativePath: string, value: DataValue) {
if (!this.processor) {
return;
}
this.processor.setData(
this.component,
relativePath,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.requestUpdate();
}
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.

medium

The updateBoundData helper should verify that this.component is not null before proceeding. While processor.setData includes an internal check and logs a warning, explicitly checking it here prevents an unnecessary call and a redundant requestUpdate() when the component context is missing. This ensures the helper only executes when the component is fully initialized and attached to a node.

Suggested change
protected updateBoundData(relativePath: string, value: DataValue) {
if (!this.processor) {
return;
}
this.processor.setData(
this.component,
relativePath,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.requestUpdate();
}
protected updateBoundData(relativePath: string, value: DataValue) {
if (!this.processor || !this.component) {
return;
}
this.processor.setData(
this.component,
relativePath,
value,
this.surfaceId ?? A2uiMessageProcessor.DEFAULT_SURFACE_ID
);
this.requestUpdate();
}

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

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

bug(lit): v0.8 interactive components missing requestUpdate after setData Lit slider - value not updating

1 participant