Only replace alert DOM element when necessary

Created on 30 January 2023, over 1 year ago

Problem/Motivation

When automatic refresh of alerts is turned on, all DOM elements are replaced on every call.

I think this is undesirable, because it can cause animations and other initialization behavior to repeat. It's necessary if an alert was edited since the last refresh, but otherwise it should not be.

Steps to reproduce

Apply the patch for Issue #3337688 πŸ› removeStaleAlerts() always removes all alerts Needs review , turn on automatic site updates with a fairly frequent interval like 15 seconds, and then create at least one alert. Watch how all alerts are re-inserted to the DOM, even when they have not changed.

Proposed resolution

Use the "changed" timestamp field on alert entities to track what version of an alert was last rendered. If the timestamp matches between an existing alert DOM element and the latest alert data, do not replace/re-insert the alert markup.

API changes

No API changes specifically, but this would change the frontend behavior of the module. The event sitewide-alert-rendered will currently fire for every alert still present whenever an automatic refresh occurs. With this change, the event would only fire if the alert was not previously rendered or if it is updated to a newer version with a more recent timestamp.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bvoynick

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @bvoynick
  • @bvoynick opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States bvoynick

    MR added. Note that fix in #3337688 must also be committed for this, to fix all alerts being regarded as stale.

Production build 0.69.0 2024