fix: move fonts into CSS @layer vendor and inject @font-face rules for screenshots #7449
+37
−6
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.
Description
modern-screenshotlibrary has issues with CSS@layerwhen cloning the DOM for screenshots. Fonts were not rendering correctly in screenshots.Changes:
@import "fontawesome-5"into@layer vendorblock invendor.scss@import "fonts"fromindex.scssinto@layer vendorblock invendor.scssonCloneDocumentcallback to extract all@font-facerules from stylesheets and inject them into the cloned documentonCloneEachNodecallback to copy computed font properties during DOM cloningTechnical detail:
When
modern-screenshot'sdomToCanvas()clones the DOM, it has trouble resolving@font-facerules from CSS layers. To fix this while keeping fonts in a CSS layer (as required), the solution uses a two-pronged approach:onCloneDocumentcallback iterates through all stylesheets, extractsCSSFontFaceRuleinstances, and injects them as a<style>block in the cloned document's headonCloneEachNodecallback copies computed font properties (fontFamily, fontWeight, fontSize, fontStyle) from original elements to cloned elementsThis ensures fonts render correctly in screenshots while maintaining proper CSS layer organization.
Checks
packages/schemas/src/languages.tsfrontend/src/ts/constants/languages.tsfrontend/static/languagespackages/schemas/src/themes.tsfrontend/src/ts/constants/themes.tsfrontend/static/themespackages/schemas/src/layouts.tsfrontend/static/layoutsfrontend/static/webfontspackages/schemas/src/fonts.tsfrontend/src/ts/constants/fonts.tsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.