Skip to content

internal: Make the Demo Form Accept Extra on_submit Handlers#6486

Merged
amsraman merged 1 commit into
mainfrom
aditya/demo-form-extra-submit
May 11, 2026
Merged

internal: Make the Demo Form Accept Extra on_submit Handlers#6486
amsraman merged 1 commit into
mainfrom
aditya/demo-form-extra-submit

Conversation

@amsraman
Copy link
Copy Markdown
Contributor

@amsraman amsraman commented May 11, 2026

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.

b. Describe your changes.

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).

@amsraman amsraman requested a review from a team as a code owner May 11, 2026 18:45
@amsraman amsraman changed the title (internal) Make the Demo Form Accept Extra on_submit Handlers internal: Make the Demo Form Accept Extra on_submit Handlers May 11, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 11, 2026

Greptile Summary

This PR exposes an on_submit parameter on demo_form and demo_form_dialog so callers can append extra event handlers after the built-in PostHog-tracking and dialog-close handlers.

  • Both public functions (demo_form, demo_form_dialog) gain an on_submit: EventType[dict[str, Any]] | None parameter, properly documented and typed.
  • The handler is normalised into a list via an isinstance(on_submit, list) check, then spread into the existing on_submit list after the two built-in handlers.

Confidence Score: 3/5

The change is small and well-scoped, but the handler-normalisation logic only recognises Python lists, so callers who pass a tuple of handlers will have their handlers silently mis-applied.

The normalization expression uses isinstance(on_submit, list) to detect multi-handler input, but Reflex also accepts tuples as multi-handler sequences. A tuple passed here skips the branch and gets wrapped as a single element, meaning the individual handlers inside it are never registered separately — a silent functional failure for any caller who uses tuple syntax.

packages/reflex-components-internal/src/reflex_components_internal/blocks/demo_form.py — specifically the extra_on_submit normalisation block (lines 294–296).

Important Files Changed

Filename Overview
packages/reflex-components-internal/src/reflex_components_internal/blocks/demo_form.py Adds optional on_submit pass-through to both demo_form and demo_form_dialog; the list-normalization logic doesn't handle tuples, which Reflex accepts as multi-handler sequences.

Sequence Diagram

sequenceDiagram
    actor User
    participant Form as rx.el.form
    participant PostHog as DemoFormStateUI.track_demo_form_posthog
    participant Dialog as demo_form_open_cs (ClientState)
    participant Extra as extra_on_submit handlers

    User->>Form: Submit
    Form->>PostHog: on_submit[0] — PostHog track
    PostHog-->>Form: done
    Form->>Dialog: on_submit[1] — set_value(False) → close dialog
    Dialog-->>Form: done
    Form->>Extra: on_submit[2..n] — caller-provided handlers
    Extra-->>Form: done
Loading

Reviews (1): Last reviewed commit: "Internal Demo Form accepts extra on_subm..." | Re-trigger Greptile

Comment on lines +294 to +296
extra_on_submit = (
on_submit if isinstance(on_submit, list) else [on_submit] if on_submit else []
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 isinstance check doesn't handle tuple event-handler lists

Reflex allows event handler collections to be passed as either a list or a tuple. If a caller passes on_submit as a tuple (e.g., on_submit=(HandlerA, HandlerB)), isinstance(on_submit, list) returns False, so the entire tuple is wrapped in another list as a single element — meaning *extra_on_submit spreads (HandlerA, HandlerB) as one item instead of two separate handlers. Reflex would then try to interpret the tuple as a single handler and likely raise a runtime error or silently ignore it.

Suggested change
extra_on_submit = (
on_submit if isinstance(on_submit, list) else [on_submit] if on_submit else []
)
extra_on_submit = (
list(on_submit)
if isinstance(on_submit, (list, tuple))
else [on_submit]
if on_submit
else []
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

tuples aren't accepted as part of that type, right?

@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 aditya/demo-form-extra-submit (e6e249e) 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.

@amsraman amsraman merged commit 34f0dc9 into main May 11, 2026
69 checks passed
@amsraman amsraman deleted the aditya/demo-form-extra-submit branch May 11, 2026 19:00
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.

2 participants