Skip to content

fix: 将 font 样式挂载到最外层 document.head 以支持嵌套子应用 - #1092

Merged
yiludege merged 2 commits into
masterfrom
fix/nested-font-style
Jun 15, 2026
Merged

yiludege merged 2 commits into
masterfrom
fix/nested-font-style

Conversation

@yiludege

@yiludege yiludege commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

问题

子应用中的 @font-face 样式被挂载到 shadowRoot.host,在嵌套子应用场景下,shadowRoot.host 仍在父应用的 shadowRoot 内部,导致 font 样式无法生效。

相关 issue:

解决方案

  • 新增 inject.fontStyleSheetContainer 指向最外层 document.head 的容器
  • 嵌套子应用通过 window.__WUJIE.inject 自动继承该容器引用
  • font 样式统一挂载到该容器,确保所有子应用都能正确加载字体

修改文件

constant.ts

  • 新增 WUJIE_FONT_STYLE_CONTAINER_ATTR 常量

sandbox.ts

  • 新增 fontStyleSheetElements 数组记录 font 样式元素
  • 新增 createFontStyleSheetContainer() 方法创建/获取容器
  • 新增 clearFontStyleSheets() 方法用于 destroy 时清理
  • patchCssRules() 中将 font 样式挂载到 fontStyleSheetContainer

effect.ts

  • handleStylesheetElementPatch() 中同样使用 fontStyleSheetContainer

测试

  • 单个子应用 font 样式正常加载
  • 嵌套子应用 font 样式正常加载
  • destroy 时 font 样式正确清理

Fixes #845
Fixes #620

问题:
- 子应用中的 @font-face 样式被挂载到 shadowRoot.host
- 嵌套子应用场景下,shadowRoot.host 仍在父应用的 shadowRoot 内
- 导致 font 样式无法生效

解决方案:
- 新增 inject.fontStyleSheetContainer 指向最外层 document.head 的容器
- 嵌套子应用通过 window.__WUJIE.inject 自动继承该容器引用
- font 样式统一挂载到该容器,确保所有子应用都能正确加载字体

修改:
- constant.ts: 新增 WUJIE_FONT_STYLE_CONTAINER_ATTR 常量
- sandbox.ts:
  - 新增 fontStyleSheetElements 数组记录 font 样式元素
  - 新增 createFontStyleSheetContainer() 方法创建/获取容器
  - 新增 clearFontStyleSheets() 方法用于 destroy 时清理
  - patchCssRules() 中将 font 样式挂载到 fontStyleSheetContainer
- effect.ts: handleStylesheetElementPatch() 中同样使用 fontStyleSheetContainer
@yiludege
yiludege force-pushed the fix/nested-font-style branch from 89f0401 to 98bc4f9 Compare June 9, 2026 09:48
@yiludege
yiludege merged commit 2ed612f into master Jun 15, 2026
1 check passed
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
在 revert #1092 错误合入后重新应用本修复。原 PR 误将 monorepo 压扁为单包结构,
本提交仅修改 wujie-core 三个源文件,并保留 #1093 的 CSS placeholder 逻辑。

Fixes #845
Fixes #620

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

孙子应用的自定义@font-face不生效 子应用嵌套子应用,被嵌套的子应用无法加载代码中的字体图标

1 participant