@@ -6,6 +6,7 @@ import { resolveCompositionViewportFromHtml } from "../utils/compositionViewport
66const SHADER_TRANSITIONS_TIMEOUT_MS = 90_000 ;
77const CAPTURE_SETTLE_MS = 1500 ;
88const PREFERRED_SEEK_TARGET_WAIT_MS = 500 ;
9+ const DEFAULT_POST_SEEK_FONT_WAIT_MS = 500 ;
910
1011// The audit-grade seek tuning shared by check and the deprecated inspect/layout:
1112// bridge+timeline fallback, ordered double-rAF settle, bounded font wait, sleep.
@@ -257,8 +258,13 @@ export async function seekCompositionTimeline(
257258 ) ;
258259 }
259260
260- if ( options . waitForFontsMs !== undefined ) {
261- await waitForCompositionFonts ( page , options . waitForFontsMs ) ;
261+ // On by default: every seek caller here is a visual-audit path (snapshot,
262+ // check, compare, validate, layout) and a seek that reveals unrequested
263+ // glyphs must not screenshot before their font subsets load. Costs one
264+ // evaluate + one rAF when nothing is loading. Pass 0 to disable.
265+ const waitForFontsMs = options . waitForFontsMs ?? DEFAULT_POST_SEEK_FONT_WAIT_MS ;
266+ if ( waitForFontsMs > 0 ) {
267+ await waitForCompositionFonts ( page , waitForFontsMs ) ;
262268 }
263269 if ( options . settleMs !== undefined ) {
264270 const settleMs = Math . max ( 0 , options . settleMs ) ;
@@ -299,12 +305,31 @@ export async function waitForCompositionFonts(
299305 . evaluate ( ( ms : number ) => {
300306 const fonts = Reflect . get ( document , "fonts" ) ;
301307 if ( typeof fonts !== "object" || fonts === null ) return Promise . resolve ( ) ;
302- const ready = Reflect . get ( fonts , "ready" ) ;
303- if ( ! ready ) return Promise . resolve ( ) ;
304- return Promise . race ( [
305- Promise . resolve ( ready ) . then ( ( ) => undefined ) ,
306- new Promise < void > ( ( resolve ) => setTimeout ( resolve , ms ) ) ,
307- ] ) ;
308+ // A seek can reveal glyphs whose font faces were never requested —
309+ // CJK @font-face splits into unicode-range subsets that only load when
310+ // first laid out. `fonts.ready` is already-resolved at that moment, so
311+ // awaiting it immediately races the load request and screenshots blank
312+ // glyphs (wild reports: Traditional Chinese / Microsoft YaHei check
313+ // snapshots). Force a synchronous layout so pending subsets actually
314+ // start loading, give the loader one frame to flip `fonts.status`,
315+ // THEN await readiness.
316+ void document . body ?. offsetHeight ;
317+ return new Promise < void > ( ( resolveWait ) => {
318+ const deadline = setTimeout ( resolveWait , ms ) ;
319+ requestAnimationFrame ( ( ) => {
320+ const status = Reflect . get ( fonts , "status" ) ;
321+ const ready = Reflect . get ( fonts , "ready" ) ;
322+ if ( status !== "loading" || ! ready ) {
323+ clearTimeout ( deadline ) ;
324+ resolveWait ( ) ;
325+ return ;
326+ }
327+ Promise . resolve ( ready ) . then ( ( ) => {
328+ clearTimeout ( deadline ) ;
329+ resolveWait ( ) ;
330+ } ) ;
331+ } ) ;
332+ } ) ;
308333 } , timeoutMs )
309334 . catch ( ( ) => { } ) ;
310335}
0 commit comments