Keep array-based entries relative-order during injectRefreshEntry #165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all: hi @pmmmwh and thanks a lot for your work in making it easy to bring react-refresh to webpack based projects. 👏
Motivation
In some of the projects I am currently working on, the bundles are loaded from a regional CDN, and thus we need to rely on a dynamic webpack public path.
I found that, for HMR - in this case based on
webpack-hot-middleware
- to work appropriately with a dynamic webpack public path one has to inject an entry that defines the dynamic public path prior to the socket entry:When I added
react-refresh-webpack-plugin
(based on the webpack-hot-middleware example) I noticed that it changed the relative order of the entries, outputting something like this:This broke the HMR setup because the dynamic public path definition no longer is set before the socket entry.
Changes
Ensure that
injectRefreshEntry
keeps the relative order of an array-based entry. Given the example above:Let me know if there are doubts about the problem and/or solution, and feel free to drop any suggestions.
Thank you for your time!