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

Add React Fast Refresh #973

Closed
onigoetz opened this issue Sep 21, 2020 · 4 comments
Closed

Add React Fast Refresh #973

onigoetz opened this issue Sep 21, 2020 · 4 comments

Comments

@onigoetz
Copy link
Member

@rahul-s-bhatt
Copy link

Hey, is this issue beginner friendly?

@onigoetz
Copy link
Member Author

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 facebook/react#16604 (comment) 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
Copy link
Member Author

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
Copy link
Member Author

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

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

No branches or pull requests

2 participants