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]: When using Rsbuild in qiankun, style hot update fails #4302

Closed
cl1107 opened this issue Dec 30, 2024 · 1 comment
Closed

[Bug]: When using Rsbuild in qiankun, style hot update fails #4302

cl1107 opened this issue Dec 30, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@cl1107
Copy link

cl1107 commented Dec 30, 2024

System Info

System:
OS: macOS 15.1.1
CPU: (16) arm64 Apple M3 Max
Memory: 302.09 MB / 48.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.12.0 - ~/.local/state/fnm_multishells/29482_1735549145825/bin/node
Yarn: 1.22.22 - ~/.local/state/fnm_multishells/29482_1735549145825/bin/yarn
npm: 10.9.0 - ~/.local/state/fnm_multishells/29482_1735549145825/bin/npm
pnpm: 9.15.2 - ~/Library/pnpm/pnpm
bun: 1.1.39 - ~/.bun/bin/bun
Watchman: 2024.12.02.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 131.0.6778.205
Edge: 131.0.2903.112
Safari: 18.1.1

Details

在 qiankun 中使用 rsbuild 时, qiankun 加载子应用时设置

sandbox: {
         experimentalStyleIsolation: true,
}

当 experimentalStyleIsolation 被设置为 true 时,qiankun 会改写子应用所添加的样式为所有样式规则增加一个特殊的选择器规则来限定其影响范围,会把 link 改写成style,
Image
Image
目前cssExtractHmr.js 中css 的热更新是获取所有 link 标签进行更新,因此失效了,我把experimentalStyleIsolation设置为 false 可以进行热更新
Image

迁移前使用 webpack 没有这个问题

Reproduce link

https://github.com/cl1107/qiankun-rsbuild-css-hmr-lose-effect

Reproduce Steps

cd main
pnpm i
pnpm run start

cd vue3
pnpm i
pnpm run start

cd vue
pnpm i
pnpm run start
vue目录是使用 vue-cli ,热更新是正常的, vue3 目录是使用 rsbuild 更新不正常

@cl1107 cl1107 added the bug Something isn't working label Dec 30, 2024
@hardfist hardfist transferred this issue from web-infra-dev/rspack Dec 30, 2024
@chenjiahan chenjiahan changed the title [Bug]: 在 qiankun 中使用 rsbuild 时,样式热更新失效 [Bug]: When using Rsbuild in qiankun, style hot update fails Dec 31, 2024
@cl1107
Copy link
Author

cl1107 commented Jan 2, 2025

我对比了一下 rsbuild 和 vue-cli最后生成配置,发现 vue-cli 最后生成的配置有使用style-laoder,而 rsbuild 没有使用,因此我尝试在 rsbuild 中开启 style-loader,在配置中将output.injectStyles设置为true即可开始,试了一下这样开启后可以解决这个热更新问题,因为不推荐在生产中开启这个特性,因此使用如下配置

  output: {
    injectStyles: process.env.NODE_ENV === 'development',
  },

参考链接:https://rsbuild.dev/zh/config/output/inject-styles

@cl1107 cl1107 closed this as completed Jan 2, 2025
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

1 participant