Repository navigation
fix(ui): eliminate cumulative layout shift in AppAlert for first-time visitors (#1452) - #1480
Open
Naveen230497 wants to merge 1 commit into
Open
Naveen230497 wants to merge 1 commit into
Naveen230497 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Eliminate Cumulative Layout Shift (CLS) in AppAlert for first-time visitors
Summary
This pull request addresses an issue where
AppAlertinitialized withuseState(false), causing the alert banner to pop into the DOM asynchronously after the initial paint onceuseEffectverified cookie state. For first-time visitors (who have no suppression cookie), this caused a noticeable Cumulative Layout Shift (CLS), abruptly shifting landing page content and images downwards.The component now initializes with
showAlert = trueso the alert is immediately present during initial render/paint, while maintaining graceful suppression when returning visitors have the snooze cookie.Related Issue
Fixes #1452
Background and Investigation
Issue #1452 reported that first-time visitors experienced an abrupt layout jump on the landing page when
AppAlertloaded.Root Cause Analysis:
AppAlertusedconst [showAlert, setShowAlert] = useState(false).showAlertwasfalse, causingAppAlertto render nothing (null).useEffectexecuted:suppressed == null),setShowAlert(true)was triggered, forcing a second render.Changes Made
1. Initialized Alert State to Visible
src/components/broadcast/AppAlert.tsx:useState(false)touseState(true).2. Preserved Suppression Behavior for Returning Visitors
useEffectcontinues to inspectCookies.get(cookieStorageKey).setShowAlert(false)dismisses the banner gracefully upon mount.3. Added Comprehensive Unit Test Suite
src/components/broadcast/__tests__/AppAlert.tsx:cookieGetter.mockReturnValue(undefined)) have the alert immediately rendered in the document without layout shift.Why This Approach?
SuppressButtoncontract.Testing and Verification
Scope and Limitations
This PR specifically stabilizes the render lifecycle of
AppAlertagainst layout shift. It does not alter the underlying banner text content or dismiss expiration logic (30 days).Future Improvements
Conclusion
Eliminates layout shift on the landing page for first-time visitors while keeping cookie-based alert suppression completely intact. Thank you to the OpenBeta team for maintaining this platform!