fix(ai-studio): re-adapt visualization when the render format changes - #65
Merged
Conversation
The adapted content was cached in bare state and reset only when the source text changed, so switching the render format kept feeding the previous format's adaptation to the new renderer (raw JSON instead of a chart) and never called the AI again. The adaptation is now an async derived value keyed by (renderer, text) in a useAdaptedVisualization hook: a stale entry is ignored by the key check instead of being reset by an effect, and each format change triggers a fresh adapt for that format.
librowski
requested review from
lukasz-jazwa,
piotrblaszczyk and
szymon-t-sc
as code owners
July 15, 2026 09:11
…data
The effect now uses an inner async function with an AbortController:
switching formats mid-flight cancels the HTTP request instead of just
ignoring its result, and the cancelled flag is gone.
A failed adapt is cached as { key, output: null } - the raw-text
fallback derives from data instead of a swallowed exception, so the
catch block has real content and the failure is one selector away
from the UI whenever we want to surface it.
…ation The hook now owns the raw-text fallback and returns renderText plus an isAdapted flag, so the caller no longer interprets a null convention spread across files.
…ation The hook now owns the raw-text fallback and returns renderText plus an isAdapted flag, so the caller no longer interprets a null convention spread across files.
lukasz-jazwa
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
"Adapt with AI" in the Visualize node ran at most once per output. The adapted content was cached in bare component state and reset only when the source text changed, so switching Render as to another format fed the previous format's adaptation to the new renderer - e.g. the chart renderer received the stat-cards JSON and displayed it as raw text - and the AI was never called again. Failures were also silently swallowed, which made the whole thing look randomly broken.
The adaptation is now an async derived value keyed by
(renderer, text), extracted into auseAdaptedVisualizationhook. A stale adaptation is ignored by the key check instead of being reset by an effect, so every format change triggers a fresh adapt for that format, and the two-effect choreography inVisualizeCardis gone.Verification
Exercised in the browser with an instrumented
fetchagainst the local stack: first adaptation fires once and renders (chart with proper axes), switching to Stat cards fires a second/api/visualize/adaptrequest and renders real stat cards instead of raw JSON.pnpm lintandpnpm typecheck(ai-studio) are green.