fix: Textarea enter_key_submit uses add_custom_code instead of _get_all_custom_code#6485
Conversation
…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
Greptile SummaryThis PR fixes a ReferenceError where
Confidence Score: 5/5Safe 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
Sequence DiagramsequenceDiagram
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
Reviews (1): Last reviewed commit: "fix: Textarea enter_key_submit uses add_..." | Re-trigger Greptile |
Merging this PR will not alter performance
Comparing Footnotes
|
|
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.
|
Thanks for the review! I've added integration tests in |
Description
Fixes #6482: Using
enter_key_submit=Trueonrx.el.textareathrows a frontendReferenceError: enterKeySubmitOnKeyDown is not defined.Root Cause
The Textarea component's
auto_heightandenter_key_submitfeatures relied on overriding_get_all_custom_codeto inject JavaScript helper functions (autoHeightOnInputandenterKeySubmitOnKeyDown). However, the compiler's builtin plugin collects custom code via_get_custom_code()(singular) andadd_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_codeoverride with anadd_custom_codeimplementation. The parent class already mergesadd_custom_coderesults into_get_all_custom_code, so no behavior is lost for code paths that use the plural form. The compiler plugin also collectsadd_custom_codevia_iter_parent_classes_with_method, ensuring the JS functions are properly injected into compiled pages.Testing
tests/units/components/test_component.py: 122 passed,tests/units/compiler/: 158 passed)