swissquote / crafty

The task runner that binds them all
https://swissquote.github.io/crafty/
Apache License 2.0
30 stars 12 forks source link

Add React Fast Refresh #973

Closed onigoetz closed 1 year ago

onigoetz commented 3 years ago
rahul-s-bhatt commented 3 years ago

Hey, is this issue beginner friendly?

onigoetz commented 3 years ago

Hi, thanks for the interest :)

Honestly, I don't know. On paper it looks quite simple :

This could already give some interesting results.

However what would need to be tested is, since Crafty is used in micro-frontend applications where an instance of React is loaded early (using RequireJS) how it would be possible to have this and Fast Refresh working at the same time? (since as explained here https://github.com/facebook/react/issues/16604#issuecomment-528663101 there is something about a global variable needed by React to handle fast refresh.

Also the other question (which is certainly going to be tightly linked to the first one, can two builds in watch mode be run in two separate directories and be refreshed at the same time on the screen ?

If you want to have a go at getting the happy case to work I'd be willing to finish the part with the two extra points since most users will probably not have this use case.

onigoetz commented 1 year ago

Current status; the implementation is done and behind this flag : https://swissquote.github.io/crafty/Packages/crafty_preset_react.html#fast-refresh

However it seems that it's nor working correctly when React is loaded through requirejs, more experimentation is needed. Also, it's unclear if it works for multiple bundles and multiple React versions/instances

onigoetz commented 1 year ago

Made some further tests and everything seems to be working properly, the gotcha is that Refresh only works when React is loaded in development mode.

The next version will enable React Fast Refresh by default when using react: true in a bundle