Skip to content

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

Description

@turnflowerdown

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions