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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[utils] Support RSC in isMuiElement util #38129

Merged
merged 11 commits into from
Sep 25, 2023
Merged

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Jul 24, 2023

@sai6855 sai6855 closed this Jul 24, 2023
@mui-bot
Copy link

mui-bot commented Jul 24, 2023

Netlify deploy preview

https://deploy-preview-38129--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 738b27e

@sai6855 sai6855 reopened this Jul 30, 2023
@sai6855 sai6855 changed the title [Select][Joy] Add listbox placement demo for Select [Grid][System] Fix nested grid logic parent component is server component Jul 31, 2023
@sai6855 sai6855 changed the title [Grid][System] Fix nested grid logic parent component is server component [Grid][System][RSC] Fix nested grid logic parent component is server component Jul 31, 2023
@sai6855 sai6855 changed the title [Grid][System][RSC] Fix nested grid logic parent component is server component [Grid][System][RSC] Fix nested grid logic when parent component is server component Jul 31, 2023
@sai6855 sai6855 changed the title [Grid][System][RSC] Fix nested grid logic when parent component is server component [Grid][System][RSC] Fix nested grid logic Jul 31, 2023
packages/mui-system/src/Unstable_Grid/createGrid.tsx Outdated Show resolved Hide resolved
React.isValidElement(child) &&
(isMuiElement(child, ['Grid']) ||
// eslint-disable-next-line no-underscore-dangle
(child.type as any)?._payload?.value?.muiName === 'Grid')
Copy link
Member

@mj12albert mj12albert Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works for me in a sandbox: https://codesandbox.io/p/sandbox/https-github-com-mui-material-ui-issues-37932-forked-qtf5j2?file=%2Fapp%2Fclient%2Fpage.tsx%3A9%2C1 (I gave the CI a kick)

Maybe we could add this additional check directly inside isMuiElement? It does increase the scope of the PR but so far only 8 Joy UI components (in addition to Grid) uses this

Without it other issues occur in a Next.js server component page when it's used, e.g. this usage of Joy UI Typography + Skeleton – In the /server page, the Skeleton doesn't show without manually adding the variant prop: https://codesandbox.io/p/sandbox/https-github-com-mui-material-ui-pull-38129-forked-93y266?file=%2Fapp%2Fserver%2Fpage.tsx%3A15%2C1 CC @siriwatknp & @brijeshb42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue could be automatically fixed if logic is moved to isMuiElement function. #38791

Copy link
Contributor

@brijeshb42 brijeshb42 Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the _payload object come from? Is it related to generic server rendered component or is it specific to nextjs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure from where _payload is coming. searched both nextjs and react docs neither of them have any info on this.

The most relavent info i could find in nextjs docs is this : https://nextjs.org/docs/app/building-your-application/rendering/server-components#how-are-server-components-rendered

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably related to this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, so it's react related

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sai6855 I think it's better to fix the isMuiElement util in this case. As a note, the muiName should be replaced with CSS (likely :has selector) but the browser support is not wide enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please add a comment about child.type as any)?._payload?.value?.muiName === 'Grid' with the link @brijeshb42 pointed to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@siriwatknp made suggested changes

@sai6855 sai6855 force-pushed the placement-demo branch 2 times, most recently from 8802d98 to 6ff8b11 Compare September 23, 2023 11:23
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mnajdova
Copy link
Member

The changes looks good, however, please rename the title to match more specifically the changes done.

@sai6855 sai6855 changed the title [Grid][System][RSC] Fix nested grid logic [utils] support RSC in isMuiElement util Sep 25, 2023
@sai6855 sai6855 changed the title [utils] support RSC in isMuiElement util [utils] support RSC in isMuiElement util Sep 25, 2023
@siriwatknp siriwatknp merged commit bd446ad into mui:master Sep 25, 2023
6 checks passed
@mnajdova mnajdova changed the title [utils] support RSC in isMuiElement util [utils] Support RSC in isMuiElement util Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Grid The React component. nextjs package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Grid][RSC] Nested Grid doesn't work when the parent component is a server component
8 participants