Why an API request is made in SSG with revalidate: false? #1890
-
Everything is working fine, I'm just trying to understand things. I have a component using SSG and Then, I have disabled javascript and it worked like I've expected: when I open the page, the data that is in the JSON file is served and no API request is made. What I would like to know is: 1 - Is this behavior expected (to always make a request even if Here's the code if it helps understand better
import { useRouter } from 'next/router'
import Head from 'next/head'
import { gql, useQuery } from 'urql'
import { withUrqlClient } from 'next-urql'
import { client, ssrCache } from 'utils/urql'
import db from 'utils/prisma'
const TOPIC_QUERY = gql`
query GetTopic($topicId: Int!) {
topic(input: { id: $topicId }) {
id
name
description
}
}
`
function Topic() {
const router = useRouter()
const { id } = router.query
const [result] = useQuery({ query: TOPIC_QUERY, variables: { topicId: Number(id) } })
const { fetching } = result
if (fetching) return <p>Getting data...</p>
const {
data: { topic },
} = result
return (
<>
<Head>
<title>{topic.name}</title>
</Head>
<p>
{topic.name} - {topic.description}
</p>
</>
)
}
export async function getStaticProps({ params }) {
await client.query(TOPIC_QUERY, { topicId: Number(params.id) }).toPromise()
return {
props: { urqlState: ssrCache.extractData() },
revalidate: false,
}
}
export async function getStaticPaths() {
const topics = await db.topic.findMany({ select: { id: true } })
const paths = topics.map((topic) => ({ params: { id: `${topic.id}` } }))
return { paths, fallback: false }
}
export default withUrqlClient(
(ssr) => ({
url: `${process.env.NEXT_PUBLIC_API_URL}`,
}),
{ ssr: false }
)(Topic) Thank you in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey i've just tried this myself and am not running into the issue 😅 https://codesandbox.io/s/inspiring-rubin-52wrc?file=/pages/index.js the issue could reside in the difference of our |
Beta Was this translation helpful? Give feedback.
Hey
i've just tried this myself and am not running into the issue 😅 https://codesandbox.io/s/inspiring-rubin-52wrc?file=/pages/index.js the issue could reside in the difference of our
getStaticProps
function or theexchanges
you're using in your client