Skip to content

fix: a font macOS would download is no match, where asking for one by name put up a download prompt and held the call until it was answered - #141

Merged
sidorares merged 1 commit into
mainfrom
fix/no-font-auto-activation
Dec 1, 2026
Merged

sidorares merged 1 commit into
mainfrom
fix/no-font-auto-activation

Conversation

@sidorares

@sidorares sidorares commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

macOS lists some 1,300 faces it downloads on demand — Hei, Kai, Songti and the rest of the CJK sets among them (/System/Library/AssetsV2/com_apple_MobileAsset_Font8). Asking AppKit or CoreText for one by name (fontWithDescriptor:, fontWithName:, CTFontCreateWithName), in a process with an NSApp, puts up " needs to download the font …" and blocks the call until someone answers it.

react-x11's browser example hands matchFont a page's whole font stack, and Chinese fallback stacks name these families as a matter of course, so a page stopped its process on a prompt per font. Reproduced with matchFont({ families: ['Hei', 'Menlo'] }) after initApp and a window: the dialog came up and the call did not return.

The change. BFontAvailable(name) answers whether a name, in any case, is a family or PostScript name of a face available now — installed, or registered by the process — from CTFontCollectionCreateFromAvailableFonts, which lists no downloadable face and activates nothing. The names are kept until kCTFontManagerRegisteredFontsChangedNotification (and loadFontData bumps the generation itself). Names CoreText hides (.SF NS) pass. It is asked first by:

  • matchFont's ResolveFamily — a name that fails is not found, and the list moves on, as for a name nobody has;
  • fontByPostScriptName;
  • listFonts({ family });
  • a pop-up's fontFamily (PopUpFont).

fontAvailable(name) exposes the same answer, and the README has a section on it. Nothing is downloaded and nothing is asked.

Tests. test/font-download.js (added to npm test and a CI step) checks fontAvailable on installed families and PostScript names, then takes the first family in the downloadable catalog this machine lacks and matches it ahead of Menlo in an app with a window, in a child process killed if the call is held; it skips the match where there is no catalog. Here it picked Hopper Script and answered Menlo at once; the same probe with Hei against main held on the dialog. buildFace moved from test/font-from-data.js to test/build-face.js.

npm test passes up to test/threaded.js, whose full case ("the folded move is not the latest", 27.46 against 29) fails identically on unmodified main on this machine; every test after it passes.

Two CI jobs failed once each and passed when run again: Node 22 in test/threaded-resize.js ("the content matches the window", 305×203 against 400×260) and Node 26 in test/surface-colorspace.js (a blank capture, "the window was not composited"). Neither touches fonts. The new step passes on 18, 22 and 26.

… name put up a download prompt and held the call until it was answered

macOS lists some 1,300 faces it downloads on demand (Hei, Kai, Songti, …), and `fontWithDescriptor:`, `fontWithName:` or CTFontCreateWithName of one, in a process with an NSApp, puts up "<app> needs to download the font …" and blocks the call. react-x11's browser hands matchFont a page's whole font stack, and Chinese fallback stacks name these families, so a page stopped its process on a prompt per font.

matchFont, fontByPostScriptName, listFonts({ family }) and a pop-up's fontFamily now match only a family or PostScript name of a face available now — CoreText's collection of available fonts, which activates nothing — and pass over any other as they pass over a name nobody has. The names are kept until the registered fonts change. `fontAvailable(name)` answers the same question for a caller.

test/font-download.js (in npm test and CI) takes the first family in the system's downloadable catalog that this machine lacks and matches it ahead of Menlo in an app with a window, in a child killed if the call is held. buildFace moves to test/build-face.js.
@sidorares
sidorares force-pushed the fix/no-font-auto-activation branch from 93144cf to c304df0 Compare December 1, 2026 05:20
@sidorares
sidorares merged commit 7560723 into main Dec 1, 2026
7 of 8 checks passed
sidorares added a commit to sidorares/react-x11-components that referenced this pull request Dec 1, 2026
…cOS would download no longer holds its tab on a Mac (#2398)

appkit 0.34.1 is windowkit/appkit#141: a family or PostScript name that macOS lists only for download, such as Hei, Kai, STHeiti or Microsoft YaHei, is no match, where asking for one by name had macOS look for the download and hold the call. Core 3.3.0's range, `^0.34.0`, admits it, so only the lockfile moves. Nothing in `src/` changes and nothing ships, since an app resolves core's appkit itself.

Chinese font stacks name those families as a matter of course, and core's Cocoa font manager hands `matchFont` the whole list `<Html>` sets a run in. Measured on a Mac with none of them installed, in the example browser on the Cocoa backend, with a page whose stacks are `Hei, Kai, STHeiti, Microsoft YaHei, PingFang SC, sans-serif` and `Hei`, and an `@font-face` whose sources are `local("Hei")` and `local("Kai")`:

| `matchFont` in the tab's process | 0.34.0 | 0.34.1 |
| --- | --- | --- |
| `Hei, sans-serif`, the first named lookup | 9,619 ms | 38 ms, which builds appkit's list of names |
| `Kai`, for `local()` | 2,137 ms | 0 ms |
| the whole stack | 1,133 ms | 2 ms |

That is some 13 seconds before the page's first paint on 0.34.0, near the 15 seconds after which `<Frame>` ends a pane that stops answering. A probe that asked a pane for `Hei, Menlo` went past it, and the pane was ended. A probe in a process with a window and an NSApp, as the browser's own process is, held for 15 seconds until it was killed, which is where windowkit/appkit#141 saw macOS put up its download dialog. On 0.34.1 every one of them answers at once, and the stack sets the text in PingFang SC.

Checked besides: a page of 100 scripts with no family named, which falls back through CoreText's own cascade, a path windowkit/appkit#141 does not touch, lays out with no call over 150 ms, and nothing was downloaded: `fontAvailable` answers false for Hei after every run.
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.

1 participant