fix(studio): font faces a host saves keep their own weight and style - #4753
Merged
Merged
Conversation
miguel-heygen
force-pushed
the
dfilm/font-face-weight-style
branch
from
September 30, 2026 08:12
44ee151 to
975e19b
Compare
miguel-heygen
marked this pull request as ready for review
September 30, 2026 08:38
somanshreddy
approved these changes
Sep 30, 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.
What changed
Studio writes an
@font-facefor each font file a text is set in, but it never says which weight or style that file draws. When a film holds several files of one family (a Bold for the title, a Regular for the subtitle, an Italic for a caption), every face claims the same default weight and style. The browser then draws every text of that family from the last file saved, in the editor and in the render.This lets a host that knows each file's weight and style say so; Studio then writes it into the face.
ImportedFontAssettakes an optionalweight("700" for a static file, "100 900" for a variable one) andstyle("normal" or "italic").importedFontFaceCsswrites them asfont-weightandfont-style, so each file draws only the texts that ask for its weight and style. A weight a browser would drop (0, 5000,bold, anything but one or two numbers from 1 to 1000) is left out.injectPreviewImportedFontkeys its preview<style>by file path instead of by family. A second file of a family now reaches the preview, and the preview shows the same file as the render. Before, it kept showing the family's first file.useDomEditSessionasimportedFontAssetsRef.resolveImportedFontAssetreturns the first asset of the family in that list, so a host puts the file a save should write first in the list before that save. It returns them ahead of the file tree, andcommitDomStylesand the text-field commit save them throughensureImportedFontFace. Studio's own font import passes no weight or style yet, so its behaviour is unchanged; reading them from the file name there is a separate change.main:ensureImportedFontFacepassed the new CSS toString.replaceas a string. A file name holding$'or$&pasted part of the page into the saved HTML. It now passes a function.cssStringnow escapes<, so a family decoded from a file name such as</style><b>xcannot close the fonts<style>block.What I measured
fontAssets.test.ts, 5 tests:$'or$&in a file name is saved as written.domStyleCommit.fonts.test.ts, 1 test: twocommitDomStylessaves, whose resolver hands over Poppins SemiBold (600) and then Regular (400), leave two faces in the saved HTML withfont-weight: 600andfont-weight: 400.<escape fails 1.useDomEditCommits,useDomEditTextCommitsanduseDomEditSessiontests: 64 pass. Studiotsc --noEmit, oxlint, oxfmt and the comment ratchet are clean.importedFontFaceCssfrommainand from this branch in a hand-built page, not the Studio UI: Poppins Bold, Regular and Italic from fonts.gstatic.com, with made-up text. Atmain, Chrome loads only the last face; with this change it loads all three.What I did NOT exercise
Before
At
main, three Poppins files for three texts: every text draws from the last file, so the title and the subtitle come out italic.After
Each face says its weight and style: the title draws Bold, the subtitle Regular, the caption Italic.