docs: events, storage, and component field notes#6779
Conversation
Keyboard event triggers (on_key_down/on_key_up) and global hotkeys via rx.window_event_listener (previously undocumented), memo-with-foreach patterns, enter_key_submit with its on_key_down conflict, set_clipboard with state vars, backend rx.download, on_load loading/error handling, and a local-storage positional-default note. Three stale knowledge-base claims were verified against source and rejected rather than upstreamed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR adds six documentation sections across event triggers, browser storage, special events, page-load events, text area, and memo — the fourth batch of upstreaming knowledge from the Reflex Build AI-builder knowledge base.
Confidence Score: 5/5Safe to merge — all changes are documentation additions with no functional code changes; examples have been verified against source. All six files contain only documentation additions. The examples are consistent with the described behaviors, and the three knowledge-base claims that could not be verified were explicitly excluded. The one minor inaccuracy — max_age listed as a sample keyword arg for all three storage types when it is Cookie-only — is trivially correctable and does not affect correctness elsewhere. docs/api-reference/browser_storage.md — the positional-default callout lists max_age as an example keyword for LocalStorage and SessionStorage, where it does not apply. Important Files Changed
Reviews (3): Last reviewed commit: "docs: correct the enter_key_submit / on_..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 96b2fe3316
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
|
|
||
| @rx.memo | ||
| def task_card(task: rx.Var[Task]) -> rx.Component: |
There was a problem hiding this comment.
Avoid documenting deprecated key forwarding
When users copy this rx.foreach example, the later key=... is passed to a memo that has no rx.RestProp. The runtime explicitly treats that as legacy and calls _warn_legacy_base_props when rest_param is None (packages/reflex-base/src/reflex_base/components/memo.py:1630-1643), with the deprecation message saying to declare rx.RestProp for base props (packages/reflex-base/src/reflex_base/components/memo.py:1869-1878). This doc therefore recommends a pattern that immediately emits a deprecation warning and is scheduled for removal; include and pass a RestProp while still not declaring key as an explicit prop, or call out the warning.
Useful? React with 👍 / 👎.
| The `enter_key_submit` prop is implemented with its own key down handler, so | ||
| passing both to the same component raises an error. If custom key handling is | ||
| needed, implement the Enter-to-submit behavior in your own `on_key_down` | ||
| handler instead. |
There was a problem hiding this comment.
Don't suggest on_key_down can replace enter_key_submit
In the case where a textarea also needs custom key handling, this fallback tells users to implement the Enter-submit behavior with a normal Reflex on_key_down, but the built-in implementation needs the raw JS event to call e.preventDefault() and e.target.form.requestSubmit() (packages/reflex-components-core/src/reflex_components_core/el/elements/forms.py:870-877), while the public key event only sends the key and modifier Vars to state handlers (packages/reflex-base/src/reflex_base/event/__init__.py:1028-1045). Following this advice still lets Enter insert a newline, and using .prevent_default would suppress all key input rather than only Enter, so the docs should point to a custom JS custom_attrs handler or another supported pattern.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Verified and fixed. Confirmed against the Reflex source: on_key_down uses key_event, which passes only (key, {alt/ctrl/meta/shift}) to the Python handler — the raw event is consumed and never forwarded, so preventDefault() / requestSubmit() aren't reachable and the newline would still be inserted. Corrected the note: a Python on_key_down handler can't stop the newline, and replicating Enter-to-submit with custom key handling needs a client-side handler (e.g. rx.call_script), not a plain on_key_down. Thanks for the catch.
Fourth batch of upstreaming Reflex Build's AI-builder knowledge base (#6775, #6777, and the recharts batch). Events/storage/component gaps:
on_key_down/on_key_upsections (keyboard triggers were previously undocumented) and a Global Keyboard Events section forrx.window_event_listener(also undocumented)rx.foreach(lambda + keyword args; thekeyprop forwarding — verified againstreflex_basesource)enter_key_submit, Shift+Enter behavior, and a verified warning that it can't be combined withon_key_down— raises ValueError)set_clipboardwith state Vars, backendrx.download(data=...)example,auto_scrollcross-linkNotably, three knowledge-base claims were checked against source and rejected rather than upstreamed (
rx.get_clipboarddoesn't exist;.temporaldoesn't guarantee ordering;syncisn't default-on). Pre-commit clean.🤖 Generated with Claude Code