fix(text): keep SDF font waiters across a failed load so a retry wakes them#109
Merged
Conversation
…s them When an SDF font's atlas fails to load, the `'failed'` handler did two things wrong, and `loadFont` had a related stranding bug: 1. `delete fontCache[fontFamily]` used bracket access on a Map, deleting a plain property that never existed and leaving any real cache entry untouched. Switch to `fontCache.delete(fontFamily)`. 2. `loadFont` overwrote `nodesWaitingForFont[fontFamily]` with a fresh `[]` on every call. After a failed attempt left nodes parked in that list, a retry discarded them — so even a successful retry never woke the parked text nodes (they stayed blank forever). Reuse the existing list instead; it is consumed and deleted on the next successful load, and shrinks as nodes self-remove via `stopWaitingForFont` on destroy. No behavior/events were added: a font that fails and is never retried still ends up blank (there is no canvas fallback in single-engine setups). Adds a regression test that parks a node, fails the first load, retries, and asserts the node is woken (verified to fail against the old overwrite). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Fixes two related defects in the SDF font loader (
src/core/text-rendering/SdfFontHandler.ts) around the atlas-load-failure path.1.
fontCacheMap deleted via bracket accessThe
'failed'handler diddelete fontCache[fontFamily], butfontCacheis aMap— bracket access deletes a plain property that never existed and leaves any real entry untouched. Switched tofontCache.delete(fontFamily).2. Text nodes stranded after a failed-then-retried load
loadFontoverwrotenodesWaitingForFont[fontFamily]with a fresh[]on every call. The sequence that breaks:loadFont(F)creates the waiter list; a text node parks itself there while the atlas loads.loadFont(F)again (retry). The old code overwrote the list with[], discarding the parked node.The fix reuses an existing waiter list instead of overwriting it, so a successful retry still wakes nodes parked before the failure. The list is consumed and deleted on the next successful load, and shrinks as nodes self-remove via
stopWaitingForFonton destroy.Why
A font-load failure currently produces a silent permanent blank for any text node already waiting on that font, and a retry can't recover those nodes. There's no canvas fallback in single-engine setups, so this is the only recovery path.
Reviewer notes
'failed'handler intentionally keepsnodesWaitingForFont[fontFamily](commented in code). Deleting it there would re-introduce the stranding bug, since parked nodes are dormant (_waitingForFont === true) and only a successful retry walking the preserved list can wake them.SdfFontHandler.test.tsgains a regression test that parks a node → fails the first load → retries → succeeds, asserting the node is woken. Verified it fails against the old overwrite (spy called 0 times) and passes with the fix.Verification
pnpm exec vitest run src/core/text-rendering/→ 29/29 passpnpm exec tsc --build→ clean🤖 Generated with Claude Code