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

fix: allow consumers to access CssModule #703

Merged
merged 13 commits into from Feb 25, 2021

Conversation

barak007
Copy link
Contributor

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Hey,
This PR fixes a subtle breaking change happened in the last release.
I had an integration that was injecting CssModule instances to the compilation, and it assumed this plugin will take care of them.
After the latest release it was impossible for me to get the CssModule class since it cannot be registered twice for serialization.
This PR allows others to get access to the CssModule class within same webpack running version.

Breaking Changes

none

Additional Info

Hey, 
This PR fixes a subtle breaking change happened in the last release.  
I had an integration that was injecting CssModule instances to the compilation, and it assumed this plugin will take care of them.
After the latest release it was impossible for me to get the CssModule class since it cannot be registered twice for serialization.
This PR allows others to get access to the CssModule class within same webpack running version.
@codecov
Copy link

codecov bot commented Feb 18, 2021

Codecov Report

Merging #703 (47b836f) into master (1be21d2) will increase coverage by 0.17%.
The diff coverage is 97.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #703      +/-   ##
==========================================
+ Coverage   89.58%   89.75%   +0.17%     
==========================================
  Files           6        6              
  Lines         768      771       +3     
  Branches      232      235       +3     
==========================================
+ Hits          688      692       +4     
+ Misses         77       76       -1     
  Partials        3        3              
Impacted Files Coverage Δ
src/loader.js 92.59% <85.71%> (+0.17%) ⬆️
src/index.js 87.87% <100.00%> (+0.29%) ⬆️
src/utils.js 91.89% <100.00%> (+0.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1be21d2...a6d9608. Read the comment docs.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need small test for this to avoid this problem in future + comments why we need to do it

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need do the same for CssDependency, so we need to remove shared and use the same approach

@barak007
Copy link
Contributor Author

I'm not sure what's going on with the lint. maybe related to new lines?

@alexander-akait
Copy link
Member

Yep, need to run prettier on these files

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need shared util anymore, just use plugin.getCssDependency(webpack) in loader

@barak007
Copy link
Contributor Author

true. I'm not sure about this error now it cannot happen.

if (!CssDependency) {
  throw new Error(
    "You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started"
  );
}

@alexander-akait
Copy link
Member

true. I'm not sure about this error now it cannot happen. this happens only when you forget to add plugin

@barak007
Copy link
Contributor Author

also something with prettier is not working for me.

@barak007
Copy link
Contributor Author

But now it will always generate the CSSDependency class. I can add validation that it already requested once if needed

@alexander-akait
Copy link
Member

Run npm run lint:prettier -- --fix

@alexander-akait
Copy link
Member

Yep, I think it make sense

@barak007
Copy link
Contributor Author

first prettier is failed to execute for some unknown reason. (I can share the log if needed)
second I'm thinking that this error is an unwanted detail because now an integration can possibly create the class unrelated to the fact that someone forgot to config the plugin. maybe this error should be based on loader context provided from the plugin.

@alexander-akait
Copy link
Member

second I'm thinking that this error is an unwanted detail because now an integration can possibly create the class unrelated to the fact that someone forgot to config the plugin. maybe this error should be based on loader context provided from the plugin.

Agree, we can use Symbol in apply for this

@barak007
Copy link
Contributor Author

Sine I'm kind of working on blind. I will need to double check this. I will try to clone it later with correct NL config and try to run all the lints and tests locally.

@barak007
Copy link
Contributor Author

The lint error is just for the commit messages it can be solved with squash. The other tests I'm not sure about. It seems that it's also broken on master.

@barak007
Copy link
Contributor Author

the failing test looks to me like pure flakiness. from my perspective this PR is ready.

@alexander-akait alexander-akait merged commit 6484345 into webpack-contrib:master Feb 25, 2021
@alexander-akait
Copy link
Member

Thanks

@pieh
Copy link

pieh commented Feb 25, 2021

Is this correct change?

Shouldn't here compiler be used as cache key and not webpack package/module? In case of multiple compilers created from same webpack package, now one compiler has impact on another 🤔

I did hit issue of getting those recent release:

You forgot to add 'mini-css-extract-plugin' plugin (i.e. { plugins: [new MiniCssExtractPlugin()] }), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started

Tho this might be wrong configuration for SSR bundle compilation where I don't want to extract css anymore (because that happen in browser bundle compilation), but I do still have mini-css-extract-plugin loader in front of css-loader for css-modules (tho css-loader has exportOnlyLocals option, so it doesn't do actual css processsing other than extracting class names).

@alexander-akait
Copy link
Member

This loader doesn't have sense without the plugin

@alexander-akait
Copy link
Member

Using extra loader on top reduce your bundling perf, so I recommend to remove it

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

Successfully merging this pull request may close these issues.

None yet

3 participants