Skip to content

[Bug]: TopNavigation size changes after SSR hydration #3337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
TrevorBurnham opened this issue Mar 6, 2025 · 5 comments · May be fixed by #3371
Closed
2 tasks done

[Bug]: TopNavigation size changes after SSR hydration #3337

TrevorBurnham opened this issue Mar 6, 2025 · 5 comments · May be fixed by #3371
Labels
bug Something isn't working

Comments

@TrevorBurnham
Copy link

Browser

No response

Package version

v3.0.913

React version

v18.3.1

Description

On my page that uses SSR, I noticed that the top navigation immediately resized after pageload, going from a "narrow" mode to a larger style:

Top navigation changing size after pageload

I also noticed that the class awsui_narrow_k5dlb_2ayr9_187 was attached to the top navigation in the page source, but removed after the page's JS executed.

I believe this code is responsible for the issue.

Deferring the breakpoint logic until the code runs on the client wouldn't solve the issue, since there could still be a mismatch between the appearance of the component as rendered in SSR and its appearance on the client. I believe the best solution would be to use CSS media queries instead of JavaScript to implement the breakpoint-based appearance modifiers.

Source code

No response

Reproduction

Render the top navigation with SSR and open in a desktop browser. When I noticed the issue, my browser viewport was 1024x wide.

Code of Conduct

@TrevorBurnham TrevorBurnham added the bug Something isn't working label Mar 6, 2025
@orangevolon
Copy link
Member

Hey @TrevorBurnham, thanks for lettings us know. We'll review your request and keep you posted if an update is available.

@YueyingLu
Copy link
Member

Hey @TrevorBurnham
thanks for the request, unfortunately our team can not prioritize the fixing TopNavigation SSR at the moment. I will close this request as we can not take actions in the short term future.

@TrevorBurnham
Copy link
Author

Would you accept a PR for this? I’m happy to contribute, but I could use more context on why the responsive behavior is currently implemented with JS instead of CSS.

@YueyingLu
Copy link
Member

Hey @TrevorBurnham
Contribution is welcome. At the time we created the TopNav we used JS for element queries. You can try to use media queries for your change.

TrevorBurnham added a commit to TrevorBurnham/cloudscape-components that referenced this issue Mar 24, 2025
This commit switches from JavaScript-based breakpoints to CSS container
queries for TopNavigation, making its appearance consistent when
rendered with SSR.

To support container queries, we need `container-type: inline-size;` on
the TopNavigation root element. This causes overflowing content to get
clipped (at least in Safari), so I've enabled `expandToViewport` to
render utility dropdowns in a portal. Note that OverflowMenu doesn't
need this treatment because it expands the height of TopNavigation
rather than overflowing.

Fixes cloudscape-design#3337
@TrevorBurnham
Copy link
Author

I've submitted a PR to fix this issue: #3371

pan-kot pushed a commit that referenced this issue Mar 26, 2025
This commit switches from JavaScript-based breakpoints to CSS container
queries for TopNavigation, making its appearance consistent when
rendered with SSR.

To support container queries, we need `container-type: inline-size;` on
the TopNavigation root element. This causes overflowing content to get
clipped (at least in Safari), so I've enabled `expandToViewport` to
render utility dropdowns in a portal. Note that OverflowMenu doesn't
need this treatment because it expands the height of TopNavigation
rather than overflowing.

Fixes #3337
TrevorBurnham added a commit to TrevorBurnham/cloudscape-components that referenced this issue Mar 26, 2025
This commit switches from JavaScript-based breakpoints to CSS container
queries for TopNavigation, making its appearance consistent when
rendered with SSR.

To support container queries, we need `container-type: inline-size;` on
the TopNavigation root element. This causes overflowing content to get
clipped (at least in Safari), so I've enabled `expandToViewport` to
render utility dropdowns in a portal. Note that OverflowMenu doesn't
need this treatment because it expands the height of TopNavigation
rather than overflowing.

Fixes cloudscape-design#3337
TrevorBurnham added a commit to TrevorBurnham/cloudscape-components that referenced this issue Mar 31, 2025
This commit switches from JavaScript-based breakpoints to CSS container
queries for TopNavigation, making its appearance consistent when
rendered with SSR.

To support container queries, we need `container-type: inline-size;` on
the TopNavigation root element. This causes overflowing content to get
clipped (at least in Safari), so I've enabled `expandToViewport` to
render utility dropdowns in a portal. Note that OverflowMenu doesn't
need this treatment because it expands the height of TopNavigation
rather than overflowing.

Fixes cloudscape-design#3337
pan-kot pushed a commit that referenced this issue Apr 2, 2025
This commit switches from JavaScript-based breakpoints to CSS container
queries for TopNavigation, making its appearance consistent when
rendered with SSR.

To support container queries, we need `container-type: inline-size;` on
the TopNavigation root element. This causes overflowing content to get
clipped (at least in Safari), so I've enabled `expandToViewport` to
render utility dropdowns in a portal. Note that OverflowMenu doesn't
need this treatment because it expands the height of TopNavigation
rather than overflowing.

Fixes #3337
TrevorBurnham added a commit to TrevorBurnham/cloudscape-components that referenced this issue Apr 5, 2025
This commit switches from JavaScript-based breakpoints to CSS container
queries for TopNavigation, making its appearance consistent when
rendered with SSR.

To support container queries, we need `container-type: inline-size;` on
the TopNavigation root element. This causes overflowing content to get
clipped (at least in Safari), so I've enabled `expandToViewport` to
render utility dropdowns in a portal. Note that OverflowMenu doesn't
need this treatment because it expands the height of TopNavigation
rather than overflowing.

Fixes cloudscape-design#3337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants