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

[core] Prepend "use-client" directive + add docs and examples for using MUI libraries with Next.js App Router #37656

Merged
merged 84 commits into from
Jul 11, 2023

Conversation

mj12albert
Copy link
Member

@mj12albert mj12albert commented Jun 20, 2023

Closes 37503

This PR adds the "use-client" directive to components/hooks exported from core libraries, and a CI step to check it.

Here's a basic demo with some @mui/material components with (using default imports) working in Next.js 13's app dir, ThemeProvider is not used, no (additional) use client directives are needed in page or layout files.

Here's the same one but using named imports – turns out 'use client' is needed on all the index.js|ts to make this work.

Summary of other changes:

  • Added guides on how to set up and use MUI libraries with Next 13
  • Updated the Material UI/Next 13 example - built out the layout and page, and simplified the project structure to be a bit closer to the output of create-next-app
  • Added examples for Joy UI and Base UI with Next 13
  • Material UI's umd build is built with rollup which ignores use client, but based on the CDN example I think it shouldn't matter (there is no server environment)
  • The @mui/icons-material build script needs to be run and changes committed, but I will do it in a separate PR (it results in 20k+ changed files and will make the GitHub UI lag like no tomorrow)

To try out the new example repos, replace the @mui packages from package.json with the latest version built by CI:

 "dependencies": {
-  "@mui/material": "latest",
-  "@mui/base": "latest",
-  "@mui/joy": "latest",
+  "@mui/material": "https://pkg.csb.dev/mui/material-ui/commit/0fb89e43/@mui/material",
+  "@mui/base": "https://pkg.csb.dev/mui/material-ui/commit/0fb89e43/@mui/base",
+  "@mui/joy": "https://pkg.csb.dev/mui/material-ui/commit/0fb89e43/@mui/joy",
 },

@mj12albert mj12albert added the core Infrastructure work going on behind the scenes label Jun 20, 2023
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

This looks like a great start! I would recommend including the @mui/material-next and @mui/system packages too. Would be interesting to investigate if we have a component or hook that support RSC, so that we can add logic in the script to skip some files.

@mj12albert mj12albert force-pushed the prepend-client-directive branch 6 times, most recently from 5183455 to c3202bc Compare June 29, 2023 09:11
@mj12albert mj12albert force-pushed the prepend-client-directive branch 9 times, most recently from b5f6d4a to 5055d4d Compare July 3, 2023 05:21
@mj12albert mj12albert changed the title Prepend client directive [core] Prepend use-client directive + add docs and examples for using MUI libraries with Next.js App Router Jul 3, 2023
@mj12albert mj12albert marked this pull request as ready for review July 3, 2023 10:36
@mj12albert mj12albert changed the title [core] Prepend use-client directive + add docs and examples for using MUI libraries with Next.js App Router [core] Prepend "use-client" directive + add docs and examples for using MUI libraries with Next.js App Router Jul 3, 2023
@mj12albert
Copy link
Member Author

This looks like a great start! I would recommend including the @mui/material-next and @mui/system packages too. Would be interesting to investigate if we have a component or hook that support RSC, so that we can add logic in the script to skip some files.

Updated the packages covered here!

I will look into enhancing the script in a separate PR - while testing the changes so far I found that some functions (e.g. our styled) need the directive too for some components to work, so it may end up we can't simply reuse findComponents and findHooks 😅

Copy link
Member

@samuelsycamore samuelsycamore left a comment

Choose a reason for hiding this comment

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

Docs review here. This was a massive undertaking! Thanks for owning it @mj12albert ! Mostly copy edits here but also some bigger picture questions scattered around. I'll circle back to the actual examples later.

@mj12albert mj12albert mentioned this pull request Jul 11, 2023
1 task
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 work @mj12albert

@siriwatknp siriwatknp merged commit a4afa9f into mui:master Jul 11, 2023
21 checks passed
Comment on lines +16 to +35
display: 'flex',
}}
>
<Box>
<Alert severity="info" sx={{ mt: 2, mb: 5 }}>
<AlertTitle>Hello 👋</AlertTitle>
This app uses the Next.js App Router and Material UI v5.
</Alert>

<Grid container rowSpacing={3} columnSpacing={3}>
<Grid xs={6}>
<MediaCard
heading="CMYK"
text="The CMYK color model (also known as process color, or four color) is a subtractive color model, based on the CMY color model, used in color printing, and is also used to describe the printing process itself."
/>
</Grid>
<Grid xs={6}>
<MediaCard
heading="HSL and HSV"
text="HSL (for hue, saturation, lightness) and HSV (for hue, saturation, value; also known as HSB, for hue, saturation, brightness) are alternative representations of the RGB color model, designed in the 1970s by computer graphics researchers."
Copy link
Member

Choose a reason for hiding this comment

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

I imagine this change was helpful to test the whole PR end-to-end but examples are not templates. Could we revert these changes? Thanks

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to circle back to a conversation we had a couple months ago about standardizing the layout for boilerplate examples. cc @danilo-leal

Copy link
Member

Choose a reason for hiding this comment

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

Next.js approach makes a lot of sense for me, once the setup works, they link you a template https://vercel.com/templates?framework=next.js.

@samuelsycamore I believe we already have a standard layout, do you mean improving it and enforcing it to all the examples?

Copy link
Member

Choose a reason for hiding this comment

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

Yep that's the idea, standardize something a little more neat and polished like the pretty startup pages used by Vercel, Vite, etc. (Mainly just about reinforcing our branding)

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding to the list ⎯ I think this adds tons of value! 👍 Also, having a global "Templates" page, complementary to the individual ones found in each product's docs, also looks like a good idea!

Copy link
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes nextjs
Projects
Status: Recently completed