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

Each at-rule overwrites the previous pointing to the same output file (Webpack 4) #47

Open
bitfella opened this issue Oct 2, 2019 · 3 comments

Comments

@bitfella
Copy link
Contributor

bitfella commented Oct 2, 2019

Hello, I guess this could be related to #27.

I am using postcss-critical-css with Webpack 4 (Windows 10) and I am facing the following issue: when importing in the same JS entrypoint several scss partials containing critical at-rules pointing to the same output file, seems like the generated css carries just the contents from one of the sources (usually the one from the last saved source file). Each at-rule overwrites the previous. Sometimes partial overwrites could happen as well, generating syntax errors in the output.

This happens for static scss imports and for dynamic imports of JS files carrying scss imports, as well.

See this repo for further explanation.

Thanks

@bitfella bitfella changed the title Each at-rule overwrite the previous pointing to the same output file (Webpack 4) Each at-rule overwrites the previous pointing to the same output file (Webpack 4) Oct 2, 2019
@zgreen
Copy link
Owner

zgreen commented Oct 3, 2019

Thanks for the bug report, and repo with the replication. It does sound like there's a bug here. I'll take a look as soon as I can; PRs welcome, in the meantime. Cheers.

@bitfella
Copy link
Contributor Author

bitfella commented Oct 4, 2019

@zgreen thanks for your quick reply. Please be aware that @ostowe's own fork should solve this issue. I've tested it locally and everything seems to work fine. Please have a look at his PR #27 :)

Thanks!

@RickKukiela
Copy link

HI!

I just ran into a similar issue with my setup. I'm using Gulp5 streams process sass to css.

I have different scss @import files that have @critical file-name.css blocks and the resulting output file is corrupted exactly where the first block ends and the other block starts.

Essentially I get something that looks like this:

    ...
    top: 13%;
    left: 15%;
  }2.185em;
    font-weight: var(--fw-normal);
    line-height: 1em;
    ....

As you can see, the actual selector is missing. However, there are about two other selectors sets with rules that should have been included. Here is what was in the 2nd scss file that was missed:

main.landing-page {
    width: 1080px;
    margin: 0 auto;
    font-size: 15px;

    .font-light {
        font-size: 2em;
        text-align: center;
        font-weight: var(--fw-light);
        line-height: 1em;
        margin-bottom: 32px;
    }

    .font-reg {
	font-size: /* 2.185em (this bit was included in output) */

You can see where the parent selector had it's last rule as font-size and the first rule in where the break occurred is also font-size so I'm not sure if that's a clue...

The final output should have looked like this:

    ...
    top: 13%;
    left: 15%;
  }
  /** START MISSING **/
  main.landing-page {
    width: 1080px;
    margin: 0 auto;
    font-size: 15px;
  }
  main.landing-page .font-light {
    font-size: 2.00em;
    text-align: center;
    font-weight: var(--fw-light);
    line-height: 1em;
    margin-bottom: 32px;
  }
  main.landing-page .font-reg {
    font-size: 2.185em;
    font-weight: var(--fw-normal);
    line-height: 1em;
    letter-spacing: -0.03em;
  }
  main.landing-page .font-bold {
    font-size: /** END MISSING **/ 2.185em;
    font-weight: var(--fw-normal);
    line-height: 1em;
    ....

I see there is PR that might fix this issue, however, that PR is very old and it very behind the main code base. The PR was also never merged.

So is this a known issue that is not planned for resolution? Or was this supposed to be fixed via other means and I just found out that it's not fully resolved?

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

No branches or pull requests

3 participants