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

[docs] Missing Documentation for Next.js <Link> and <Image> Integration with MUI Components #45404

Open
Demianeen opened this issue Feb 25, 2025 · 3 comments
Assignees
Labels
docs Improvements or additions to the documentation status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page

Comments

@Demianeen
Copy link

Demianeen commented Feb 25, 2025

Related page

https://mui.com/material-ui/integrations/nextjs/

Kind of issue

Missing information

Issue description

Next.js has its own routing and image optimization mechanisms, but I don't see docs mentioning it. Should we add it?

Context

Building Next.js app with MUI

Search keywords: NextLink NextImage Next Link Next Image

@Demianeen Demianeen added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page labels Feb 25, 2025
@Demianeen
Copy link
Author

Demianeen commented Feb 25, 2025

For Next.js Link I currently have integration like this:

import NextLink from 'next/link'

const LinkBehaviour = forwardRef<
  HTMLAnchorElement,
  ComponentProps<typeof NextLink>
  >(function LinkBehaviour(props, ref) {
  return <NextLink ref={ref} {...props} />
})

export const theme = createTheme({
  components: {
    MuiLink: {
      defaultProps: {
      	component: LinkBehaviour,
      },
    },
})

I am not sure it will work with Button's href prop though. I also am not sure how to integrate Image properly myself. I can pass Image inside an avatar to display it but I am not sure this can be called "integration":

<Avatar>
  <Image src="/profile.jpg" alt="Profile" width={40} height={40} />
</Avatar>

@mj12albert
Copy link
Member

mj12albert commented Feb 25, 2025

We have example repos for Next.js integration, e.g. https://github.com/mui/material-ui/tree/master/examples/material-ui-nextjs-ts

Example usage of Link/NextLink is here: https://github.com/mui/material-ui/blob/master/examples/material-ui-nextjs-ts/src/app/page.tsx#L25-L27

I also am not sure how to integrate Image properly myself

AFAIK Next.js Image is just a component, Material UI doesn't have one, so there isn't anything to "integrate" like Link/NextLink

@mj12albert mj12albert added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 25, 2025
@Demianeen
Copy link
Author

Demianeen commented Feb 25, 2025

We have example repos for Next.js integration, e.g. https://github.com/mui/material-ui/tree/master/examples/material-ui-nextjs-ts

It passes it as component in one place, which mean there is huge chance that somebody will forget to change Link or Button with href to it. The issue with Link can be solved with theme. But I wonder if Button with href would render MUI Link despite Next.js defined one in theme or would it render Next.js Link. It can be beneficial to cover this in docs for example as a lot of people would just use Next.js integration guide. I personally didn't even know the example repo existed

AFAIK Next.js Image is just a component, Material UI doesn't have one, so there isn't anything to "integrate" like Link/NextLink

I mean to have the mui components use Image from next.js instead of normal img component. So, for example:

<Avatar alt="Remy Sharp" src="/static/images/avatar/1.jpg" />

Would actually render Next Image instead of default img element. Is this possible with Mui?

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Feb 25, 2025
@zannager zannager added the docs Improvements or additions to the documentation label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page
Projects
None yet
Development

No branches or pull requests

3 participants