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

fetchOptions not caching in nextjs #1311

Open
kostasb opened this issue Jan 8, 2024 · 0 comments
Open

fetchOptions not caching in nextjs #1311

kostasb opened this issue Jan 8, 2024 · 0 comments
Labels
bug Something isn't working needs-triage

Comments

@kostasb
Copy link
Contributor

kostasb commented Jan 8, 2024

Describe the bug
As noted in xataio/mdx-docs#206 the fetchOptions SDK parameter passes additional options to Next.js to configure the caching behavior.

Trying to verify with the Next.js Starter app, I changed the getAll call to .getMany({ pagination: { size: 10 }, fetchOptions: { next: { revalidate: '3600' } } }).

However, upon editing a record in the Xata table and refreshing the page, the app shows the latest record value instead of the previously cached result.

Repro log:

npx degit xataio/examples/apps/getting-started-nextjs xata-nextjs
cd xata-nextjs
npm install
xata init
curl https://raw.githubusercontent.com/xataio/examples/main/seed/blog-posts.csv --create-dirs -o seed/blog-posts.csv
xata import csv seed/blog-posts.csv --table Posts --create
xata pull main
edit /src/app/page.tsx to add the fetchOptions parameter
npm run dev

edit Posts table "title" column of one of the 10 rendered records.
Refresh the page on the browser.

I have tried this with both next@13.4.19 and next@14.0.4.

This is in line with relevant user report on Discord.

For the record, per internal discussion I've also tried using a standard fetch with the same parameters, which also had the same not-caching behavior under getServerSideProps.

export const getServerSideProps = async () => {
  const a = await fetch("https://repro-q867qv.eu-west-1.xata.sh/db/my-xata-app:main/tables/Posts/data/rec_cm20jmhmv7907b15049g",{headers:{Authorization: 'Bearer xau_...'},next: {revalidate: 3600}})
  console.log(a)
  const data = await a.json();
  console.log(data);
...
}

The purpose of this issue is to determine how / what is required for the TS SDK to enable/work with Next.js caching before we document the fetchOptions parameter.

@kostasb kostasb added the bug Something isn't working label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

No branches or pull requests

1 participant