Skip to content

Avatars flash on mount even if cached #2044

Open
@lauri865

Description

@lauri865

Bug report

Current Behavior

Avatars never render on first mount, even if cached.

Expected behavior

If avatar image is cached by the browser, the image should render straight away on initial mount.

Reproducible example

Refresh this page: https://www.radix-ui.com/docs/primitives/components/avatar

Suggested solution

Instead of loading the image in useEffect, the image loading should be started directly in the useState initializer. If the image is cached, image.complete of new Image will return true synchronously, and then the state value can be returned as "loaded" right away.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions