Skip to content

Font loading status #3876

@andreasgangso

Description

@andreasgangso

Clear and concise description of the problem

As a developer using VueUse I want to know the current status of all or certain fonts so that i can show a loading spinner or avoid showing text until the font is loaded.

Suggested solution

export const useFontsReady = createSharedComposable(async () => {
    const ready = ref(false);
    const error = ref<unknown>();

    async function waitForFonts() {
        if (('fonts' in document)) {
            try {
                await document.fonts.ready;
            } catch (e) {
                error.value = e;
            }
        }
        ready.value = true;
    }
    waitForFonts();

    return { ready, error };
});

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions