fix(website-builder-react): stack Grid columns via CSS media query - #5628
Merged
Conversation
Grid column stacking was resolved in JS from the runtime viewport
breakpoint (`breakpoint === stackAtBreakpoint`) and applied as inline
styles. On SSR the breakpoint is always "desktop", so the served HTML
renders columns side-by-side and only corrects once the client
hydrates and re-resolves the breakpoint — causing a layout flash, and
staying broken entirely when the content subtree does not hydrate.
Stacking is now emitted as a scoped CSS media query in the rendered
HTML, so the browser applies it by the real viewport width with no JS,
no hydration dependency, and no flash.
- Grid renders a scoped class (`wb-grid-<id>`) plus a `<style>` block
with `@media (max-width: <breakpoint-width>) { ... }`.
- The stack width is read from the theme's breakpoint definition.
- ContentSdk now populates `viewportManager` breakpoints on the server
too (the resize listener stays client-only), so SSR has the real
widths to generate the media query.
- String/CSS building lives in `gridStyles.ts`, not the component.
Scope: Grid stacking only. Per-breakpoint styles/content for other
elements are follow-ups.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
Grid column stacking is resolved in JS from the runtime viewport breakpoint (
breakpoint === stackAtBreakpoint) and applied as inline styles.On SSR the breakpoint is always
desktop, so the served HTML renders columns side-by-side and only corrects once the client hydrates and re-resolves the breakpoint. That causes a layout flash — and stays broken entirely when the content subtree doesn't hydrate (e.g. content rendered vianext/dynamic({ssr:true})), which is how this surfaced on an OpenNext/SSG frontend: a grid set to stack at mobile stayed 2-column at mobile width.Fix
Emit stacking as a scoped CSS media query in the rendered HTML, so the browser applies it by the real viewport width — no JS, no hydration dependency, no flash.
wb-grid-<element.id>plus a<style>block:ContentSdk.initnow populatesviewportManagerbreakpoints on the server too (the resize listener stays client-only), so SSR has the real widths to generate the media query.gridStyles.ts(createGridClass,createGridStackingCss), not inline in the component.Scope
Grid stacking only. Multiple grids and nested grids are safe (unique per-id class + direct-child combinator). Deliberately out of scope, as follow-ups:
rowGap/columnGap, spacing, visibility) — same JS→@mediatreatment, generalized.<picture>/srcset).draftModebehavior (orthogonal bugs).Testing
@mediablock is present in the SSR HTML and the browser stacks columns at the breakpoint width with no client JS (content subtree not hydrated).Known follow-ups before merge
createGridClass/createGridStackingCss.🤖 Generated with Claude Code