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: the auto option for inline module syntax #1274

Merged
merged 7 commits into from
Mar 15, 2021
Merged

Conversation

alexander-akait
Copy link
Member

This PR contains a:

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

Motivation / Use-Case

fixes #1273

Breaking Changes

No

Additional Info

/cc @jquense fixed, please look

],
Array [
"button.modules.css!=!./index-loader-syntax-sass.css",
".iuzmhXWrT3_Z-zKS-rMGM {
Copy link
Member Author

Choose a reason for hiding this comment

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

Now they are CSS moduled

@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #1274 (c44418f) into master (c13f369) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1274   +/-   ##
=======================================
  Coverage   99.46%   99.46%           
=======================================
  Files          11       11           
  Lines         752      753    +1     
  Branches      256      258    +2     
=======================================
+ Hits          748      749    +1     
  Misses          4        4           
Impacted Files Coverage Δ
src/utils.js 98.77% <100.00%> (+<0.01%) ⬆️

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 c13f369...c44418f. Read the comment docs.

const { resourcePath } = loaderContext;
const resourcePath =
// eslint-disable-next-line no-underscore-dangle
loaderContext._module.matchResource || loaderContext.resourcePath;
Copy link
Contributor

Choose a reason for hiding this comment

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

woohoo! should this also be the logic for local ident generation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, you are right, otherwise we will get the same class names.

After fix local ident generation should we merge it and release? All is fixed?

Copy link
Contributor

Choose a reason for hiding this comment

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

i think so, seems like this covers it all. hard to know for sure until i try it out on a code base. Thanks again for helping me out here

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, here interesting case, when we have:

import three from './button.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js';
import four from './other.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js';

We run the loader only once, why? Because ES modules executed only once. So I don't think here bug. But we can solve it using:

// i.e. adding `?` with different values
import three from './button.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=bar';
import four from './other.module.scss!=!./base64-loader?LmZvbyB7IGNvbG9yOiByZWQ7IH0=!./simple.js?foo=baz';

Copy link
Contributor

Choose a reason for hiding this comment

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

ah interesting, so the query param acts like a cache buster. That solution seems fine to me

Copy link
Contributor

@jquense jquense Mar 15, 2021

Choose a reason for hiding this comment

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

yeah in my case it'd be easy to use a stable identifier here. This wouldn't solve the className hash generation issue tho right? I'm guessing you discovered this writing a test for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Solved, please check code

Copy link
Contributor

Choose a reason for hiding this comment

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

arg, i'm trying this out now and _module.matchResource is null locally. Going to debug a bit to see why will report back

Copy link
Member Author

Choose a reason for hiding this comment

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

If you don't have matchResource in request, it will be nullish

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah this is for requests with it in it. For some reason i am seeing the module get created twice, one with the matchResource and one without, the one without is what makes it to the css-loader. It maybe has to do with ESM, still trying to figure it out

Array [
"other.module.scss!=!./base64-loader/index.js?[ident]!./simple.js?foo=baz",
"._1KqQu-H04lA8NLg4-NKnDf {
color: red;
Copy link
Member Author

Choose a reason for hiding this comment

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

You can see here: hash for classes are different

Copy link
Member Author

Choose a reason for hiding this comment

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

But note: you should use different matchResource, otherwise hash will be same

Copy link
Contributor

Choose a reason for hiding this comment

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

perfect!

@jquense
Copy link
Contributor

jquense commented Mar 15, 2021

LGTM

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.

2 participants