Data-bound chart components 2/8: typed figure handles - #462
Data-bound chart components 2/8: typed figure handles#462FarhanAliRaza wants to merge 3 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
Greptile SummaryThe PR replaces bare live-chart tokens with typed figure handles and adds a typed
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported static-chart rejection of explicitly disabled handlers is fixed and covered by a focused regression test.
|
| Filename | Overview |
|---|---|
| python/reflex_xy/component.py | Adds the typed live-source path, compatibility routing, and static-event validation; the previous disabled-handler issue is fixed by removing None event props before validation. |
| python/reflex_xy/handles.py | Introduces immutable serialized figure and data handles plus strict figure-token normalization. |
| python/reflex_xy/vars.py | Changes synchronous and asynchronous figure vars from raw token strings to FigureHandle values while preserving the empty-token sentinel. |
| python/reflex_xy/assets/XYChart.jsx | Normalizes the typed figure prop and legacy token prop into one live subscription token. |
| tests/reflex_adapter/test_component.py | Covers typed figure props, compatibility warnings, static event refusal, and the explicitly disabled-handler regression. |
| spec/design/reflex-integration.md | Updates the authoritative Reflex integration contract for typed handles, compatibility behavior, and static event validation. |
Reviews (4): Last reviewed commit: "fix(reflex): review follow-ups on the ty..." | Re-trigger Greptile
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
All reported issues were addressed across 12 files
Tip: instead of fixing issues one by one fix them all with cubic
Re-trigger cubic
Chart state vars carried a bare token string, so the component's source was untyped: reflex_xy.chart(Dash.points) — the wrong var — compiled fine and failed at hydrate as a blank mount with an err frame. Wrap the token in a frozen dataclass (handles.py: FigureHandle, and DataHandle[S] for the tier above this one) and give the component a Var[FigureHandle] `figure` prop. The wrong var or a raw string now fails at create(), which is page evaluation — the framework's own TypeError, before a browser is involved. @reflex_xy.figure vars, register(), and inline() all return handles; the empty-token handle keeps the existing "not ready / no chart" sentinel, so the var type stays non-optional. Two compile-time refusals come with it: kernel-backed event props (on_point_hover/on_point_click/on_select_end) on a static src source now raise instead of silently never firing, and the positional live spellings chart(var) / chart(token_string) warn while routing to figure=. The static positional chart(Chart) form is NOT deprecated — it remains the only route for arbitrary Charts such as facet grids. Public helpers that take "a figure" (append, set_view, reset_view, select, clear_selection, release) accept a handle or its bare token for one release cycle. The wrapper reduces `figure` and legacy `token` to one subscription token; nothing below the subscribe path changes. Spec: reflex-integration.md §3.1 (handle-valued vars), §5 (figure= prop, deprecation shim, event refusal), file map.
c42e175 to
d0886d6
Compare
Review follow-ups on the typed-handle seam:
- create() drops None-valued on_* props (explicitly disabled handlers)
before validation, so on_point_hover=None compiles on every tier and
the static-source kernel-event check tests values, not key presence.
- token_of() no longer accepts DataHandle: figure-only helpers (append,
set_view, release, ...) fail immediately with TypeError instead of
addressing a room that can never exist.
- release() raises on invalid input instead of silently degrading to
registry.release("").
|
Review addressed in 3e98589:
Pinned by |
- XYChart.jsx: a present figure handle always wins over the legacy token prop; its empty token is the "not ready" sentinel, never a fallback to a stale legacy spelling. - The positional-string deprecation warning now says what actually works for a held bare token (figure=FigureHandle(token)) instead of pointing string sources at a prop that rejects raw strings. - test_component anchors the token assertion to the figure prop itself so a regression to the legacy wire path is caught. - reflex-integration.md §5 names the failure point create()/page evaluation, matching §3.1 instead of the looser 'at compile'.
Stacked on #461. Base is
stack/1-design-and-pins— the Files-changed tab shows only this layer.Problem
Chart state vars carried a bare token string, so the component's source was untyped.
reflex_xy.chart(Dash.points)— the wrong var — compiled fine and failed at hydrate as a blank mount with anerrframe.Change
Wrap the token in a frozen dataclass (
handles.py:FigureHandle, plusDataHandle[S]for the tier above) and give the component aVar[FigureHandle]figureprop. The wrong var or a raw string now fails atcreate()— page evaluation — with the framework's ownTypeError, before a browser is involved.@reflex_xy.figurevars,register(), andinline()all return handles. The empty-token handle keeps the existing "not ready / no chart" sentinel, so the var type stays non-optional.Two compile-time refusals come with it:
on_point_hover/on_point_click/on_select_end) on a staticsrcsource now raise instead of silently never firing;chart(var)/chart(token_string)warn while routing tofigure=.chart(Chart)— the positional static form — is deliberately NOT deprecated. It's the only route for arbitrary Charts such as facet grids, and it predates no replacement.Public helpers that take "a figure" (
append,set_view,reset_view,select,clear_selection,release) accept a handle or its bare token for one release cycle.The wrapper reduces
figureand legacytokento one subscription token; nothing below the subscribe path changes.Spec
reflex-integration.md§3.1 (handle-valued vars), §5 (figure=prop, deprecation shim, event refusal), file map.Test plan
uv run pytest tests/reflex_adapter tests/test_validation_timing.py— 170 passedpre-commit run --all-files,ruff check,ruff format --check,ty check— clean