-
Notifications
You must be signed in to change notification settings - Fork 193
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
Component modifications are not applied #334
Comments
Is it possible to create a reproducible example? Can you share some of your configurations (Babel, Webpack)? |
@pmmmwh thank you for the quick reply. Unfortunately there is no possibility to provide a valuable reproducible example. Project is proprietary and huge. We didn't use babel though configuration was copied from your example. Maybe you can guide me with possible cases? Because right now I got no ideas how to debug this. |
Here some app architecture level details. It is based on micro-frontends solution. Host app provides exposed to Plugin app bundles as a Do I have to run |
Is it possible to give the latest beta a try and report back? I know that the plugin does not work quite as reliable when micro-frontends are used due to the different runtime chunks involved in Webpack ... Can you expose a bit more of the Webpack configuration so I can take a look? Maybe try |
@pmmmwh still no luck with the latest beta :( Here is how Plugin app webpack config looks like: const libName = 'my_lib'
return {
entry: './src/main.tsx',
output: {
library: libName,
type: 'umd'
},
filename: `${libName}.js`,
publicPath: 'https://localhost:3000'
clean: true,
externals: {
'react': 'React',
'react-dom': 'ReactDom',
'react-refresh': 'ReactRefresh'
}
module: {
rules: [
{
test: /.\tsx?$/,
use: [{
loader: 'babel-loader',
options: { plugins: ['react-refresh/babel'] }
}, {
loader: 'ts-loader',
options: { transpileOnly: true }
}]
}
]
},
plugins: [
() => new ReactRefreshPlugin({ library: libName })
],
devServer: {
host: 'localhost',
port: 3000,
client: {
host: 'localhost',
port: 3000,
},
liveReload: false,
hot: 'only'
}
} |
Are you using module federation or how are you managing micro front-ends? |
Micro frontends are managed this way: umd bundle is imported by host application. Plugin app provides a piece of JSX that will be injected and rendered by host application. |
Would you mind creating a example on how the app would be structured and how it would work? I'm quite unfamiliar with micro-frontends so I can't really provide any reasonable help. |
I have the same problem - hot-refresh works when I change I tried to find out the root cause, I copied an example from this repo ( Then I returned back to my not working solution and accidentally found out that hot-refresh works for my solution in one Chrome profile. Literally, I open two profiles - change the .tsx component - it refreshes in one profile and not in the other. The difference between profiles is that the profile, which works, has react-dev-tools Chrome add-in installed. As soon as I installed this add-in to the second profile, it also starts working. I'm not sure how it helps here, but maybe it will give some clues on what might be the cause? It seems react-dev-tools enables something, which somehow unblocks hot-refresh. M - magic :) Just out of curiosity - @yekver do you have react-dev-tools add-in installed? Could you check whether it works with this add-in enabled for you? |
Maybe the reason is, that in my solution react is externalized (it's an external dependency and not bundled in the resulting lib). So it works for |
So I found simple reproduction:
If you have react-dev-tools add-in enabled, then disable it, otherwise, it patches react and it starts working. Also, it doesn't work event with react-dev-tools if external production react build is used. A good question whether it's a bug here or in |
If you externalize React and React DOM, you need to also externalise React Refresh. It is expected behaviour that this does not work with the production build of React, it simply does not contain the development tools needed. |
Yea, but react-dev-tools is managed to somehow patch external react instance so that hot-refresh works when react-dev-tools is enabled on a page. Is it possible to do the same automatically in |
DevTools (and React Refresh) initialises global development hooks where the development build of React would attach renderer instances to. This is what needed to happen before React renders. This plugin ensures this is the case by using this entry point, which is injected in front of all your entry points. However, in the case of externalisation, this approach can be easily defeated. In theory you can patch your app in a way where the entrypoint above would always run first - there are checks to ensure single injection so it should be quite safe to have it in multiple places. Edit:
You will still need the plugin code which handles the runtime globals as well as the injected HMR runtime code though. We do not currently have the option for you to exclude entry injection, but since entries have checks for single entry you could be quite fine by doing Mind trying this approach?
|
I actually tested externalisation and I couldn't reproduce. |
Actually your sandbox doesn't work for me: 2021-05-17_1-32-41.mp4Just make sure you don't have react-dev-tools plugin running in browser (or maybe other react-related things?). |
Aha let me just create a new profile to work with this ... |
I have fixed the sandbox (and all the HTTPS errors etc.) and made it work with externalisation. It should be generic enough - whenever you're externalising React this should be the solution you can use in the places where React is pulled from scripts (so in micro-frontends, this would be the host app; in mono-repos, this would be the app entry). We could allow skipping entry injection, but given that in most cases it is unsafe to do so (it is up to the user to properly organize and order execution which is quite easy to get wrong) I'm not sure if I want to allow this additional API surface (and the issues that would come in with this "mode") ... |
I don't have control over the react injection (as said it's a vendor's platform where I create kind of extensions using react). However, I found that if I explicitly include react in my dev builds it works without issues on the platform and I can leverage hot-refresh. I will use this trick for the time being. @pmmmwh thank you for your help here, it's extremely useful for those, who externalize react and try to use hot-refresh plugin at the same time. |
Yep, I think it is still a bit of an Basically the only guarantee we depend on is to have I'll try to update the troubleshooting documentation soon. |
Very glad I found this -- thanks for the info @pmmmwh. Had a similar issue implementing for this project here: https://github.com/enuchi/React-Google-Apps-Script/ I'm externalizing React, and also loading the app in an iframe. The console showed refresh was working, but the changes weren't being reflected. I loaded the app in a regular browser window instead of in an iframe and then it worked fine! -- but based on above realized it was due to React Dev Tools being loaded (I'm assuming Dev Tools isn't getting loaded inside the iframe window). I just tried in a separate profile without React Dev Tools and it also didn't work. So my solution was to just not externalize React when in development and it works great. Is that the recommended approach (if it's something we can control)? Couldn't figure out what the solution actually was in the codesandbox example you gave. |
@enuchi If you don't have control over execution order then yes, skipping externalization in development is your best bet.
Yes, DevTools intentionally does not copy things over through a frame boundary. |
Thanks again for your help on this @pmmmwh! |
In my case I have an external react that is built as a separate webpack bundle and shared throughout the site (for use by other webpack and non-webpack apps). What helped me was to externalize the So in summary, in my bundle that builds react and exposes it on |
A guide on externalising React is added now. |
It is quite strange but I got stuck in the following situation:
scss
change is successfully applied in-placejson
changes is successfully applied in-placecomponent
changes are ignored.In the network tab I can see that all changes were successfully received and console notifies me that changes are applied and
App is up to date!
, unfortunately there is no visual or logic changes and UI keeps the stale state. Only full reload can fix the situation.I reviewed project configuration multiple times without any luck. I've modified entry to match the following format:
entry: { main: ['./src/index.tsx'] }
and addedtarget: 'web'
. I went across the provided Troubleshooting guide without any luck.I'm confused because of no warnings/errors.
Used versions:
Seems like this bug is closely related to this one
How can I debug this and provide you with some more helpful information?
The text was updated successfully, but these errors were encountered: