Repository navigation
fix(dataeditor): settle column defaults and the cell callback at create time - #7607
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
[Medium impact] The PR appears safe to merge; no new actionable issues were found. Summary
Reviews (10) · Last reviewed commit: "fix(dataeditor): apply the defaults to a..." · Reviewed by Greptile |
Merging this PR will not alter performance
|
761b58f to
f12a9b7
Compare
8988e6e to
8eb0553
Compare
8eb0553 to
1ff8832
Compare
…te time `DataEditor.create` only applied the documented default column `type` and `id` to literal column lists. State-backed columns reached Glide untouched, so a column without a `type` produced an invalid text cell and crashed at render (#7596). Replace `add_hooks` with hooks carried on the vars assigned to the props: - A state-backed column list is mapped through the defaults inside a `useMemo` keyed on it, so the mapping runs when the columns change rather than for every cell Glide draws. It takes the same shapes as the literal path, a title string or an object. The columns prop names that memoized list and still tracks the state field it comes from. - `getCellContent` is a `useCallback` over the rendered columns and data. Both dependency arrays list the leaf vars behind each prop, through `get_leaf_vars`, so a derived prop such as `State.columns.filter(...)` depends on `State.columns` alone. A literal or function carrying no var data is a constant expression and is left out. - `formatDataEditorCells` is imported by the hook that uses it. Both hooks are created in `create` along with `get_cell_content`, so the component no longer mutates itself during rendering and no hoisted state has to be stashed on the instance. Column formatting moves into the data editor module as `_format_column`, which builds a new dict instead of modifying the caller's. The old `reflex_base.utils.format.format_data_editor_column` stays as a deprecated shim so an older data editor release keeps working against a newer base. The data editor is floored on reflex-base 0.10.1.dev0 for `get_leaf_vars`. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD
The dependency arrays dropped a literal or function carrying no var data as a constant, but a memo prop or loop var carries none either: an `@rx.memo` component passing `data=[[value]]` got a `useCallback` with `[]` and kept the first value. Now that `get_leaf_vars` reads through literal containers and function bodies, the arrays list every var the props read, with no heuristic left: `[[value]]` yields `value`, a predicate closing over nothing yields nothing, and `State.data[1:]` yields `State.data`. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD
…nly columns
`_format_column` read `title` even when the column already carried an `id`,
so a literal column such as `{"id": "name", "type": "str"}` raised
`KeyError` where it used to pass through. Fill in the default `id` only
when none is given.
The memoized column var kept the input's type, so a state var of title
strings failed the prop type check before the mapping that turns titles
into column dicts could run. Type it as `Sequence[dict[str, Any]]`, which
is what the mapping yields whatever the input holds.
Tell a user who sees the `format_data_editor_column` deprecation what to
do: upgrade reflex-components-dataeditor, its only caller.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD
cf6d518 to
cd97a00
Compare
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
`_format_column` passes a var element through as is, so a literal list such
as `[{"title": "Name"}, State.extra]` handed Glide a column with no `type`,
the same crash the render-time defaults fix for a state-backed list. When a
literal list holds a var, route the whole list through that same `useMemo`
mapping; its dependencies are the vars the list reads, and the mapping
leaves the already formatted columns as they are.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD
All Submissions:
Type of change
Description
closes #7596
DataEditor.createonly applied the documented default columntypeandidto literal column lists. State-backed columns reached Glide untouched, so a column without atypeproduced an invalid text cell and crashed at render.This replaces
add_hookswith hooks carried on the vars assigned to the props, all created increate:useMemokeyed on it, so the mapping runs when the columns change rather than for every cell Glide draws. It takes the same shapes as the literal path, a title string or an object, and the memoized var is typed as the column dicts the mapping yields, so alist[str]of titles passes the prop check. The columns prop names that memoized list and still tracks the state field it comes from.getCellContentis auseCallbackover the rendered columns and data. Both dependency arrays list the vars each prop reads, throughget_leaf_vars(feat(vars): add get_leaf_vars #7606): the state fields, loop vars and memo props behind it, down to those inside a literal such as[[value]]or a predicate, and none of the constants. SoState.columns.filter(...)depends onState.columnsalone,State.data[1:]onState.data, and all-literal columns and data on nothing.formatDataEditorCellsis imported by the hook that uses it instead of byadd_imports.Both hooks are created along with
get_cell_content, so the component no longer mutates itself during rendering and nothing has to be stashed on the instance.Column formatting moves into the data editor module as
_format_column, which builds a new dict instead of modifying the caller's and fills in the defaultidonly when none is given.reflex_base.utils.format.format_data_editor_columnstays as a deprecated shim (0.10.1, removal 1.0) so an older data editor release keeps working against a newer base. The data editor is floored onreflex-base >= 0.10.1.dev0forget_leaf_vars.For
rx.data_editor(columns=State.columns, data=State.data)the compiled component now holds:Changes To Core Features:
tests/units/components/datadisplay/test_dataeditor.pycovers the literal defaults (explicit values win, a column with an id needs no title, input not modified), the rejected inputs, the generated callback name, the callback with and without dependencies, a memo prop inside a literal, the state-backed hooks in order with preserved var data, alist[str]state var of titles, derived props (a filter and a slice) depending on the vars they read, a literal var memoized once, and a Node run of the generated hooks against the realformatDataEditorCellshelper that asserts the normalized columns and the cells for dict and array rows.tests/units/reflex_base/utils/test_format.pycovers the deprecation shim.A real app with a state-backed grid whose column has no
typewas compiled and loaded in headless Chromium: the rows render, and adding a row and an untyped column re-renders with no page errors.ruff,pyrighton the touched files,make_pyi.py --check, and the unit tests pass.check_min_deps.pycould not run in this environment (shallow clone without reachable release tags); the data editor uses only reflex-base APIs present in 0.10.0 plusget_leaf_vars, now on main.🤖 Generated with Claude Code
https://claude.ai/code/session_01RqJ6TNt8AXzbDVm5kLb2nD