Skip to content

Releases: ArnaudBarre/eslint-plugin-react-refresh

v0.5.2

23 Feb 19:49

Choose a tag to compare

  • Support nested function calls for extraHOCs (actually fixes #104)

v0.5.1

23 Feb 08:32

Choose a tag to compare

  • Mark ESLint v10 as supported
  • Support false positives with TypeScript function overloading (fixes #105)
  • Support nested function calls for extraHOCs (fixes #104)

v0.5.0

01 Feb 10:04
daa2efb

Choose a tag to compare

Breaking changes

  • The package now ships as ESM and requires ESLint 9 + node 20. Because legacy config doesn't support ESM, this requires to use flat config
  • A new reactRefresh export is available and prefered over the default export. It's an object with two properties:
    • plugin: The plugin object with the rules
    • configs: An object containing configuration presets, each exposed as a function. These functions accept your custom options, merge them with sensible defaults for that config, and return the final config object.
  • customHOCs option was renamed to extraHOCs
  • Validation of HOCs calls is now more strict, you may need to add some HOCs to the extraHOCs option (like connect or styled)

Config example:

import { defineConfig } from "eslint/config";
import { reactRefresh } from "eslint-plugin-react-refresh";

export default defineConfig(
  /* Main config */
  reactRefresh.configs.vite({ extraHOCs: ["someLibHOC"] }),
);

Config example without config:

import { defineConfig } from "eslint/config";
import { reactRefresh } from "eslint-plugin-react-refresh";

export default defineConfig({
  files: ["**/*.ts", "**/*.tsx"],
  plugins: {
    // other plugins
    "react-refresh": reactRefresh.plugin,
  },
  rules: {
    // other rules
    "react-refresh/only-export-components": [
      "warn",
      { extraHOCs: ["someLibHOC"] },
    ],
  },
});

Why

This version follows a revamp of the internal logic to better make the difference between random call expressions like export const Enum = Object.keys(Record) and actual React HOC calls like export const MemoComponent = memo(Component). (fixes #93)

The rule now handles ternaries and patterns like export default customHOC(props)(Component) which makes it able to correctly support files like this one given this config:

{
  "react-refresh/only-export-components": [
    "warn",
    { "extraHOCs": ["createRootRouteWithContext"] }
  ]
}

Note

Actually createRoute functions from TanStack Router are not React HOCs, they return route objects that fake to be a memoized component but are not. When only doing createRootRoute({ component: Foo }), HMR will work fine, but as soon as you add a prop to the options that is not a React component, HMR will not work. I would recommend to avoid adding any TanStack function to extraHOCs it you want to preserve good HMR in the long term. Bluesky thread.

Because I'm not 100% sure this new logic doesn't introduce any false positive, this is done in a major-like version. This also give me the occasion to remove the hardcoded connect from the rule. If you are using connect from react-redux, you should now add it to extraHOCs like this:

{
  "react-refresh/only-export-components": ["warn", { "extraHOCs": ["connect"] }]
}

v0.4.26

16 Dec 23:26

Choose a tag to compare

  • Revert changes to fix #93 (fixes #95)

v0.4.25

14 Dec 18:23

Choose a tag to compare

  • Report cases like export const ENUM = Object.keys(TABLE) as EnumType[]; (fixes #93)
  • Allow _ in component names (#94)

v0.4.24

15 Oct 08:59

Choose a tag to compare

  • Add "generateImageMetadata", "generateSitemaps" & "generateStaticParams" to allowExportNames in Next config

v0.4.23

01 Oct 21:48

Choose a tag to compare

  • Add "metadata", "generateMetadata" & "generateViewport" to allowExportNames in Next config

v0.4.22

25 Sep 16:22

Choose a tag to compare

  • Add "viewport" to allowExportNames in Next config (#89)

v0.4.21

22 Sep 23:01

Choose a tag to compare

  • Add Next config (fixes #85)

This allows exports like fetchCache and revalidate which are used in Page or Layout components and don't trigger a full page reload.

import reactRefresh from "eslint-plugin-react-refresh";

export default [
  /* Main config */
  reactRefresh.configs.next,
];

v0.4.20

21 Apr 22:25

Choose a tag to compare

  • Don't warn on nested HOC calls (fixes #79)
  • Fix false positive with as const (fixes #80)