Skip to content

fix: make prop-derived chart values reactive (Area label position, Sparkline series type)#3311

Open
rajanpanth wants to merge 2 commits into
evidence-dev:mainfrom
rajanpanth:fix/reactive-prop-derivations
Open

fix: make prop-derived chart values reactive (Area label position, Sparkline series type)#3311
rajanpanth wants to merge 2 commits into
evidence-dev:mainfrom
rajanpanth:fix/reactive-prop-derivations

Conversation

@rajanpanth

Copy link
Copy Markdown

Sibling fix to #3310 — same bug class, found by sweeping the other viz components for it.

Problem

Two chart components derive values from props with plain let declarations, freezing them at mount-time while their consumers are reactive:

  • Area.svelte: let defaultLabelPosition = swapXY ? 'right' : 'top' — toggling swapXY after mount leaves the reactive labelPosition fallback stale (labels fall back to top on a swapped chart instead of right).
  • _Sparkline.svelte: let seriesType = type === 'area' ? 'line' : typeseriesType is consumed inside the $: try config block, so mounting as bar and switching to line keeps rendering bars.

Fix

Derive both with $: so the reactive consumers see current values — the same one-line pattern as the stacked100 fix in #3310. Changeset included (patch, @evidence-dev/core-components).

Deliberately excluded from the sweep: the isInitial/queryID mount-time captures in core/* (intentionally non-reactive — they record initial state), and function-local lets.

Note on tests: #3310 establishes the regression-spec pattern for this class on BarChart; these two are the same one-line derivation change. Happy to add per-component specs if you want them — Area mounts inside chart context, so I kept this PR surgical.

Area computed its default label position from swapXY and Sparkline its
series type from type with plain let declarations, so both froze at
mount-time values while their consumers are reactive: toggling swapXY
left area labels falling back to 'top' instead of 'right', and changing
a sparkline's type from bar to line kept rendering bars. Same class as
the BarChart stacked100 fix (evidence-dev#3310): derive with $: so the reactive
consumers see current values.
@rajanpanth
rajanpanth requested a deployment to Approval required to run action on external PR July 24, 2026 04:30 — with GitHub Actions Waiting
Untruncated re-sweep of the viz tree found the identical pattern in
Line.svelte (the earlier sweep output was truncated). _Chart's ySet/xSet
are intentionally non-reactive per their in-code comment and stay as-is.
@rajanpanth
rajanpanth requested a deployment to Approval required to run action on external PR July 25, 2026 02:31 — with GitHub Actions Waiting
@rajanpanth

Copy link
Copy Markdown
Author

Pushed a follow-up commit: an untruncated re-sweep of the viz tree found the identical pattern in Line.svelte (defaultLabelPosition derived from swapXY with a plain let, consumed by the reactive labelPosition fallback) — now fixed the same way, and the changeset text updated. That completes the class: the only remaining prop-derived lets (_Chart's ySet/xSet) are intentionally non-reactive per their in-code comment and were left alone.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant