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

fix: resolve problem with null request on the first load #16

Merged
merged 1 commit into from
May 16, 2024

Conversation

stepan-twnty
Copy link
Contributor

@stepan-twnty stepan-twnty commented May 15, 2024

I'm pretty sure the problem with the null request is connected to a missing guard.

When react renders your component the imgData is null. According to docs on the first render, React builds your component then injects it into the DOM, and only then runs useEffects.

In our case:

  1. We have the state imgData with the value null.
  2. React build component and inject this
<Img
          id="imageZoom"
          src={imgData} // Keep in mind this state is still null
          alt={alt}
          style={{ opacity: zoomed }}
          width={width}
          height={height}
        />

to DOM.
3) Browser requests the image with src null
4) Only then the React runs UseEffect with the correct image src.

My changes should prevent this null request

@stepan-twnty stepan-twnty mentioned this pull request May 15, 2024
@Mario-Duarte Mario-Duarte self-requested a review May 16, 2024 20:56
@Mario-Duarte Mario-Duarte merged commit e247924 into Mario-Duarte:master May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants