Next.js Discord

Discord Forum

dynamic routing without static generation?

Unanswered
Giant Chinchilla posted this in #help-forum
Open in Discord
Giant ChinchillaOP
Hello,
New to nextjs and development in general.
I'm building an application with firestore and nextjs13 that allows users to share images with each other. sort of like instagram I guess, to develop my skills.

https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes
This seems to be geared towards statically generating on build time, which makes sense for blog posts, or e-commerce websites where the owner of the platform is doing the updates. But what about a social network where users themselves upload images? I would like for each uploaded image to have its own post link.

https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#revalidate

I know about using revalidate but I dont really understand how this works with image pages that are uploaded after build time, and how can it be triggered on-demand (i can set revalidate to say 10s so that after a user uploads an image they can immediately visit the page, but it feels inefficient.)

Overall im trying to understand how to manage a platform that generates urls based on user-submitted posts. If theres any resources you could point me towards, that would also be much appreciated

3 Replies

Giant ChinchillaOP
Actually I think this was kind of a dumb question...
export async function generateStaticParams(id: string) {
  return [
    {
      id: {
        image: `image${id}`,
        user: `user${id}`,
        imageUrl: `imageUrl${id}`,
        likes: `likes${id}`,
      },
    },
  ];
}

this kind of solves my question, but i need to test the build version to understand if it works the way i think it does
Giant ChinchillaOP
nope this doesnt work :/
American
Hi mate,

I experienced a similar issue with revalidation on Next13 with my forum platform. Typically, forums consist of topics and posts. They also feature new posts, announcements, and trending threads on the home page. I managed this challenge primarily through logging.

Please note that you can't log the user path in the backend controller as the route is prefetched and the controller will erroneously determine that the user is on the page when they're actually not. I've been keeping logs when a user visits a category, topic, or the home page.

Every time a user alters their route, a client request is sent to check for any modifications on that specific path. If there are changes, then the command useRouter().refresh() is initiated (with useRouter defined as a const, of course).

Also, you can use websocket for realtime data.

This process might be intricate, contingent upon the project's structure, but there are many strategies to manage it. Best of luck to you, and feel free to reach out if you need further assistance.