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

feat: add patch for inserting css in qiankun environment #3195

Closed

Conversation

dleged
Copy link

@dleged dleged commented Jul 8, 2020

What happens?

qiankun used with styled components;

  1. Load qiankun front-end application;
  2. Switch A application to B application, and then switch back to A application;
  3. A application switch react router, css style of styled-components used on this page will be lost;

Context

qiankun: 2.0.12:
styled-components: 4.4.1/5.1.0/5.1.1:
Chrome: 83.0.4103.97:

When I debugger, I found that there is an exception here, which is obviously caused when accessing qiankun. The real tag sheet.cssRules does not add css style. In the correct case, this.element.sheet and this.sheet refer to the same reference.

avatar
avatar

Here are two qiankun styled-componets related issues that have not been resolved

  1. https://github.com/umijs/qiankun/issues/637;
  2. https://github.com/umijs/qiankun/issues/617;

🌹🌹🌹🙏🙏🙏 The twelve sub-applications of our project all have the problem of CSS style loss, so I eagerly hope that the styled-componets organization can give us help. The styled-componets organization can pass this pull request.

* this.element.sheet.cssRules and this.sheet.cssRules are not the same pointer application
*
*/
if (this.element.sheet !== this.sheet) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a different bug that needs to be fixed in the Stylesheet class.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks,I have solved this problem in qiankun.

Choose a reason for hiding this comment

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

Thanks,I have solved this problem in qiankun.

How did you do that?I have the same problem. Give me some help please~~~

Copy link
Author

@dleged dleged Dec 9, 2021

Choose a reason for hiding this comment

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

Thanks,I have solved this problem in qiankun.

How did you do that?I have the same problem. Give me some help please~~~

默认情况下生产环境是使用 CSSOMTag 的方式动态插入样式规则的,与 qiankun 的结合使用会存在问题;
设置 styled-components 加载方式,只要关闭 CSSOMTag 的插入方式,使用 TextTag 插入的方式即可。
在 React 的最外层使用如下设置:

<StyleSheetManager disableCSSOMInjection={true}> //你的应用代码 ...... <StyleSheetManager/>

@quantizor quantizor closed this Jul 29, 2020
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.

None yet

3 participants