Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Next.js 13 - Why isn't my root page dynamic

I am making a website with Next.js 13.0. When I run next build, all the pages work except my root page. It's being built as static when I want it to be dynamic. I even have export const dynamic = "force-dynamic" in my code yet it continues to build as a static page. It's no different from my dynamic pages so I don't get what's the problem.

The code for src/app/page.tsx:

import { collection, getDocs, limit, orderBy, query } from "firebase/firestore"
import Article from "@components/Article"
import { ArticleData } from "@types"
import { db } from "@firebase"

export const dynamic = "force-dynamic"

const getArticles = async () => {
  const articles: ArticleData[] = []

  const snapshot = await getDocs(
    query(collection(db, "articles"), orderBy("created", "desc"), limit(5))
  )

  snapshot.forEach((doc) => {
    articles.push({
      ...doc.data(),
      id: doc.id,
    } as ArticleData)
  })

  return articles
}

const Home = async () => {
  const articles = await getArticles()

  return (
    <>
      {articles.map((data, i) => (
        <Article key={i} data={data} />
      ))}
    </>
  )
}

export default Home

Any ideas?

like image 999
ntedvs Avatar asked Oct 20 '25 11:10

ntedvs


1 Answers

Replace this export const dynamic = "force-dynamic" by this code export const revalidate = 0

My source https://supabase.com/blog/fetching-and-caching-supabase-data-in-next-js-server-components

like image 162
moundziegou gabin Avatar answered Oct 23 '25 01:10

moundziegou gabin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!