ssg doesn't work for new data

When a user creates a new post, it doesn't generate a new site. I thought I could achieve that through revalidate but it doesn't seem to work. This is the code of post/[id].tsx:
export const getStaticPaths: GetStaticPaths = async () => {
const posts = await prisma.post.findMany();
// TODO: this can cause problems if we run this the first time the database is reset
if (posts) {
return {
paths: posts.map((post) => ({
params: {
id: post.id,
},
})),
fallback: false,
};
} else {
return {
paths: [],
fallback: false,
};
}
};

export const getStaticProps = async (
// this is the id from the page
context: GetStaticPropsContext<{ id: string }>
) => {
const ssg = createProxySSGHelpers({
router: appRouter,
transformer: superjson,
ctx: await createContextInner({ session: null }),
});

await ssg.post.getAllPosts.prefetch();

return {
props: {
trpcState: ssg.dehydrate(),
id: context.params?.id,
},
revalidate: 1,
};
};
export const getStaticPaths: GetStaticPaths = async () => {
const posts = await prisma.post.findMany();
// TODO: this can cause problems if we run this the first time the database is reset
if (posts) {
return {
paths: posts.map((post) => ({
params: {
id: post.id,
},
})),
fallback: false,
};
} else {
return {
paths: [],
fallback: false,
};
}
};

export const getStaticProps = async (
// this is the id from the page
context: GetStaticPropsContext<{ id: string }>
) => {
const ssg = createProxySSGHelpers({
router: appRouter,
transformer: superjson,
ctx: await createContextInner({ session: null }),
});

await ssg.post.getAllPosts.prefetch();

return {
props: {
trpcState: ssg.dehydrate(),
id: context.params?.id,
},
revalidate: 1,
};
};
It works in dev mode (due to dev mode), but it doesn't work in production (vercel)
49 Replies
Johnson
Johnson2y ago
the not generated sites just 404
barry
barry2y ago
I doubt the revalidation works properly locally but it’s set to 1 second lol
Johnson
Johnson2y ago
I assume I should make that a bit bigger?
barry
barry2y ago
If it updates every second that’s fine 😂
Johnson
Johnson2y ago
well idk if it's the revalidate, but it does work locally, just takes a long time to load for some reason
barry
barry2y ago
Revalidation isn’t enabled for development
Johnson
Johnson2y ago
ohhhh
barry
barry2y ago
It’s just a normal request every time
Johnson
Johnson2y ago
u think changing revalidate will fix the problem? I might not understand correctly
barry
barry2y ago
It’s just x seconds
Johnson
Johnson2y ago
revalidate generally makes all the sites that have not been generated so far, generate, right? At least that's how I thought of it
barry
barry2y ago
You’re just passing x seconds It will only re run the code if there has been more than x seconds since last “run” Else it will just return a cached response
Johnson
Johnson2y ago
yeah okay
barry
barry2y ago
There’s also on demand revalidation Haven’t tried it myself though
Johnson
Johnson2y ago
yeah I read about that, but I really wonder why the current code won't generate the new site
barry
barry2y ago
Errors? And how do you know it isn t
Johnson
Johnson2y ago
after all, if validate is 1, it should try every second I guess well I get a 404 when I try to connect and when I re-deploy it works
barry
barry2y ago
Server error?
Johnson
Johnson2y ago
I can check vercels functions, but I don't think there is anything in there
barry
barry2y ago
It doesn’t just 404 😂 If it did without erroring I would be scared
Johnson
Johnson2y ago
maybe its not an error directly, but the code itself is just wrong one sec
barry
barry2y ago
Your paths are wrong You just passed [] Oh nvm phone view cursed Debug time
Johnson
Johnson2y ago
I get this, but this is just because I check for auth each time a user conects
Johnson
Johnson2y ago
so no, vercel doesn't really give me any errors, so I think the code is just wrong
barry
barry2y ago
What if you build and run locally
Johnson
Johnson2y ago
one sec same thing so its not vercel, its the code
barry
barry2y ago
No errors either?
Johnson
Johnson2y ago
console is clear
barry
barry2y ago
Put on GitHub I clone when I get home
Johnson
Johnson2y ago
ke
Johnson
Johnson2y ago
GitHub
GitHub - vothvovo/nextjsdebug: oof
oof. Contribute to vothvovo/nextjsdebug development by creating an account on GitHub.
Johnson
Johnson2y ago
done I put everything I know inside the readme.md
barry
barry2y ago
@Johnson Deployed it myself, nothing wrong. https://nextjsdebug.vercel.app/post/cl9mucr7c0000ju09ja9mm51o As you can see, I put revalidation on 1 minute, the ISO string which is a date only changes if a minute has passed. No problems.
Johnson
Johnson2y ago
wut
barry
barry2y ago
Don't know what you did wrong lol Forgot to add env variables on Vercel's config?
Johnson
Johnson2y ago
I just logged in and created a new post click on it it will give you a 404
barry
barry2y ago
lol your discord account fucked up
Johnson
Johnson2y ago
wut
barry
barry2y ago
Oh I get why lol Lemme test something Yh you can't do it this way
Johnson
Johnson2y ago
fyi the sites do generate if you re-deploy
barry
barry2y ago
getStaticPaths only runs at build time.
Johnson
Johnson2y ago
yeah but I thought
barry
barry2y ago
So the routes don't exist Which is the problem
Johnson
Johnson2y ago
through revalidate I can re-run that damn
barry
barry2y ago
It does but not getStaticPaths
Johnson
Johnson2y ago
ohh so I only run getStaticProps on revalidate well how do I solve this problem then
barry
barry2y ago
csr / ssr
Johnson
Johnson2y ago
can I implement some kind of logic that makes sure to only run ssr when there is no site available(so basically I haven't re-deployed yet)?
Want results from more Discord servers?
Add your server