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

When using useSWRInfinite with {revalidateOnMount: true, revalidateFirstPage: false}, if there is a useLayoutEffect, the component will not make a new request when it is mounted. #3042

Open
turnflowerdown opened this issue Nov 19, 2024 · 0 comments

Comments

@turnflowerdown
Copy link

Bug report

Description / Observed Behavior

When using useSWRInfinite with {revalidateOnMount: true, revalidateFirstPage: false}, if there is a useLayoutEffect with change state in it, the component will not make a new request when it is again mounted.

Expected Behavior

Enter the component again need to send a new request

Repro Steps / Code Example

  1. Load components for the first time,success send a request
  2. Return to the previous page
  3. Enter the component again, and no request is sent
  const [state, setState] = useState(true);
  useLayoutEffect(() => {
    setState(false);
  }, []);

  useSWRInfinite(index => ({
    pageNum: index + 1,
    pageSize: 20,
  }), fetcher, {
    revalidateOnMount: true,
    revalidateFirstPage: false,
  });

Additional Context

swr      2.2.5
react    18.3.1
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

No branches or pull requests

1 participant