Skip to content

WIP Reload lazy load props in WhenVisible when they become undefined #2392

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chack1172
Copy link
Contributor

This is an attempt to fix #2388 but it's not finished, it has some bugs.

It works when using the prop without the always attribute, but I'm struggling to make it work when it is true.

Since we cannot rely on useEffect to check if props are changed, because it will throw error before calling them, I switched the loading state to a ref and using an useMemo to check if props are changed checking that they are not undefined.

I then added the loading value to the useEffect so that when it change from true to false, it reload the props, but this will make it run twice, it make another request when it pass from false to true. I tried blocking it if props are loaded but this will make the always prop not work anymore.

I'm also having problem with current tests on WhenVisible component:

  • The server does not send the prop back, so loading will always be false
  • When using the params prop instead of passing data, the only key is not required so it will make all the lazy props to reset and so the loading ref will always be false. For example it is not passed in test on the fifth component:
<div style={{ marginTop: '6000px' }}>
        <WhenVisible
          fallback={<div>Loading fifth one...</div>}
          always
          params={{
            data: {
              count,
            },
            onSuccess: () => {
              setCount((c) => c + 1)
            },
          }}
        >
          <Foo label={`Count is now ${count}`} />
        </WhenVisible>
      </div>```

@chack1172 chack1172 marked this pull request as draft June 20, 2025 13:50
@chack1172 chack1172 force-pushed the fix/when-visible-reload branch from 3953b1f to 8203ebb Compare June 20, 2025 13:52
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.

WhenVisible broke on reload
1 participant