refactor(font): replace fontLifecycleManager singleton with lazy accessor
Convert the eager fontLifecycleManager singleton to getFontLifecycleManager() (+ __resetFontLifecycleManager for tests), so its AbortController/FontFace bookkeeping is set up on first use rather than at module load. Update consumers (FontVirtualList, FontList, SampleList) and resolve it once as a field in comparisonStore; the comparisonStore mock now exposes getFontLifecycleManager.
This commit is contained in:
@@ -419,7 +419,18 @@ export class FontLifecycleManager {
|
||||
}
|
||||
}
|
||||
|
||||
let _fontLifecycleManager: FontLifecycleManager | undefined;
|
||||
|
||||
/**
|
||||
* Singleton instance — use throughout the application for unified font loading state.
|
||||
* App-wide font lifecycle manager, created on first access. Lazy so its
|
||||
* AbortController / FontFace bookkeeping isn't set up at module load.
|
||||
*/
|
||||
export const fontLifecycleManager = new FontLifecycleManager();
|
||||
export function getFontLifecycleManager(): FontLifecycleManager {
|
||||
return (_fontLifecycleManager ??= new FontLifecycleManager());
|
||||
}
|
||||
|
||||
// test-only reset, so specs don't share loaded-font/eviction state
|
||||
export function __resetFontLifecycleManager() {
|
||||
_fontLifecycleManager?.destroy();
|
||||
_fontLifecycleManager = undefined;
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ import { createFontLoadRequestContfig } from '../../lib/createFontLoadRequestCon
|
||||
import {
|
||||
type FontLoadRequestConfig,
|
||||
type UnifiedFont,
|
||||
fontLifecycleManager,
|
||||
getFontCatalog,
|
||||
getFontLifecycleManager,
|
||||
} from '../../model';
|
||||
|
||||
interface Props extends
|
||||
@@ -53,6 +53,7 @@ let {
|
||||
}: Props = $props();
|
||||
|
||||
const fontCatalog = getFontCatalog();
|
||||
const fontLifecycleManager = getFontLifecycleManager();
|
||||
|
||||
const isLoading = $derived<boolean>(fontCatalog?.isLoading);
|
||||
const isFetching = $derived<boolean>(fontCatalog.isFetching);
|
||||
|
||||
Reference in New Issue
Block a user