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-refresh-webpack-plugin to react projects #258

Open
joeldenning opened this issue Jan 27, 2021 · 12 comments
Open

Add react-refresh-webpack-plugin to react projects #258

joeldenning opened this issue Jan 27, 2021 · 12 comments
Labels
enhancement New feature or request

Comments

@joeldenning
Copy link
Member

cc @frehner who has worked on this in the past. I'm happy to add this if you don't have time @frehner - just created the issue to track what we discussed on Slack.

@frehner
Copy link
Member

frehner commented Jan 27, 2021

I'm going to implement this in my apps first to check to see if there are any other issues. Should only take an hour or so hopefully

@frehner
Copy link
Member

frehner commented Jan 28, 2021

We have discovered some issues that may make integrating this at the moment a headache. It may be worth waiting on this a bit until react-refresh and the webpack plugin are a little more stable.

@nilzona
Copy link

nilzona commented Sep 7, 2021

Hey @frehner .. just out of curiosity. What was the issues you discovered?

@frehner
Copy link
Member

frehner commented Sep 7, 2021

I believe either I or the library author has resolved all the issues that we had; we're using the latest version and are not having any problems at the moment. 🙂

@nilzona
Copy link

nilzona commented Sep 8, 2021

hey @frehner .. I used the latest create-single-spa to generate some react single-spa applications. I am then using import-map-overrides to point to a local webpack-dev-sever served with react-refresh and react-refresh-webpack-plugin. It doesn't work for me. HMR seems to work, but there's no actual changed applied to the dom.

Do you have any example where you got it working?

I created this issue in hope to get some help.

@nilzona
Copy link

nilzona commented Sep 16, 2021

The issue mentioned above has been resolved:

pmmmwh/react-refresh-webpack-plugin#502

It is now possible to enable HMR with the latest create-single-spa generated react libraries.

@joeldenning
Copy link
Member Author

I tried this out a bit today and didn't get it working. I don't have further time today to work on it. Based on the comments in the thread you linked to, it seems that react-refresh needs to be a shared dependency or into the root config, and be loaded before react and react-dom? Making react-refresh a shared dependency won't be very easy because react-refresh only publishes CJS bundles to npm and systemjs doesn't load cjs bundles. Specifically, react-refresh references process which is not a real thing in browsers and only works when webpack fakes support for it in browsers, which would not happen for us.

So the next step would be to overcome that problem and get react-refresh loaded in the root config or as a shared dependency, then try again.

@frehner
Copy link
Member

frehner commented Sep 20, 2021

Alternatively, you need to have the React DevTools extension installed, and that has the side-effect of fixing the issue with the loading order

@joeldenning
Copy link
Member Author

Ah thanks for pointing that out - after installing the react devtools the hot reloading does work! Would be nice to not require that of every single-spa user, though, or have to constantly document/answer questions about it. So I still think loading react-refresh as a shared dep would be ideal.

@nilzona
Copy link

nilzona commented Sep 22, 2021

@joeldenning ... I think you had the same issue as I had :) I was banging my head against the wall trying to figure it out and then when I installed React Dev Tools I got it working right away. Yes, it would be nice to not be dependent on React Developer Tools. Any ideas on how that could be a shared dep?

@joeldenning
Copy link
Member Author

Yes but it's just would take a fair amount of effort - either create an esm bundle for it, or do it in the root config with System.set(). I won't get to it today.

@MilanKovacic MilanKovacic added the enhancement New feature or request label Oct 1, 2023
@alex-enchi
Copy link

with latest webpack for me removing adding hot: true to the dev server worked wonders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants