dynamicParams = false, still tries to render page on Vercel?
Unanswered
Ancient Murrelet posted this in #help-forum
Ancient MurreletOP
I have a fairly trivial page.tsx file, where dynamicParams is set to false. i.e. it should not render 404 for any page that should not exist.
However, when I deploy to Vercel and try to visit any page that is not supposed to exist e.g.
And in the logs it's clear that it tries to to render the page and I even get an error from tRPC :
Any idea why?
When I do build I do get the following error:
However, when I deploy to Vercel and try to visit any page that is not supposed to exist e.g.
/wiki/pancakes I get an application error.And in the logs it's clear that it tries to to render the page and I even get an error from tRPC :
result: l [TRPCClientError]: path failed validation: path.block_id should be a valid uuid, instead was "pancakes"Any idea why?
When I do build I do get the following error:
result: l [TRPCClientError]: Dynamic server usage: Page couldn't be rendered statically because it used "headers", for each page that's supposed to be rendered, if that's relevant.import React from "react"
import { WikiContent } from "~/app/wiki/_components"
import tempData from "../tempData.json"
import { api } from "~/trpc/server"
export default async function Wiki({ params }: { params: { id: string } }) {
const data = await api.notion.getPageBlocks.query({ id: params.id })
return (
<div className="bg-background2 w-100 min-h-screen flex flex-col items-center p-4">
<main className="ml-0 md:ml-[240px] flex flex-col min-h-screen mt-18 md:mt-0">
<div className="p-4 flex flex-col gap-4 w-full max-w-screen-lg mx-auto">
<div>
<WikiContent blocks={data.results} />
</div>
</div>
</main>
</div>
)
}
export const dynamicParams = false
export function generateStaticParams() {
const pages = tempData.result.data.json.results
return pages.map((page) => ({
id: page.id
}))
}47 Replies
Ancient MurreletOP
Thanks ðŸ™
that is the TRPCClient client throwing an error... vercel/nextjs doesn't have any control on it...
@riský that is the TRPCClient client throwing an error... vercel/nextjs doesn't have any control on it...
Ancient MurreletOP
That is true. But my bigger question is, why is it even trying to render that page at all.
/pancakes should not exist.if you do a search for pancakes, it doesn't show up in code...
and does
tempData.result.data.json.results by any chance contain "pancakes"@riský and does `tempData.result.data.json.results` by any chance contain "pancakes"
Ancient MurreletOP
No it contains long id's ergo
229b6fb5-3720-4c5e-acf8-222b7e90be6aRight now for testing purposes it only generates three pages.
Regardless, pancakes was just an example. 1234, banana, applepie, all cause an application error.
As it tries to render any page
your last error, makes sense... you can't use the headers function and have the page static
@Ancient Murrelet No it contains long id's ergo `229b6fb5-3720-4c5e-acf8-222b7e90be6a`
this is kinda weird that it gets pancakes...
Ancient MurreletOP
Yeah, even though it complains about that thing this is still what the logs says in the end.
that it spat out 3 static pages.
you still should remove headers usage if you want static page
Ancient MurreletOP
Yeah, I guess I could try forcing static and see what happens, as it removes headers.
I think it's just wonky interactions with tRPC causing issues I imagine.
Might be a bit too early to start a project with the appDir and tRPC.
also can you try returning the
notFound() function if data is undefined (or validate that the param isn't in tempData)as i think it is making it dynamic (from headers usage), so you should remind it that that only certain pages should work...
Ancient MurreletOP
True! Not a bad idea.
force-static broke everything 😅I'm running into a bunch of other issues too with tRPC now.
Like it's not caching the results at all and it refetches everything every time I switch pages...
Like it's not caching the results at all and it refetches everything every time I switch pages...
thats because you are using headers... nextjs kinda doesn't cache it when they are used (even if its only used in layout)
Ancient MurreletOP
I think I'll just go back to the pages dir to be honest, or skip tRPC. Appreciate the help : )
if you remove the usage of headers, it will work
otherwise, you can use things like
unstable_cache to cache the queries (or use the nextjs fetch api to cache responses from response of req)Ancient MurreletOP
Yeah. I'm using a beta branch of https://create.t3.gg/ that uses app dir instead of pages.
This is the file they use for fetch requests on the server. It's a bit odd that they do use headers in it 👀
This is the file they use for fetch requests on the server. It's a bit odd that they do use headers in it 👀
import {
createTRPCProxyClient,
loggerLink,
unstable_httpBatchStreamLink
} from "@trpc/client"
import { headers } from "next/headers"
import { type AppRouter } from "~/server/api/root"
import { getUrl, transformer } from "./shared"
export const api = createTRPCProxyClient<AppRouter>({
transformer,
links: [
loggerLink({
enabled: (op) =>
process.env.NODE_ENV === "development" ||
(op.direction === "down" && op.result instanceof Error)
}),
unstable_httpBatchStreamLink({
url: getUrl(),
headers() {
const heads = new Map(headers())
heads.set("x-trpc-source", "rsc")
return Object.fromEntries(heads)
}
})
]
})You've been super duper helpful. Last thing. ðŸ™
Could you elaborate on this?
Could you elaborate on this?
(or use the nextjs fetch api to cache responses from response of req).like if you use the fetch api on nextjs, it caches the response of the request, so if you do the same query, it won't need to run it again (and you can customize its cache by using re-validate time and manually re-validating it with tags)
Ancient MurreletOP
Yeah, normal fetch seems great.
tRPC is giving me a headache trying to figure out how to do the same things.
note: i haven't ever used tRPC, but it doesn't sound that worth it for me (esp after reading about this)
Ancient MurreletOP
It's super cool with next 12, as you get automatic type safety between your client and server.
well, you can use server actions to have typing now... (but 3rd parties don't get very good apis then)
Ancient MurreletOP
And if you have like a monorepo or something I could see tRPC being worthwhile with the app dir too, as you could share the types across the whole project.
Yeah, server actions are still quite early o_o so a lil scared of those.
hmm monorepo does sound good then...
@Ancient Murrelet Yeah, server actions are still quite early o_o so a lil scared of those.
to be fair, they seems more stable than... this...
Ancient MurreletOP
True, haha 😅
Locally it works fine, it even caches the results from my tRPC requests, and dynamicParams works fine and gives a 404.
Just goin a lil crazy when trying to deploy.
even on prod mode localy (next build && next start)
Ancient MurreletOP
Yeah, locally too.
Anyways! Appreciate the feedback a ton : )
Gonna fiddle with a liiiitle bit or just change to fetch.
Have a super weekend!
@Ancient Murrelet Anyways! Appreciate the feedback a ton : )
sorry for not giving you the perfect answer, but glad to help as much as i could 🙂