Skip to content

Bug? Named exports in top level components break HMR #4583

Answered by pmmmwh
fatso83 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, maintainer of the Webpack integration of React Refresh here, maybe I can chime in and provide some insights ... (This answer only relates to the React parts of HMR)

TL; DR: This is intentional behaviour, and is necessary to provide guarantees that the HMR would end up in a consistent state.

The reason why it doesn't work is that the additional export is not considered as a component (well, CamelCase functions/classes). If a file contains any exports that is not a component, the transform will not mark the component as side-effects free. This is important because anything else other than a component is generally not guaranteed to be side-effects free, but if there are side-effects, to …

Replies: 6 comments 14 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@fatso83
Comment options

Comment options

You must be logged in to vote
1 reply
@fatso83
Comment options

Comment options

You must be logged in to vote
10 replies
@galaxynova1999
Comment options

@yarinsa
Comment options

@pmmmwh
Comment options

@tommyrharper
Comment options

@folmert
Comment options

Answer selected by fatso83
Comment options

You must be logged in to vote
1 reply
@fatso83
Comment options

Comment options

You must be logged in to vote
1 reply
@lucas-teks
Comment options

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