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

[joy-ui][GlobalStyles] Ensure compatibility with RSC #38955

Merged
merged 2 commits into from
Sep 15, 2023

Conversation

mateuseap
Copy link
Contributor

Closes #38494

What I Did

In this pull request, I made the following changes:

  1. Created a new file, GlobalStyles.tsx, in the packages/mui-joy/src/GlobalStyles folder.
  2. Modified the packages/mui-joy/src/GlobalStyles/index.tsx file to export the GlobalStyles.
  3. Ran the script yarn rsc:build to insert the use client directive into the GlobalStyles.tsx file.

I followed the guidance provided by @siriwatknp in the following comment: #38494 (comment).


@mui-bot
Copy link

mui-bot commented Sep 13, 2023

Netlify deploy preview

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

@material-ui/core: parsed: +Infinity% , gzip: +Infinity%
@material-ui/lab: parsed: +Infinity% , gzip: +Infinity%
@material-ui/styles: parsed: +Infinity% , gzip: +Infinity%
@material-ui/private-theming: parsed: +Infinity% , gzip: +Infinity%
@material-ui/system: parsed: +Infinity% , gzip: +Infinity%
@material-ui/unstyled: parsed: +Infinity% , gzip: +Infinity%
@material-ui/utils: parsed: +Infinity% , gzip: +Infinity%
@mui/material-next: parsed: +Infinity% , gzip: +Infinity%
@mui/joy: parsed: +Infinity% , gzip: +Infinity%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 9a70d9a

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 13, 2023

Off-topic

This makes me wonder as we don't do it in this PR, @mj12albert why add this in #37656?

'use client';
export { default } from './GlobalStyles';

How about we remove all of those?

@mj12albert
Copy link
Member

mj12albert commented Sep 14, 2023

This makes me wonder, @mj12albert why add this in #37656?

@oliviertassinari Without 'use client' in the index file, the RSC error would occur when using named imports like import { Box } from '@mui/material'#37656 (comment)

However I tried to make a sandbox based off your PR to show this and can't reproduce that error anymore, so maybe it's no longer needed now

@oliviertassinari oliviertassinari added component: GlobalStyles The React component. package: joy-ui Specific to @mui/joy labels Sep 14, 2023
@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 15, 2023

Without 'use client' in the index file, the RSC error would occur when using named imports like import { Box } from '@mui/material' – #37656 (comment)

@mj12albert A reproduction of the issue raised in #37656 (comment): https://stackblitz.com/edit/github-9lau57-jwzhw4?file=package.json,src%2Fapp%2Fpage.tsx.

It looks like the problem was that we were missing "use client" in files that were client components, for example in @mui/base/node/FormControl/FormControlContext.js. It wasn't that the index missed "use client".

In #38967, the issue seems to be gone.

@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Sep 15, 2023
@@ -1,11 +1 @@
import * as React from 'react';
Copy link
Member

Choose a reason for hiding this comment

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

@mj12albert the index file also needs 'use client'; right?

Copy link
Member

Choose a reason for hiding this comment

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

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.

👍 Great first PR! looking forward to the next one. Thanks a lot!

@siriwatknp siriwatknp merged commit 163068d into mui:master Sep 15, 2023
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: GlobalStyles The React component. package: joy-ui Specific to @mui/joy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Joy][GlobalStyles] Does not work when used in a RSC directly
5 participants