This is contrived issue reproduction between Next.js and Xata.
When using Xata in a dynamic route with getStaticParams
it will cause a runtime shift between first build and rebuilds. This happens because incrementalCache
seems to switch values from first build.
โ๏ธ Issue happens only in development
Deployed app: xata-nextjs-getstaticparams.vercel.app
Passing a hardcoded next.revalidate
option on build will stick it to either dynamic or static.
Dynamic
const xata = new XataClient({
fetch: (path, options) => {
return fetch(path, {
...options,
next: {
revalidate: false,
},
});
},
});
Static
const xata = new XataClient({
fetch: (path, options) => {
return fetch(path, {
...options,
next: {
revalidate: 10,
},
});
},
});
Environment Based
const xata = new XataClient({
fetch: (path, options) => {
return fetch(path, {
...options,
next: {
revalidate: process.env.NODE_ENV === "development" ? 0 : 60,
},
});
},
});
The problem with the workaround is that the user will need to always generate their own instance instead of leveraging the codegen to its maximum potential.
The SDK can uses the fetch
instance from Next.js without needing to hardcode any default value.
pnpm i && pnpm dev
Serves in localhost:3000
This app requires a Xata account, once you have one add your access token to your .env
or .env.local
to run it locally.
XATA_API_KEY=<token>
The .xatarc
carries the build configuration to your app. codegen.output
will tell the CLI where to put the generated SDK code. While the databaseURL
is your Database URL. You can generate it using the Xata CLI, manually, or via the VS Code Extension.
๐ก It is also possible to pass
--databaseUrl
and--output
flags to thexata:codegen
task and skip the.xatarc
completely.
Posts
Column | Type |
---|---|
id |
string |
slug |
string |
title |
string |
๐ก You can use the Example Database on Xata Web UI.
Thanks to @Sam-Apostel for first finding this at sam-apostel/blog