Skip to content

fix: Textarea enter_key_submit uses add_custom_code instead of _get_all_custom_code#6485

Merged
masenf merged 2 commits into
reflex-dev:mainfrom
algojogacor:fix/textarea-enter-key-submit-custom-code
May 11, 2026
Merged

fix: Textarea enter_key_submit uses add_custom_code instead of _get_all_custom_code#6485
masenf merged 2 commits into
reflex-dev:mainfrom
algojogacor:fix/textarea-enter-key-submit-custom-code

Conversation

@algojogacor
Copy link
Copy Markdown
Contributor

Description

Fixes #6482: Using enter_key_submit=True on rx.el.textarea throws a frontend ReferenceError: enterKeySubmitOnKeyDown is not defined.

Root Cause

The Textarea component's auto_height and enter_key_submit features relied on overriding _get_all_custom_code to inject JavaScript helper functions (autoHeightOnInput and enterKeySubmitOnKeyDown). However, the compiler's builtin plugin collects custom code via _get_custom_code() (singular) and add_custom_code(), not _get_all_custom_code() (plural). This caused both JS functions to be missing from compiled pages.

Fix

Replace the _get_all_custom_code override with an add_custom_code implementation. The parent class already merges add_custom_code results into _get_all_custom_code, so no behavior is lost for code paths that use the plural form. The compiler plugin also collects add_custom_code via _iter_parent_classes_with_method, ensuring the JS functions are properly injected into compiled pages.

Testing

  • All existing unit tests pass (tests/units/components/test_component.py: 122 passed, tests/units/compiler/: 158 passed)

…ll_custom_code

The Textarea component's auto_height and enter_key_submit features relied on
overriding _get_all_custom_code to inject JavaScript helper functions. However,
the compiler's builtin plugin collects custom code via _get_custom_code (singular)
and add_custom_code, not _get_all_custom_code (plural). This caused both
autoHeightOnInput and enterKeySubmitOnKeyDown to be missing from compiled pages,
resulting in ReferenceError at runtime.

Fix by implementing add_custom_code (the intended mechanism for injecting
module-level JS) and removing the _get_all_custom_code override, since the
parent class already merges add_custom_code results into _get_all_custom_code.

Fixes reflex-dev#6482
@algojogacor algojogacor requested a review from a team as a code owner May 11, 2026 17:56
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 11, 2026

Greptile Summary

This PR fixes a ReferenceError where enterKeySubmitOnKeyDown and autoHeightOnInput were missing from compiled pages when the enter_key_submit or auto_height props were set on rx.el.textarea. The compiler plugin collects custom code via add_custom_code through _iter_parent_classes_with_method, not from _get_all_custom_code overrides, so the old override was silently ignored.

  • Replaces the _get_all_custom_code override in Textarea with an add_custom_code implementation, matching the pattern used by other components such as plotly.py and dataeditor.py.
  • The fix preserves the None-guard logic so the JS snippets are only appended when the relevant prop is actually set on the component instance.

Confidence Score: 5/5

Safe to merge — the change is a targeted one-method swap in a single file, the new method matches the pattern already used by other components in the repo, and the base class explicitly documents that add_custom_code implementations do not need to call super().

The old _get_all_custom_code override was dead code with respect to the compiler plugin; replacing it with add_custom_code is the correct fix and introduces no new logic, only routes the same JS strings through the correct collection path.

No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-components-core/src/reflex_components_core/el/elements/forms.py Switches Textarea from overriding _get_all_custom_code to implementing add_custom_code, matching the pattern expected by the compiler's builtin plugin and correctly injecting the AUTO_HEIGHT_JS and ENTER_KEY_SUBMIT_JS helpers.

Sequence Diagram

sequenceDiagram
    participant Compiler as Compiler (builtin plugin)
    participant Component as Component._get_all_custom_code
    participant Textarea as Textarea

    Note over Compiler,Textarea: Before fix (broken)
    Compiler->>Component: _get_all_custom_code()
    Component-->>Compiler: collects _get_custom_code() + add_custom_code()
    Note right of Textarea: _get_all_custom_code() override never reached by compiler

    Note over Compiler,Textarea: After fix (correct)
    Compiler->>Component: _get_all_custom_code()
    Component->>Component: _iter_parent_classes_with_method(add_custom_code)
    Component->>Textarea: add_custom_code(self)
    Textarea-->>Component: [AUTO_HEIGHT_JS, ENTER_KEY_SUBMIT_JS]
    Component-->>Compiler: merged dict with JS helpers
Loading

Reviews (1): Last reviewed commit: "fix: Textarea enter_key_submit uses add_..." | Re-trigger Greptile

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 11, 2026

Merging this PR will not alter performance

✅ 24 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing algojogacor:fix/textarea-enter-key-submit-custom-code (6913023) with main (56da91a)

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.

@FarhanAliRaza
Copy link
Copy Markdown
Contributor

I think we need to add a test for it.

…tion

Add unit tests asserting the JS helpers are emitted via add_custom_code,
plus a Playwright regression test for the enter_key_submit behavior.
Tighten the add_custom_code docstring.
@masenf masenf merged commit bc434f7 into reflex-dev:main May 11, 2026
69 checks passed
@algojogacor
Copy link
Copy Markdown
Contributor Author

Thanks for the review! I've added integration tests in test_textarea_enter_key_submit.py and unit tests in test_form.py covering both the enter_key_submit and auto_height custom code injection. All CI checks are passing. Let me know if you'd like any changes.

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.

Textarea enter_key_submit references undefined enterKeySubmitOnKeyDown

3 participants