-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ENG-8050: background event updates set final=None
#5898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENG-8050: background event updates set final=None
#5898
Conversation
When `final=None`, the frontend does not update the `event_processing` flag.
CodSpeed Performance ReportMerging #5898 will create unknown performance changesComparing Summary
Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
Changed how background event handlers and background state modifications communicate with the frontend by setting final=None instead of final=True. This prevents the frontend from updating the event_processing flag when background tasks emit state updates, allowing the event queue to continue processing without being blocked by background operations.
Key changes:
- Modified
StateUpdate.finalfrombooltobool | Noneto support a tri-state value - Background event handlers now return
final=Noneinstead offinal=Trueinreflex/state.py:1782 - Added
backgroundparameter toApp.modify_state()method to distinguish background modifications StateProxynow passesbackground=Truewhen callingmodify_state()for background operations- Frontend JavaScript now checks
if (update.final !== null)before updatingevent_processingflag
Impact:
This change ensures background tasks can update state without interfering with the frontend's event processing queue management, preventing race conditions where background updates would incorrectly signal completion of foreground events.
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The changes are well-designed and logically sound. The tri-state approach (
final=True|False|None) cleanly separates background operations from foreground event processing. The JavaScript null check is defensive and won't break existing behavior. All changes are coordinated across the frontend-backend boundary correctly. - No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| reflex/.templates/web/utils/state.js | 5/5 | Added null check for update.final before updating event_processing flag, preventing unintended flag updates from background tasks |
| reflex/state.py | 5/5 | Changed StateUpdate.final type to `bool |
| reflex/app.py | 5/5 | Added background parameter to modify_state() method to distinguish background modifications and set final=None for background updates |
| reflex/istate/proxy.py | 5/5 | Updated StateProxy to pass background=True when calling modify_state(), ensuring background state modifications are properly flagged |
Sequence Diagram
sequenceDiagram
participant Frontend as Frontend (state.js)
participant Backend as Backend (App)
participant State as BaseState
participant Proxy as StateProxy
Note over Frontend,Proxy: Background Event Handler Flow
State->>State: Process background event handler
State->>State: Set final=None (not True)
State->>Backend: Return StateUpdate(delta, final=None)
Backend->>Frontend: Emit update with final=None
Frontend->>Frontend: Check if update.final !== null
Frontend->>Frontend: Skip event_processing flag update
Note over Frontend: event_processing remains unchanged
Note over Frontend,Proxy: Background State Modification via Proxy
Proxy->>Backend: modify_state(token, background=True)
Backend->>Backend: Acquire state lock
Backend->>Proxy: Yield mutable state
Proxy->>State: Modify state
Backend->>Backend: Get delta from state
Backend->>Backend: Set final=None (background=True)
Backend->>Frontend: Emit StateUpdate(delta, final=None)
Frontend->>Frontend: Check if update.final !== null
Frontend->>Frontend: Skip event_processing flag update
Note over Frontend,Proxy: Regular Event Handler Flow
State->>State: Process regular event handler
State->>State: Set final=True
State->>Backend: Return StateUpdate(delta, final=True)
Backend->>Frontend: Emit update with final=True
Frontend->>Frontend: Check if update.final !== null
Frontend->>Frontend: Set event_processing = false
4 files reviewed, no comments
…er-resets-event-processing
When
final=None, the frontend does not update theevent_processingflag.