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

Data is not updated when fallbackData and revalidateOnMount: false are provided #1852

Closed
VladimirMikulic opened this issue Feb 11, 2022 · 3 comments

Comments

@VladimirMikulic
Copy link

Bug report

Description / Observed Behavior

Data is not updated when fallbackData and revalidateOnMount: false are provided.
It doesn't matter that the key changes, the actual request is never made to get the new data based on that key.

Expected Behavior

I would expect SWR to fetch new data on key change.

Repro Steps / Code Example

Here's how our code looks like:
(we would like to take advantage of SSG and not request the data on client-side upon mount - only if the key changes)

const getEndpoint = (page, count, filters) => {
   // returns new endpoint based on filters like: https://my-api.com?page=1&count=10&buyPrice=true
}

const Page = ({ fallbackData }) => {
  const [filters, setFilters] = useState(defaultFilters)

  const onChange = () => {
    ...
    setFilters(newFilters)
  }

  // Filters change, new endpoint is generated, but fetcher is never called
  const { data } = useSWRInfinite(
    (pageIndex) => getEndpoint(pageIndex + 1, 10, filters),
    fetcher,
    { fallbackData, revalidateOnMount: false }
  );

  return (...)
}

export async function getServerSideProps(context) {
  const fallbackData = await getFallbackData(context.query);
  
  return {
    props: {
      fallbackData
    },
  };
}

Additional Context

SWR version: 1.2.1
Next.js: 12.0.10

@koba04
Copy link
Collaborator

koba04 commented Feb 18, 2022

This seems to be fixed by #1837 and please see the test of #1847, so I expect your issue would be solved in the next release.

@koba04
Copy link
Collaborator

koba04 commented Feb 22, 2022

1.2.2 has been released, so now you can try this on the version.

@VladimirMikulic
Copy link
Author

It works! Thank you so much @koba04!

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

2 participants