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

feat: invalidate message and fix HMR for HOC, class component & styled components #79

Merged
merged 1 commit into from Jan 25, 2023

Conversation

ArnaudBarre
Copy link
Member

@ArnaudBarre ArnaudBarre commented Jan 2, 2023

Fixes all known HMR issues (fix #26, fix #6, fix #21, fix #11, fix #8, fix #20).

The SWC plugin also add an issue in the case of "hidden" component (like styled components), fixed in vitejs/vite-plugin-react-swc@954793d (available in 3.1.0-beta.2)

Instead of backporting only the fix, I did what I didn't have time to do before v3: using a more precise validate boundary check and adding invalidate message.

Because of a change in comment handling in esbuild, we need to add Vite 4.1 as a peer dependency to include esbuild > 0.16.14. This requires a bump of rollup and TS, that are removed of the exclude list of renovate at the same time, doesn't seem required for this small codebase.

@ArnaudBarre ArnaudBarre force-pushed the fix-styled-components branch 2 times, most recently from 5bf98f0 to e20e791 Compare January 23, 2023 17:07
@ArnaudBarre ArnaudBarre marked this pull request as ready for review January 23, 2023 17:07
@ArnaudBarre ArnaudBarre changed the title feat: invalidate message and support exported styled components (fix #26) feat: invalidate message and fix HMR for HOC, class component & styled components Jan 23, 2023
@ArnaudBarre ArnaudBarre merged commit 48017b7 into main Jan 25, 2023
@ArnaudBarre ArnaudBarre deleted the fix-styled-components branch January 25, 2023 13:56
@ArnaudBarre
Copy link
Member Author

Available in v3.1.0-beta.0!

@jrmyio
Copy link

jrmyio commented Jan 26, 2023

Available in v3.1.0-beta.0!

v4.1.0-beta.0 I assume ;)

I ran into some styled component theming causing a full refresh. Upgraded to the 4.1.0-beta.0 and the issue is fixed !

Awesome work !

@ArnaudBarre
Copy link
Member Author

The plugin version is v3.1.0-beta.0, but it requires to bump Vite to v4.1.0-beta.0!

@brillout
Copy link

I just ran the VPS test suite and the HMR tests are passing.

@glekner
Copy link

glekner commented Jan 30, 2023

Amazing work! waiting for a release

@ArnaudBarre
Copy link
Member Author

This should be released this week when Vite 4.1 is stable

@rcofie
Copy link

rcofie commented Feb 6, 2023

@ArnaudBarre how does one upgrade it to the latest version so I don't get an error with ReactRefresh?

@ArnaudBarre
Copy link
Member Author

This available with the version 3.1 (requires Vite 4.1)

@andrUIko
Copy link

It seems to be not resolved still in current stable version (4.1.0)

@ArnaudBarre
Copy link
Member Author

Are you using v3.1?
If yes can you provide a case where this is not working for you?

@andrUIko
Copy link

andrUIko commented Mar 30, 2023

Are you using v3.1? If yes can you provide a case where this is not working for you?

vitejs/plugin-react - 3.1.0
vite - 4.1.0
The warning occurred when I wrapped component with HOC and made default export
export default Wrapper(Component)
I've already dropped idea of using HOCs and refactored Wrapper to be
<Wrapper><Component/></Wrapper>

@ArnaudBarre
Copy link
Member Author

export default Wrapper(Component) is not following refresh rules because it's anonymous. You should get a warning for that

@elainecyx
Copy link

vite: 4.2.1
@vitejs/plugin-react: 3.1.0
react: 18.2.0
i got error like this: Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
how can i fix ? Thanks!
@ArnaudBarre

@ArnaudBarre
Copy link
Member Author

Hey this is not the right place to report a bug. (And this PR has nothing to do with this bug). First try to reproduce the issue from a fresh template on stackblitz & then open a new issue with a link to it.
You might also read this https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#middleware-mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment