Repository navigation
script: Expose FontFace and FontFaceSet to workers - #50046
Merged
Merged
Conversation
|
🔨 Triggering try run (#44393623195) for Linux (WPT) |
TimvdLippe
approved these changes
Nov 18, 2026
TimvdLippe
left a comment
Contributor
There was a problem hiding this comment.
Nice work! I have two small comments
|
Test results for linux-wpt from try job (#44393623195): Flaky unexpected result (18)
Stable unexpected results that are known to be intermittent (9)
Stable unexpected results (2)
|
|
|
This was referenced Nov 18, 2026
Contributor
|
I don't think these test failures are related, but they do confuse me. Did you rebase this PR on |
Expose `FontFace`, `FontFaceSet`, `FontFaceSetLoadEvent` and `self.fonts` to workers. Workers have no document, so they parse font descriptors against their own URL in no-quirks mode, and `web_font_context()` moves from `Window` to `GlobalScope`. A worker's font face set is never pending on the environment, so it switches to loaded as soon as none of its fonts are loading. Fonts loaded in a worker are not added to a font context yet, because workers still share the page's `FontContext`. Signed-off-by: rogerkorantenng <[email protected]>
Signed-off-by: rogerkorantenng <[email protected]>
rogerkorantenng
force-pushed
the
fontface-in-workers
branch
from
November 18, 2026 22:26
28d8e92 to
6a922d7
Compare
Contributor
Author
|
I hadn't, it was based on a commit from this morning. I've rebased it on main. The failures are known intermittents apart from h1-parsing, which is a network error, so I don't think they're related either. |
This was referenced Nov 19, 2026
willypuzzle
pushed a commit
to willypuzzle/servo
that referenced
this pull request
Nov 20, 2026
Dedicated and shared workers used to share the page's `FontContext`.
Fonts a worker loaded could end up in the page, and a font loading in a
worker made the page's `document.fonts.ready` wait for it. Now each of
these workers gets its own empty `FontContext`, which matches the spec
("Within a Worker document, the font source is initially empty") and
what Firefox does. Fonts loaded with `self.fonts` are stored there, and
their WebRender resources are freed when the worker shuts down, like the
layout thread does for pages. Service workers already have their own
`FontContext`, so they're unchanged.
This also fixes loading a second `FontFace` for a URL that was already
loaded for the same family. That failed with "Failed to load font data"
on pages too, because script loads skipped URLs that were already
loaded.
Testing: a page's `document.fonts.ready` no longer waits for a slow font
in a worker (7 ms instead of 2.7 s). With servo#49915 applied locally, a
worker's canvas draws with the font the worker loaded, and can't see
fonts loaded by the page. I also created and closed 20 workers that each
load a font and draw text. Two page tests that loaded the same
`FontFace` twice no longer error, and the WPT `workers` and canvas text
tests still pass.
This builds on servo#50046, so its commits are included here until that one
lands.
Part of servo#49892
Signed-off-by: rogerkorantenng <[email protected]>
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.
This exposes
FontFace,FontFaceSet,FontFaceSetLoadEventandself.fontsto workers. The code mostly needed the document for a base URL and quirks mode, so it now uses the global instead. Workers use their own URL, like Firefox, and no-quirks mode.web_font_context()moved fromWindowtoGlobalScope.In a worker, the font set switches to loaded once none of its fonts are loading. Without that,
self.fonts.readynever resolves.Workers still share the page's
FontContext, so fonts loaded in a worker aren't stored yet, and they can delay the page'sdocument.fonts.ready. The next PR gives each worker its own.Testing:
offscreencanvas-worker-font-load-crash.html,fontfaceset-load-var.html,fontfaceset-load-css-wide-keywords.htmland two worker OffscreenCanvas text tests now pass. I also ran the same FontFace checks in a worker and a window, and they behave the same.Part of #49892