ArnaudBarre / eslint-plugin-react-refresh

Validate that your components can safely be updated with Fast Refresh
MIT License
206 stars 13 forks source link

Add an option to not warn on const export #8

Closed JiangWeixian closed 1 year ago

JiangWeixian commented 1 year ago

Thanks for you job! I test on vite based project, when I create a button.tsx file, contains:

import React from 'react'

export const CONSTANT = 12
export const Foo = () => {
  window.document.title = '6'
}

export default function Button() {
  const [count, setCount] = React.useState(0)
  return <div onClick={() => setCount(1)}>{count}1</div>
}

When I edit this file, it's safety hmr update. Do I miss something?

ArnaudBarre commented 1 year ago

So yeah this file is not respecting the rules of Fast refresh:

I hope it's clear!

Edit: For the constant export, this could be allowed by the plugin via an option though (I don't want to make it a default because I don't think other integrations handle this specific case)

JiangWeixian commented 1 year ago

https://user-images.githubusercontent.com/6839576/231635195-c3e732cd-6952-4372-ba24-69360bd957fe.mp4

You are correct, I update vite to @4, found when I update foo inside button.tsx, vite will invalidate this file(in @3 it logs hmr update). However, button state looks like kept.