-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ENG-8113: handle_frontend_exception triggers auto reload #5922
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
Conversation
For configurable types of errors refresh once per configurable period in an attempt to automatically clear spurious issues when reloading.
CodSpeed Performance ReportMerging #5922 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
Greptile Summary
Added automatic page reload functionality to handle_frontend_exception for configurable error patterns. When frontend errors match entries in auto_reload_on_errors (currently targeting "TypeError: Cannot read properties of null"), the page automatically reloads once per configurable cooldown period (10 seconds) to clear spurious issues.
Key changes:
- Added
auto_reload_on_errorsClassVar to configure which error messages trigger auto-reload - Added
auto_reload_cooldown_time_msClassVar (10 seconds) to prevent reload loops - Modified
handle_frontend_exceptionto yield anEventSpecthat executes JavaScript to check sessionStorage and conditionally reload - Import
Iteratorfrom collections.abc andcall_scriptfrom reflex.event
Minor recommendations:
- Extract the sessionStorage key
'reflex_last_reloaded_on_error'into a constant - Add human-readable comment for the cooldown duration (10000ms = 10 seconds)
- Update
window.location.reload(true)towindow.location.reload()as the boolean parameter is deprecated
Confidence Score: 4/5
- This PR is safe to merge with minor style improvements recommended
- The implementation is sound with proper cooldown logic to prevent reload loops. The changes are focused and well-documented. The three style comments are minor improvements (constant extraction, time duration comment, deprecated API usage) that don't affect functionality.
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| reflex/state.py | 4/5 | Added auto-reload functionality for frontend exceptions with configurable error patterns and cooldown period. Minor style improvements recommended. |
Sequence Diagram
sequenceDiagram
participant Frontend
participant FrontendEventExceptionState
participant SessionStorage
participant Browser
Frontend->>FrontendEventExceptionState: handle_frontend_exception(info, component_stack)
FrontendEventExceptionState->>FrontendEventExceptionState: Check if error matches auto_reload_on_errors
alt Error matches and within cooldown
FrontendEventExceptionState->>SessionStorage: Get 'reflex_last_reloaded_on_error'
SessionStorage-->>FrontendEventExceptionState: Return last_reload timestamp
FrontendEventExceptionState->>FrontendEventExceptionState: Check if (now - last_reload) > cooldown_time_ms
alt Outside cooldown period
FrontendEventExceptionState->>SessionStorage: Set 'reflex_last_reloaded_on_error' to now
FrontendEventExceptionState->>Browser: Trigger window.location.reload()
Browser->>Browser: Reload page
end
end
FrontendEventExceptionState->>FrontendEventExceptionState: Call frontend_exception_handler(Exception(info))
1 file reviewed, 3 comments
For configurable types of errors refresh once per configurable period in an attempt to automatically clear spurious issues when reloading.