Issue #3291075: Add option to render the alerts server-side, avoiding layout shift issues

Summary

Adds optional server-side rendering (SSR) for sitewide alerts to eliminate Cumulative Layout Shift (CLS) by rendering alerts in the initial HTML response instead of fetching them via JavaScript after page load.

Closes #3291075

Changes

  • Added server_side_render config option to render alerts in initial HTML response
  • Updated SitewideAlertRenderer to support SSR with path filtering, display ordering, and cache max-age based on scheduled alert changes
  • Added processSsrAlerts() JavaScript function to handle dismiss buttons and check localStorage for previously dismissed SSR alerts
  • Added data attributes (data-dismissible, data-dismissal-ignore-before) to alert template for JS dismiss handler attachment
  • Added update hook sitewide_alert_update_10301 for existing sites upgrading to the module

Testing

  1. Navigate to /admin/config/sitewide_alerts and enable "Render alerts server-side"
  2. Create a sitewide alert at /admin/content/sitewide_alert/add
  3. Visit the front page and verify:
    • Alert appears in the initial HTML (view page source)
    • No layout shift occurs when page loads
  4. For dismissible alerts:
    • Click the dismiss button
    • Refresh the page and verify alert stays dismissed
    • Clear localStorage and verify alert reappears
  5. For path-restricted alerts:
    • Create an alert limited to specific pages
    • Verify it only appears on those pages with SSR enabled

Additional Notes

  • SSR is disabled by default to maintain backward compatibility
  • JavaScript still handles: dismissals, automatic refresh polling, and SPA navigation
  • Cache automatically expires when scheduled alerts change (start/end times)
  • Added comprehensive kernel and functional tests for SSR functionality

By: codebymikey By: chrissnyder By: malcomio By: suryabhi By: mlncn By: rpayanm By: ibullock By: doxigo By: smustgrave By: edwardsay By: cyu By: greg boggs By: aron novak By: qusai taha By: dburiak By: mangesh.borukar By: nala-he By: mohammedodeh

Edited by Chris Snyder

Merge request reports

Loading