Use flex body layout to avoid CLS in customized themes#3931
Closed
guaca wants to merge 1 commit into
Closed
Conversation
Replace the body grid layout with a flex column layout and make .content-for-layout grow explicitly. This avoids relying on the main content being the Dawn themes to expand the wrong element during page load and trigger layout shifts.
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.
PR Summary:
Replaces Dawn's body-level grid layout with a flex column layout so the main
content-for-layoutarea grows by selector instead of relying on its position as the third direct child of<body>. This makes the layout more resilient for customized themes and prevents severe CLS when merchants add, remove, or reorder body-level elements.Why are these changes introduced?
Dawn currently lays out the page with:
This layout assumes that the page structure always maps cleanly to four body-level rows, with
content-for-layoutoccupying the1frrow. In practice, many merchant themes are customized from Dawn and may add, remove, or move direct children of<body>such as announcement bars, submenu containers, app-injected elements, drawers, or other custom markup.When
content-for-layoutis not the element that receives the1frgrid row, a different body child can be expanded during page load. For example, an announcement bar or submenu can temporarily take the available viewport height before the main content finishes rendering. Once the intended content loads and the layout recalculates, the page shifts significantly, causing poor CLS.Our team has fixed this issue several times while working directly with merchants. The recurring fix has been to move away from the body grid row-index assumption and use the same flexbox-based approach used by Horizon.
What approach did you take?
This change updates the body layout from CSS Grid to Flexbox:
It then explicitly makes the semantic main content container responsible for filling the available page height:
This removes the dependency on
content-for-layoutbeing a specific direct child of<body>. Instead, the element that should grow is targeted directly by class.Expected impact
1frrow during page load.Visual impact on existing themes
No intentional visual change is expected for unmodified Dawn layouts.
Other considerations
This change intentionally avoids relying on DOM child order for page-height behavior. The
content-for-layoutelement remains the source of truth for the expanding content region.The added
.content-for-layout > .shopify-section:last-child { flex-grow: 1; }rule preserves the ability for the last rendered section inside the main content area to fill remaining vertical space when the page content is shorter than the viewport.Decision log
.content-for-layoutdirectly for growth.content-for-layout.flex: 1oncontent-for-layout.Testing steps/scenarios
content-for-layout, causingcontent-for-layoutto no longer be the third relevant body child.Expected results
Before:
After:
No CLS issues are observed

Demo links
Checklist