Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Masonry] Component is not rendered correctly with SSR #32688

Closed
2 tasks done
ammar-oker opened this issue May 8, 2022 · 5 comments
Closed
2 tasks done

[Masonry] Component is not rendered correctly with SSR #32688

ammar-oker opened this issue May 8, 2022 · 5 comments
Assignees
Labels
component: masonry This is the name of the generic UI component, not the React module!

Comments

@ammar-oker
Copy link

ammar-oker commented May 8, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

The Masonry component from @mui/lab package is not rendered correctly on the server side. Therefore when JavaScript is disabled on the client, it's not rendered.

Initially, it will render one column despite the value of the column prop. After hydration is done, it'll show the correct number of columns.

The main issue here is the layout shifting during the client-side rendering.

Expected behavior 馃

When using the Masonry component from @mui/lab package, I expect it to be fully rendered on the server-side.

Steps to reproduce 馃暪

Steps:

  1. In a Next.js project, set up mui with emotion engine.
  2. Install mui/lab package and import Masonry component.
  3. Use the Masonry component and set the column prop to a fixed number (e.g. 3).
  4. Build your project and run a production env.
  5. Disable javascript in the browser.
  6. You will see the Masonry component rendered with one column.

Context 馃敠

I'm trying to implement a Masonry fully rendered on the server without any client-side rendering to avoid layout shifting.

Your environment 馃寧

My browser is Chrome 101.0.4951.54

`npx @mui/envinfo`
  System:
    OS: macOS 12.2.1
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.14.0/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  Browsers:
    Chrome: 101.0.4951.54
    Safari: 15.3
  npmPackages:
    @emotion/react: ^11.9.0 => 11.9.0 
    @emotion/styled: ^11.8.1 => 11.8.1 
    @mui/base:  5.0.0-alpha.79 
    @mui/icons-material: ^5.6.2 => 5.6.2 
    @mui/lab: ^5.0.0-alpha.80 => 5.0.0-alpha.80 
    @mui/material: ^5.6.4 => 5.6.4 
    @mui/private-theming:  5.6.2 
    @mui/styled-engine:  5.6.1 
    @mui/system:  5.6.4 
    @mui/types:  7.1.3 
    @mui/utils:  5.6.1 
    @mui/x-date-pickers:  5.0.0-alpha.0 
    @types/react: 18.0.8 => 18.0.8 
    react: ^18.1.0 => 18.1.0 
    react-dom: ^18.1.0 => 18.1.0 
    typescript: 4.6.4 => 4.6.4 
@ammar-oker ammar-oker added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 8, 2022
@ammar-oker
Copy link
Author

created a minimal reproduction repo
馃憠 https://github.com/ammar-oker/mui-issue-32688-reproduction

@degitgitagitya

This comment was marked as duplicate.

@danilo-leal danilo-leal changed the title @mui/lab Masonry Component is Not Rendered Correctly With SSR [Masonry] Component is not rendered correctly with SSR May 10, 2022
@danilo-leal danilo-leal added the component: masonry This is the name of the generic UI component, not the React module! label May 10, 2022
@mnajdova
Copy link
Member

Did you check https://mui.com/material-ui/react-masonry/#server-side-rendering There is more setup needed in order for SSR to work. cc @hbjORbj can provide more info (e.g. link some PR/RFC etc)

@mnajdova mnajdova removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 17, 2022
@ammar-oker
Copy link
Author

Setting the defaultHeight and defaultColumns solved the issue. Thanks for your assistance!

@noahehall
Copy link

setting default* props fixes layout issues in non-ssr contexts as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: masonry This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

6 participants