Skip to content

rx.upload_files() from a toast action or call_script callback throws "ReferenceError: filesById is not defined" (the scenario #7156's changelog names) #7244

Closed

Description

@masenf

Describe the bug

#7156 fixed the event ordering so that a toast action or a rx.call_script callback can trigger an upload handler: the compiled event is now ReflexEvent("...cb.handle_upload", {...}, {}, "uploadFiles"). But the payload still emits files: filesById?.["u2"], and const [filesById, setFilesById] = useContext(UploadFilesContext) is hoisted only into the component that renders rx.upload. A sonner action/cancel onClick and the eval'd backend callback in .web/utils/state.js (applyEvent) run outside that component, so the reference is undefined, no upload request is sent and the handler never runs.

The documented pattern works: rx.upload(id="u3") plus a sibling rx.button(on_click=UB.handle(rx.upload_files(upload_id="u3"))), or the same button nested inside rx.upload.

To Reproduce

Page with an rx.upload(id="u2") zone and:

# (a) toast action, fired from a frontend trigger and also yielded from a backend handler
rx.toast("...", action={"label": "Upload", "on_click": CB.handle_upload(rx.upload_files(upload_id="u2"))})
# (b) call_script callback
rx.call_script("1", callback=lambda v: CB.handle_upload(rx.upload_files(upload_id="u2")))

Select a file in the u2 zone, click the action / trigger the callback.

Observed behavior

Console: ReferenceError: filesById is not defined (an uncaught page error for both toast variants, _call_script ReferenceError for the callback). No upload request; the handler's uploaded list stays empty.

Expected behavior

The handler receives the files, as the reflex-base 0.9.12 changelog line for #7156 states ("a rx.call_script callback or toast action triggering an upload handler … handlers like uploadFiles never ran"). Either propagate the UploadFilesContext hook/VarData to the callback sites, or reword that changelog line and the toast docs so nobody ships action= + rx.upload_files.

Specifics

  • Python 3.11.15
  • Reflex 0.9.12a1 (reflex-base 0.9.12a1); not a regression: 0.9.11.post1 fails too (the frontend-fired toast dies earlier on queueEvents is not defined, the backend-yielded toast fails with the identical filesById error)
  • Linux, Chromium

Additional context

0.9.12a1 pre-release QA, FINDING-015, confirmed by an adversarial verifier (MEDIUM). Evidence in event_loop/: elapp page /callback, out/callback.txt cases 6, 8, 9, out/callback.errors.txt, verification/out_dev12/callback.*, verification/out_prev/callback.stdout.txt; working control /upbtn in verification/elapp_with_upbtn_page.py. Full write-up: FINDINGS.md.

Activity

  1. added theissue type on Sep 22, 2026
  2. linear-code commented on Sep 22, 2026

    @linear-code
  3. added
    release-train
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    release-train

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions