Skip to content

fix: suppress spurious font warnings during R3F teardown#261

Open
sawa-zen wants to merge 1 commit into
pmndrs:mainfrom
sawa-zen:fix/suppress-teardown-font-warnings
Open

fix: suppress spurious font warnings during R3F teardown#261
sawa-zen wants to merge 1 commit into
pmndrs:mainfrom
sawa-zen:fix/suppress-teardown-font-warnings

Conversation

@sawa-zen

Copy link
Copy Markdown

Problem

When React Three Fiber unmounts a component tree, removeChild calls parent.object.remove(child.object) on each three.js object. This triggers uikit's "removed" event handler (updateParentState), which calls properties.setEnabled(false), resetting all property signals to their defaults.

Since computedFont uses a raw effect() (not controlled by abortController), it re-evaluates when fontFamiliesSignal changes to undefined. The effect falls back to defaultFontFamiles ({ inter }), and if the component had a non-default fontFamily (e.g. "ja" for Japanese), it logs:

  • unknown font family "ja". Available font families are "inter". Falling back to "inter".
  • Missing glyph info for character "ラ" (for each character not in the inter font)

These warnings are harmless — the component is being destroyed — but noisy, especially with CJK text that produces one warning per character.

Fix

Skip font loading when fontFamiliesSignal.value is undefined. This value being undefined reliably indicates a fallback/teardown state (properties have been reset) rather than an explicit font configuration. In normal operation, fontFamiliesSignal.value is always set (either from own props or inherited from parent).

This prevents both the "unknown font family" error and the subsequent "Missing glyph info" warnings.

Reproduction

  1. Create a uikit Container with fontFamilies including a non-Latin font
  2. Add Text children with fontFamily set to that font
  3. Unmount the component tree (e.g. navigate away in a React app)
  4. Observe console warnings during unmount

When React Three Fiber unmounts components, `removeChild` calls
`parent.object.remove(child.object)` which triggers uikit's "removed"
event handler. This resets properties via `setEnabled(false)`, causing
`fontFamiliesSignal.value` to become undefined. The `computedFont`
effect then re-evaluates, falls back to the default inter font, and
logs "unknown font family" / "Missing glyph info" warnings for any
non-Latin characters.

These warnings are harmless (the component is being destroyed) but
noisy. This fix skips font loading when `fontFamiliesSignal.value` is
undefined, which reliably indicates a fallback/teardown state rather
than an explicit font configuration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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