material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[core] Remove `'use client'` from index files and useAutocomplete reexport

Open DiegoAndai opened this issue 1 year ago • 3 comments

Remove 'use client' from:

  • index files
  • useAutocomplete material-ui reexport file. This required a minor modification of the buildRsc script.

This is to avoid an issue with Next.js that surfaced in https://github.com/mui/material-ui/pull/41596:

Error: It's currently unsupported to use "export *" in a client boundary. Please use named exports instead.

Also suggested in https://github.com/mui/material-ui/pull/40358#issuecomment-1872254225. There's no use of 'use client' in index files.

DiegoAndai avatar Apr 18 '24 18:04 DiegoAndai

Netlify deploy preview

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

Bundle size report

Details of bundle changes (Toolpad) Details of bundle changes

Generated by :no_entry_sign: dangerJS against 32d0f0a671c430e6ec76e655261c38c23adde505

mui-bot avatar Apr 18 '24 18:04 mui-bot

Nice, a continuation of https://github.com/mui/material-ui/pull/40663.

I'm confused to why Next.js can't properly handle "use client" in barrel files, it sounds off. But in any cases, it makes sense to me to toggle between client and server bundles at the lowest possible level.

I proposed the same change for Base UI: https://github.com/mui/base-ui/issues/330

oliviertassinari avatar Apr 19 '24 16:04 oliviertassinari

@DiegoAndai I'm adding the following to the no-restricted-syntax rule in eslint to prevent the pattern from re-entering in the future:

{
  message: "The 'use client' pragma can't be used with export * in the same module. This is not supported by Next.js.",
  selector: 'ExpressionStatement[expression.value="use client"] ~ ExportAllDeclaration',
},

Janpot avatar Aug 28 '24 07:08 Janpot

Thanks @Janpot 😊

DiegoAndai avatar Aug 28 '24 16:08 DiegoAndai