Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Avatar] Adding support for Framework image #3154

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Udhayarajan
Copy link

@Udhayarajan Udhayarajan commented Sep 28, 2024

Description

Hi Team,

I'm proposing a new suggestion to address issue #2230 on top of existing PR #2999

I've implemented this solution by removing the prefetch image which helps to determine the image loading error.

Since Primitive.img already handles OnLoad and OnError events, it makes sense to leverage these callbacks for handling image load failures in a single fetch.

Changes Introduced

  • On the first render, Primitive.img is displayed, and its OnLoad and OnError callbacks are subscribed through an intermediate handler:
    • Loading: The image’s style.display is set to none.
    • Success: The display property is updated to the user-specified value.
    • Failure: The component re-renders, returning null to display the fallback.
  • Removed the useImageLoadingStatus custom hook, simplifying the image loading process:
    function useImageLoadingStatus(src?: string, referrerPolicy?: React.HTMLAttributeReferrerPolicy) {

NOTE: I don't find any other use-case of useImageLoadingStatus hook, other than tracking image loading status

What This Solves

  • Enables better integration with framework-specific optimizations (e.g., Next.js’s Image component).

Visual Comparison

Before:

before.mp4

After:

after.mp4

EDIT:
Upon toggling Disable Cache off It makes only one request

@Udhayarajan Udhayarajan changed the title [Avatar] Optimize Image Loading by Removing Duplicated Fetch and Adding support for Framework image [Avatar] Adding support for Framework image Sep 28, 2024
@Udhayarajan Udhayarajan marked this pull request as draft September 28, 2024 09:43
@Udhayarajan Udhayarajan marked this pull request as ready for review September 28, 2024 09:58
@chaance chaance added the Resolution: Needs Investigation This issue needs more investigation label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs Investigation This issue needs more investigation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants