-
SummaryI'm trying to use the new Cache Components in my project, but ran into a question that I couldn't really understand. Here let's say I have a super simple page like this: export default function HomePage() {
return (
<div>
<p>This is the home page</p>
</div>
)
}As you can see, this is a static page, no runtime data or dynamic data fetching. However, since the Cache Components documentation says:
That makes me think even if this is a static page, Next.js will still treat it a dynamic page if I don't add export default function HomePage() {
"use cache"
return (
<div>
<p>This is the home page</p>
</div>
)
}But when I compile it, an error shows up saying:
Of course I can just follow the message to make my function async, but since there is actually no async operation in that function, I don't really think it's necessary. Besides, I'm not sure if there are any penalties if I make it async. So my question is:
Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Right, the thing here is that, you also need to remember that generating a static shell is part of the process. In your case, your page is nothing but static content, there's no dynamic/runtime behavior to handle, no fallback UI needed. Cache Components implements PPR, so it can just output the entire HTML for this page. If you added Also, since all pages generate a static shell, to be, potentially, filled in with dynamic/runtime content, you can totally inspect these in the build output, or better yet, see the React Dev Tools Suspense tab, which shows boxes where content with fallback exists and how it progresses over time.
We are actively working in the wording and teaching story of Cache Components. |
Beta Was this translation helpful? Give feedback.
Right, the thing here is that, you also need to remember that generating a static shell is part of the process.
In your case, your page is nothing but static content, there's no dynamic/runtime behavior to handle, no fallback UI needed. Cache Components implements PPR, so it can just output the entire HTML for this page. If you added
use cacheyou'd be telling Next.js, to also revalidate this page, but for such a page that's not needed.Also, since all pages generate a static shell, to be, potentially, filled in with dynamic/runtime content, you can totally inspect these in the build output, or better yet, see the React Dev Tools Suspense tab, which shows boxes where content with fallback…