Refactor: Only reload Main/Dash on visibility if Live Updates disabled#2181
Conversation
WalkthroughThe changes update the JavaScript logic in the PHP template to conditionally include or exclude event handlers for window focus, blur, and document visibility changes based on the live update configuration. Event handlers for pausing and resuming live updates are now only present when live updates are disabled. The visibility change handler is also adjusted to differentiate its behavior depending on whether live updates are enabled or disabled, modifying when updates are paused, resumed, or the page is reloaded. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Browser
participant PHP Template (DefaultPageLayout.php)
participant LiveUpdate Logic
Note over PHP Template: On page render
PHP Template->Browser: Output JS with/without event handlers based on liveUpdate setting
alt liveUpdate == "no"
Browser->Browser: On window focus: call nchanFocusStart()
Browser->Browser: On window blur: set timer, call nchanFocusStop()
Browser->Browser: On visibilitychange (hidden): call nchanFocusStop()
Browser->Browser: On visibilitychange (visible): (no action)
else liveUpdate != "no"
Browser->Browser: On visibilitychange (hidden): call nchanFocusStop()
Browser->Browser: On visibilitychange (visible): call nchanFocusStart() or reload page (if timer set)
end
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
emhttp/plugins/dynamix/include/DefaultPageLayout.php (1)
1295-1363: Improved UX by conditionally handling window events based on live update settingThis refactoring correctly implements the PR objective by wrapping window focus/blur and visibility change event handlers in a PHP conditional that only includes them when live updates are disabled. This prevents unnecessary page reloads when live updates are already enabled, resulting in a more consistent user experience.
Consider adding a brief comment explaining the conditional behavior to help future maintainers understand the intent, such as:
// Only include window focus/blur event handlers when live updates are disabled // to prevent unnecessary page reloads when live updates are already handling data refreshes <? if ( $display['liveUpdate'] == "no" ):?>
Summary by CodeRabbit