fix: 修复异步加载 CSS 时重复插入的问题 - #1093
Merged
Merged
Conversation
问题: - 子应用调用 document.head.appendChild(link) 后,wujie 异步加载 CSS - 在 CSS 加载完成前,checkLinkAndLoad 等去重检查无法找到已存在的元素 - 导致相同的 CSS 被重复插入多次 场景示例: - TDesign IconFont 组件的 checkLinkAndLoad 函数 - React StrictMode 下 useEffect 执行两次 - 快速连续调用相同 CSS 加载 解决方案: - 在异步加载 CSS 前,立即创建占位 <style> 元素并插入 DOM - 保留原始 <link> 的属性(如 class),以便去重逻辑能找到 - CSS 加载完成后填充内容到占位元素 修改: - effect.ts loadStyleSheet 函数: - 提前解析属性并创建占位元素 - 立即插入 DOM(关键改动) - CSS 加载完成后填充内容或处理 ignore 情况
5 tasks
yiludege
added a commit
that referenced
this pull request
Jun 15, 2026
* Revert "fix: 将 font 样式挂载到最外层 document.head 以支持嵌套子应用 (#1092)" This reverts commit 2ed612f. * fix: 将 font 样式挂载到最外层 document.head 以支持嵌套子应用 在 revert #1092 错误合入后重新应用本修复。原 PR 误将 monorepo 压扁为单包结构, 本提交仅修改 wujie-core 三个源文件,并保留 #1093 的 CSS placeholder 逻辑。 Fixes #845 Fixes #620 Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
yiludege
added a commit
that referenced
this pull request
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
子应用调用
document.head.appendChild(link)后,wujie 异步加载 CSS。在 CSS 加载完成前,checkLinkAndLoad等去重检查无法找到已存在的元素,导致相同的 CSS 被重复插入多次。场景示例
checkLinkAndLoad函数解决方案
<style>元素并插入 DOM<link>的属性(如 class),以便去重逻辑能找到修改文件
effect.ts
loadStyleSheet函数:测试