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]: Strange HMR bug after removing <style> in Vue SFC #7805

Open
ZhangTaibin opened this issue Sep 5, 2024 · 5 comments
Open

[Bug]: Strange HMR bug after removing <style> in Vue SFC #7805

ZhangTaibin opened this issue Sep 5, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@ZhangTaibin
Copy link

Version

System: Window
Browser: Edge
vue: 2/3
and others node js 18/20

Details

i just create a pure project with pnpm create rsbuild@latest.

And then run the project with pnpm run dev . it's ok and i dont edit anything.

when i delete <style></style element in App.vue. It will throw an error writting "Cannot read properties of undefined (reading 'call')". Then i stop the HMR and run the project again. It will be OK.

I think that it has some strange problem with HMR

Reproduce link

not link

Reproduce Steps

pnpm create rsbuild@latest

cd project

pnpm i

pnpm run dev

delete style element in App.vue

@chenjiahan chenjiahan changed the title [Bug]: Strange HMR bug [Bug]: Strange HMR bug after removing <style> in Vue SFC Sep 5, 2024
@chenjiahan chenjiahan transferred this issue from web-infra-dev/rsbuild Sep 5, 2024
@chenjiahan chenjiahan added the bug Something isn't working label Sep 5, 2024
@CPunisher
Copy link
Contributor

i cant reproduce with rspack.
after debugging with rsbuild, I find vue style query triggers vue-loader before the vue file does, which is difference from the correct orders in rspack. The vue loader throws errors since there is no style block in the descriptor when handling the style query.

@CPunisher
Copy link
Contributor

CPunisher commented Sep 16, 2024

I reproduce with the following rspack config:

const rspack = require('@rspack/core');
const { VueLoaderPlugin } = require('vue-loader');

/** @type {import('@rspack/cli').Configuration} */
const config = {
  entry: './src/index.js',
  plugins: [
    new VueLoaderPlugin(),
    new rspack.HtmlRspackPlugin({}),
    new rspack.CssExtractRspackPlugin({
      runtime: false,
    }),
  ],
  // experiments: {
  //   css: true,
  // },
  module: {
    rules: [
      {
        test: /\.css$/i,
        use: [
          { loader: rspack.CssExtractRspackPlugin.loader, options: {} },
          'css-loader',
        ],
        type: 'javascript/auto',
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          // Note, for the majority of features to be available, make sure this option is `true`
          experimentalInlineMatchResource: true,
        },
      },
    ],
  },
};
module.exports = config;

My guess about the process:
CssExtractRspackPlugin loader calls this.importModule, which introduce an extra module that derives from the css module generated by vue-loader (App.vue?type=style). This extra module is handled by ModuleExecutor. When the style block in the vue file is removed, rspack calls ModuleExecutor::hook_before_make to rebuild the extra module before rebuilding others. When vue-loader processes the extra module, error is thrown since there is no style block in the vue descriptor.

@hardfist
Copy link
Contributor

this should be fixed in #7878 and released in 1.0.5, @CPunisher can you help verify it

@hardfist
Copy link
Contributor

@ZhangTaibin please try 1.0.5

@ZhangTaibin
Copy link
Author

ZhangTaibin commented Sep 19, 2024

It's done when use Rspack CLI to create project.

When use [email protected] to create project. If i change CSS content, it's done.

But it's not done when i delete style tag or clear all CSS content. it throw an error Cannot read properties of undefined (reading 'content')

System: Windows 11
Node: 18
Rsbuild: 1.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants