Skip to content

[codex] Fix memoized component hook prop rendering#6506

Merged
masenf merged 1 commit into
mainfrom
codex/fix-data-editor-memo-hook-props
May 14, 2026
Merged

[codex] Fix memoized component hook prop rendering#6506
masenf merged 1 commit into
mainfrom
codex/fix-data-editor-memo-hook-props

Conversation

@Alek99
Copy link
Copy Markdown
Member

@Alek99 Alek99 commented May 14, 2026

Summary

  • Compile auto-memo component hooks before rendering so hook-mutated props are present in memo modules.
  • Add regression coverage for auto-memo components whose add_hooks fills a render prop.

Root Cause

The auto-memo full-component path rendered before calling get_all_hooks(). DataEditor.add_hooks() generates the getData* hook and mutates the component with the getCellContent prop, so the memoized docs module included the hook function but rendered without getCellContent. Glide then tried to call the missing callback and the docs page failed with TypeError: x is not a function.

Validation

  • uv run ruff check reflex/compiler/utils.py tests/units/compiler/test_memoize_plugin.py
  • uv run pytest tests/units/compiler/test_memoize_plugin.py -q
  • uv run pytest tests/units/components/datadisplay/test_dataeditor.py -q
  • Ran the docs locally at http://localhost:3030/docs/library/tables-and-data-grids/data-editor/ and verified the page renders, including the first data grid, without the Application Error / TypeError. The only console noise seen locally was unrelated Base UI nativeButton messaging from the docs shell.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 14, 2026

Merging this PR will degrade performance by 3.8%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 22 untouched benchmarks
⏩ 2 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_get_all_imports[_complicated_page] 2.8 ms 2.9 ms -4.37%
test_get_all_imports[_stateful_page] 548.2 µs 566.5 µs -3.22%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/fix-data-editor-memo-hook-props (a217b65) with main (c3c720f)2

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (39c74cb) during the generation of this report, so c3c720f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@Alek99 Alek99 marked this pull request as ready for review May 14, 2026 04:55
@Alek99 Alek99 requested a review from a team as a code owner May 14, 2026 04:55
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 14, 2026

Greptile Summary

Fixes a bug where auto-memo component modules were compiled with missing hook-mutated props because render() was called before _get_all_hooks() in the non-root-only memo path. The fix is a two-line order swap.

  • reflex/compiler/utils.py: In the else branch of compile_experimental_component_memo, _get_all_hooks() is now invoked before render() so that side-effects from add_hooks() (e.g. DataEditor wiring getCellContent) are present when the JSX tree is serialised.
  • tests/units/compiler/test_memoize_plugin.py: Adds HookGeneratedProp, a minimal stub whose add_hooks() mutates a prop, and a regression test that asserts the hook string and the wired prop both appear in the compiled memo module.

Confidence Score: 5/5

Safe to merge — the change is a two-line order swap with a direct regression test that proves the fix.

The root cause is well-understood (render captured props before add_hooks had a chance to mutate them), the fix is minimal and surgical, the if-branch (root-only memos) was already ordering hooks before render and is unaffected, and the new HookGeneratedProp stub plus its test directly exercise the fixed path end-to-end.

No files require special attention.

Important Files Changed

Filename Overview
reflex/compiler/utils.py Two-line order swap in compile_experimental_component_memo: _get_all_hooks() is now called before render() in the else branch so that add_hooks()-mutated props are visible at render time.
tests/units/compiler/test_memoize_plugin.py Adds HookGeneratedProp stub and test_auto_memo_component_renders_after_add_hooks_mutates_props to assert that hook-generated props appear in the compiled memo module output.

Sequence Diagram

sequenceDiagram
    participant CU as compile_experimental_component_memo
    participant R as render (deep copy)
    participant AH as _get_all_hooks() / add_hooks()
    participant RE as render()

    Note over CU: else branch (non-root-only memo)
    CU->>R: copy.deepcopy(definition.component)
    Note over CU,R: BEFORE fix: render() called first
    rect rgb(255,200,200)
        CU-->>RE: "rendered = render.render() ❌"
        CU-->>AH: "hooks = _get_all_hooks() ← too late"
    end
    Note over CU,R: AFTER fix: _get_all_hooks() first
    rect rgb(200,255,200)
        CU->>AH: "hooks = _get_all_hooks() ✅"
        CU->>RE: "rendered = render.render() ← sees mutated props"
    end
    CU->>R: _get_all_custom_code()
    CU->>R: _get_all_dynamic_imports()
    CU->>R: _get_all_imports()
Loading

Reviews (1): Last reviewed commit: "Fix memoized component hook prop renderi..." | Re-trigger Greptile

Copy link
Copy Markdown
Member

@adhami3310 adhami3310 left a comment

Choose a reason for hiding this comment

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

precommit isn't passing

@Alek99 Alek99 force-pushed the codex/fix-data-editor-memo-hook-props branch from 84fbe7e to a217b65 Compare May 14, 2026 06:48
@Alek99 Alek99 mentioned this pull request May 14, 2026
@Alek99 Alek99 requested a review from adhami3310 May 14, 2026 22:03
@masenf masenf merged commit 0f8c714 into main May 14, 2026
69 of 70 checks passed
@masenf masenf deleted the codex/fix-data-editor-memo-hook-props branch May 14, 2026 22:57
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.

3 participants