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

Adding already rendered image has a small flicker #2492

Open
1 task done
kidroca opened this issue Mar 3, 2023 · 0 comments · May be fixed by #2493
Open
1 task done

Adding already rendered image has a small flicker #2492

kidroca opened this issue Mar 3, 2023 · 0 comments · May be fixed by #2493
Labels
bug has: pr Subject of a pull request
Milestone

Comments

@kidroca
Copy link

kidroca commented Mar 3, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

When we're (repeatedly) adding the same image on screen there's a small flicker happening the first time the component renders

For example the avatars of a chat app

  • each time a message is added/received the avatar of the new message flickers
  • even though the avatar is the same as the one rendered on previous messages above

Expected behavior

Adding the same image twice, should render instantly the 2nd time it's used

Steps to reproduce

Browser: Chrome
ENV: codesandbox
react-native-web: 0.18.12

Steps:

  1. Go to the test case address
  2. Press the "Add More" button at the top a few time
  3. Notice each time the images flicker
  4. (Optional) uncomment the defaultSource (L34) and repeat the steps - no flicker occurs
Screen.Recording.2023-03-03.at.12.22.40.mov

Test case

https://codesandbox.io/s/rnw-image-flicker-bug-sample-obbhov

Additional comments

There's no such problem if we use both defaultSource and source with the same source

<Image soruce={{ uri: '/my-image.jpg' }} defaultSource={{ uri: '/my-image.jpg' }} />

This is because of internal logic immediately rendering the defaultSource, while source is not rendered and always starts from IDLE state.
I've traced this back to refactoring the Image from class based to functional component, where we no longer add images to ImageUriCache (probably it was overlooked in the refactor?)


The flicker can be easily observer if we put a breakpoint in Image render's code

  1. First render - no dom element added, loading state IDLE ❌
  2. 2nd render - loading state IDLE, dom element added, but empty ❌
  3. 3rd render - loading state LOADED, dom element updated with image content ✅

Since the image was already rendered and is available on screen it should be immediately rendered at step 1

@kidroca kidroca added the bug label Mar 3, 2023
@necolas necolas added this to the 0.20: Image milestone Mar 20, 2023
necolas pushed a commit that referenced this issue Apr 10, 2023
If the Image component is rendered with a `null` source, and consecutively
updated with actual source url that was already loaded, it would fail to
pick up the change - `state` would be `IDLE` for a brief moment and
this would cause a small flicker when the image renders

Let's always start from IDLE state, and update `shouldDisplaySource`
condition to be based on `ImageLoader.has` cache or not

Fix #2492
@necolas necolas added the has: pr Subject of a pull request label Apr 10, 2023
necolas pushed a commit that referenced this issue Apr 10, 2023
If the Image component is rendered with a `null` source, and consecutively
updated with actual source url that was already loaded, it would fail to
pick up the change - `state` would be `IDLE` for a brief moment and
this would cause a small flicker when the image renders

Let's always start from IDLE state, and update `shouldDisplaySource`
condition to be based on `ImageLoader.has` cache or not

Fix #2492
necolas pushed a commit that referenced this issue Apr 12, 2023
If the Image component is rendered with a `null` source, and consecutively
updated with actual source url that was already loaded, it would fail to
pick up the change - `state` would be `IDLE` for a brief moment and
this would cause a small flicker when the image renders

Let's always start from IDLE state, and update `shouldDisplaySource`
condition to be based on `ImageLoader.has` cache or not

Fix #2492
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug has: pr Subject of a pull request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants