-
Notifications
You must be signed in to change notification settings - Fork 94
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
Use webpack-merge 2.0, fix react hot loader #59
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one change is superfluous and one must be changed, but otherwise fine :)
@@ -18,7 +18,7 @@ export { | |||
*/ | |||
function getLoaderConfigByType (context, webpackConfig, fileType) { | |||
const loaderConfig = webpackConfig.module.loaders.find( | |||
(loader) => loader.test === context.fileType(fileType) | |||
(loader) => regexEqual(loader.test, context.fileType(fileType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to do a real regex comparison. context.fileType(fileType)
should return the same regex reference throughout the whole configuration process.
The only scenario I can think of where it makes a difference: If there are two loader configs matching two file types which have semantically equal regexs to match. But I think we should not even match those as well 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a comment here making that a little clearer...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unfortunally not the case anymore when I updated webpack-merge to 2.0.0. A test was failing because it couldn't find the correct loader for text/css.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I propose we first investigate why this is happening. Looks like an easy fix to deep-compare the regexes, but that might be a minor bug in webpack-merge. If so we should not try to fix it afterwards in webpack-blocks, but fix it in webpack-merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is because of the deep clone webpack-merge is doing behind the scene. In a strict functional way, it is expected that the Regex instance might be a different one with the same value. I'm not sure it is bad to use a more reliable way to compare regexes. I don't think we can expect two instances with the same value on different loaders. I don't think regex are seen as primitive types in javascript.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really doing a deep clone of the regex (new regex with same value)? I wouldn't expect that... (Or: If it really works this way, maybe this is this the bug 😉)
@@ -23,37 +23,37 @@ test('complete webpack config creation', (t) => { | |||
]) | |||
|
|||
t.is(webpackConfig.module.loaders.length, 8) | |||
t.deepEqual(webpackConfig.module.loaders[0], { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, if the order has changed here, we should re-order the assertions as well. Having the indexes in the order 7, 6, 0, 1, 2 really is confusing.
You have some good points here 🙂 Just need to adjust it a little bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the loaders order. However, for the regex a test was failing because of that. Regex are kinda tricky and if the merge is 100% functional, it probably copy it now.
@@ -18,7 +18,7 @@ export { | |||
*/ | |||
function getLoaderConfigByType (context, webpackConfig, fileType) { | |||
const loaderConfig = webpackConfig.module.loaders.find( | |||
(loader) => loader.test === context.fileType(fileType) | |||
(loader) => regexEqual(loader.test, context.fileType(fileType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unfortunally not the case anymore when I updated webpack-merge to 2.0.0. A test was failing because it couldn't find the correct loader for text/css.
Guess we have to look into that slight comparison issue a little more (see comment in code). I cannot say when I will be able to have a deeper look into it myself, though. I am at Munich airport between two connecting flights right now and visiting my girlfriend's family for the next few days... But maybe I manage to find some time :) |
The bright side is, though: The integration tests did their job perfectly fine 👍😄 |
The problem when comparing with the regex instance instead of the value is it is order specific. Meaning if another block add a loader and then your block adds a loader with the same regex, you don't know it will not use your instance but the existing one. I honestly believe it's better to go for comparing the regex value. That way, it is more functional :) |
@eXon Let's discuss this :)
If two loaders are going to match the same file extensions then they use the same The problem about comparing the regex' values is not only that it's slower (I really don't care for this particular use case), but that regex' are bitches that are really hard to compare. If we don't assume referential integrity anymore and always deep-compare the regex' values we encounter a new problem: Regex synonyms. Consider Referential integrity makes comparing trivial and helps me sleep well at night, without having to fear people open issues, because a comparison does not work for their crazy edge-case 🙈😅 |
@andywer good news! looks like it's not a problem anymore with the last version of webpack-merge 👍 |
Looks like it's still not working. My node_modules folder was not up to date. I'll continue searching why the regex instance is not the same. |
I was just debugging #76 and tried updating I found that the last webpack-merge version leaving the regular expressions intact was |
I stand corrected: They introduced a breaking change and just published as a hot fix version. This commit introduces What's happening in |
When they are comparing the loader test regex, Maybe it's good enough for us too? |
@eXon Yeah, I give in. Let's do it like that as well, but let's add a short comment explaining that we do it because of |
Created #77, since this was your hot reloading PR. We should start to take more care not to throw different independent features into the same PR. Otherwise we will have "spaghetti PRs" soon :) |
Well the fix for the hot-reload bug was to upgrade webpack-merge but it will do the job. Awesome thanks 👍 |
@eXon I wasn't even aware of that anymore. So can we close this PR then? Might be good if you check out the latest master and confirm that it works. |
Your PR diff is almost identical so I'll close this. Thanks for the fix! |
Fix #56
All I've done is add unit test for reactHot and update webpack-merge to 2.0.0.
It's a big jump in the version, but it ensures merging the loaders is done correctly for react-hot. However, it looks like the loaders order is now changed a little bit. Not a big deal, but worth testing enough before pushing this.