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

fix(react): improve option for react-refresh #455

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/configs/react.ts
Expand Up @@ -7,6 +7,12 @@ import { GLOB_TS, GLOB_TSX } from '../globs'
const ReactRefreshAllowConstantExportPackages = [
'vite',
]
const RemixPackages = [
'@remix-run/node',
'@remix-run/react',
'@remix-run/serve',
'@remix-run/dev',
]

export async function react(
options: OptionsTypeScriptWithTypes & OptionsOverrides & OptionsFiles = {},
Expand Down Expand Up @@ -42,6 +48,8 @@ export async function react(
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
i => isPackageExists(i),
)
const isUsingRemix = RemixPackages.some(i => isPackageExists(i))
const isUsingNext = isPackageExists('next')

const plugins = pluginReact.configs.all.plugins

Expand Down Expand Up @@ -91,7 +99,27 @@ export async function react(
// react refresh
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: isAllowConstantExport },
{
allowConstantExport: isAllowConstantExport,
allowExportNames: isUsingNext
? [
'config',
'generateStaticParams',
'metadata',
'generateMetadata',
'viewport',
'generateViewport',
]
: isUsingRemix
? [
'meta',
'links',
'headers',
'loader',
'action',
]
: undefined,
},
Comment on lines +104 to +122
Copy link
Owner

Choose a reason for hiding this comment

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

I would allow all of them directly without checking the packages - would that have any bad side-effects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it should be a big problem, but when using pure vite and react, if the exported name coincides with the preset, it will still affect fast refresh.

],

// recommended rules from @eslint-react
Expand Down