MCPcopy Create free account
hub / github.com/fontsource/fontsource / triggerFontLoad

Function triggerFontLoad

website/app/hooks/useIsFontLoaded.ts:73–97  ·  view source on GitHub ↗
(cacheKey: string, fontFaces: FontFace[])

Source from the content-addressed store, hash-verified

71};
72
73const triggerFontLoad = (cacheKey: string, fontFaces: FontFace[]) => {
74 if (fontStatusCache.has(cacheKey)) {
75 return; // Already loading or loaded.
76 }
77
78 fontStatusCache.set(cacheKey, 'loading');
79
80 // Initial notification for the 'loading' state.
81 notify(cacheKey);
82
83 const promises = fontFaces.map((font) => loadFont(font));
84
85 Promise.all(promises)
86 .then(() => {
87 fontStatusCache.set(cacheKey, 'loaded');
88 })
89 .catch((error) => {
90 fontStatusCache.set(cacheKey, 'failed');
91 console.warn(`Failed to load font set: ${cacheKey}`, error);
92 })
93 .finally(() => {
94 // Final notification for 'loaded' or 'failed' state.
95 notify(cacheKey);
96 });
97};
98
99export const useFontStatus = (
100 family: string,

Callers 1

useFontStatusFunction · 0.85

Calls 4

notifyFunction · 0.85
loadFontFunction · 0.85
setMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected