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

react-refresh/only-export-components conflicts with Next.js #364

Closed
3 tasks done
musjj opened this issue Jan 23, 2025 · 3 comments · Fixed by #365 or #368
Closed
3 tasks done

react-refresh/only-export-components conflicts with Next.js #364

musjj opened this issue Jan 23, 2025 · 3 comments · Fixed by #365 or #368
Assignees
Labels
accepted The issue is accepted and a PR can be proposed. bug Something isn't working

Comments

@musjj
Copy link
Contributor

musjj commented Jan 23, 2025

Your environment

  • Environment name and version: Node.js 22.11.0
  • Operating System and version: NixOS 24.11
  • Package manager and version: npm 10.9.0

Describe the bug

Next.js allows users to export metadata objects in pages and layouts:

export const metadata = {
  title: 'Acme',
  openGraph: {
    title: 'Acme',
    description: 'Acme is a...',
  },
}

This conflicts with the react-refresh/only-export-components rule.

Project

None

Minimal reproduction

No response

Steps to reproduce

  1. Put the following snippet in a Next.js codebase:
    export const metadata = {
      title: 'Acme',
      openGraph: {
        title: 'Acme',
        description: 'Acme is a...',
      },
    }
  2. Run eslint .

Logs

Code of Conduct

I will submit a PR

  • I'd be willing to submit a PR for this issue.
@musjj musjj added bug Something isn't working triaging Issue is still being evaluated. PRs not yet accepted. labels Jan 23, 2025
@AndreaPontrandolfo
Copy link
Owner

So we should disable the rule in this file, only for pages and layouts.

@AndreaPontrandolfo AndreaPontrandolfo added accepted The issue is accepted and a PR can be proposed. and removed triaging Issue is still being evaluated. PRs not yet accepted. labels Jan 23, 2025
@musjj
Copy link
Contributor Author

musjj commented Jan 23, 2025

I'm thinking of whitelisting it for metadata only, like:

"react-refresh/only-export-components": [
  "error",
  { allowExportNames: ["metadata"] },
]

What do you think?

@AndreaPontrandolfo
Copy link
Owner

Oh yeah, even better, but i think we should still do it only in that file.

Also in the react config file we could add { allowExportNames: ["loader"] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue is accepted and a PR can be proposed. bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants