mirror of
https://github.com/dergigi/boris.git
synced 2026-01-04 23:44:21 +01:00
fix: ensure fonts are fully loaded before applying styles
- Convert loadFont to async function that returns a Promise - Use Font Loading API to wait for fonts to be actually ready - Add comprehensive logging for font loading stages - Wait for font loading in useSettings before applying CSS variables - Update Settings component to handle async font loading - Prevents FOUT (Flash of Unstyled Text) by ensuring fonts are ready - Fixes timing issue where custom fonts weren't being applied consistently This ensures custom fonts are fully loaded and ready before being applied, eliminating the race condition where content would render with system fonts before custom fonts were available.
This commit is contained in:
@@ -39,13 +39,15 @@ const Settings: React.FC<SettingsProps> = ({ settings, onSave, onClose }) => {
|
||||
useEffect(() => {
|
||||
// Preload all fonts for the dropdown
|
||||
const fonts = ['inter', 'lora', 'merriweather', 'open-sans', 'roboto', 'source-serif-4', 'crimson-text', 'libre-baskerville', 'pt-serif']
|
||||
fonts.forEach(font => loadFont(font))
|
||||
fonts.forEach(font => {
|
||||
loadFont(font).catch(err => console.warn('Failed to preload font:', font, err))
|
||||
})
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
// Load font for preview when it changes
|
||||
const fontToLoad = localSettings.readingFont || 'source-serif-4'
|
||||
loadFont(fontToLoad)
|
||||
loadFont(fontToLoad).catch(err => console.warn('Failed to load preview font:', fontToLoad, err))
|
||||
}, [localSettings.readingFont])
|
||||
|
||||
// Auto-save settings whenever they change (except on initial mount)
|
||||
|
||||
Reference in New Issue
Block a user