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

[Bug]: loaders for styles are not deduplicated when experiments.css is true #3482

Closed
beliefgp opened this issue Sep 14, 2024 · 2 comments
Closed
Labels
🐞 bug Something isn't working need reproduction

Comments

@beliefgp
Copy link

Version

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M3
    Memory: 84.05 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 128.0.6613.138
    Safari: 17.5
  npmPackages:
    @rsbuild/core: ^1.0.1 => 1.0.4 
    @rsbuild/plugin-less: ^1.0.1 => 1.0.1 
    @rsbuild/plugin-vue: ^1.0.1 => 1.0.1

Details

File was processed with these loaders:
* rsbuild-test/node_modules/vue-loader/dist/pitcher.js??ruleSet[1].rules[0].use[0]
* rsbuild-test/node_modules/@rspack/core/dist/builtin-plugin/css-extract/loader.js
* commonjs|rsbuild-test/node_modules/@rsbuild/core/compiled/css-loader/index.js??clonedRuleSet-2.use[1]
* builtin:lightningcss-loader??clonedRuleSet-2.use[2]
* rsbuild-test/node_modules/@rspack/core/dist/builtin-plugin/css-extract/loader.js
* rsbuild-test/node_modules/@rsbuild/core/compiled/css-loader/index.js??clonedRuleSet-2.use[1]
* builtin:lightningcss-loader??clonedRuleSet-2.use[2]
* rsbuild-test/node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]

目前 vue2,vue3 版本都会出现这个问题,我尝试改了 plugin-vue2 的实现,但发现好像现在重置 loader 没有效果了,还是重置之前的 loaders。

// src/VueLoader15PitchFixPlugin.ts
var VueLoader15PitchFixPlugin = class {
  constructor() {
    this.name = "VueLoader15PitchFixPlugin";
  }
  apply(compiler) {
    const { NormalModule } = compiler.webpack;
    compiler.hooks.compilation.tap(this.name, (compilation) => {
      const isExpCssOn = compilation.compiler.options?.experiments?.css;
      if (!isExpCssOn) return;
      NormalModule.getCompilationHooks(compilation).loader.tap(
        {
          name: this.name,
          stage: Number.MAX_SAFE_INTEGER
        },
        (loaderContext) => {
          if (
            // the related issue only happens for <style>
            /[?&]type=style/.test(loaderContext.resourceQuery) && // the fix should be applied before `pitch` phase completed.
            // once `pitch` phase completed, vue-loader will remove its pitcher loader.
            // /[\\/]vue-loader[\\/]lib[\\/]loaders[\\/]pitcher/.test(
            //   loaderContext.loaders?.[0]?.path || ""
            // )
            loaderContext.loaders?.some(loader => /[\\/]vue-loader[\\/]lib[\\/]loaders[\\/]pitcher/.test(loader.path))
          ) {
            const seen = /* @__PURE__ */ new Set();
            const loaders = [];
            for (const loader of loaderContext.loaders || []) {
              const identifier = typeof loader === "string" ? loader : loader.path + loader.query;
              if (!seen.has(identifier)) {
                seen.add(identifier);
                loaders.push(loader);
              }
            }

            loaderContext.loaders = loaders;
          }
        }
      );
    });
  }
};

Reproduce link

xxxxx

Reproduce Steps

rsbuild build

@beliefgp beliefgp added the 🐞 bug Something isn't working label Sep 14, 2024
Copy link
Contributor

Hello @beliefgp. Please provide a reproduction repository or online demo. For background, see Why reproductions are required. Thanks ❤️

Copy link
Contributor

As the issue was labelled with need reproduction, but no response in 5 days. This issue will be closed. Feel free to comment and reopen it if you have any further questions. For background, see Why reproductions are required.

由于该 issue 被标记为 "需要重现",但在 5 天内没有回应,因此该 issue 将被关闭。如果你有任何进一步的问题,请随时发表评论并重新打开该 issue。背景请参考 为什么需要最小重现

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working need reproduction
Projects
None yet
Development

No branches or pull requests

2 participants