Next.js Discord

Discord Forum

pages are SSG but should be dynamic

Answered
B33fb0n3 posted this in #help-forum
Open in Discord
Hey, I created mutliple pages and some of them are dynamic and some not (https://ibb.co/j3j0CYR). Now I tried to use a parallel route inside this admin dashboard (https://ibb.co/c2v5sfB) and everything works fine on localhost.

When I push it to vercel I get [this error](https://paste.gg/p/B33fb0n3/30ad8ff9aaa14edf955027f0af9d3929).

I followed the guide [here](https://nextjs.org/docs/messages/app-static-to-dynamic-error) and used export const dynamic = 'force-dynamic'. The result is the same: statically generated pages...

(the generateStaticParams shouldn't affect this behavior, because there are pages that are dynamic without using the export const dynamic...

How am I able to make my route dynamic?
Answered by Ray
I got it build on vercel with 14.1 by adding export const dynamic = "force-dynamic"; to admin/layout.tsx
View full answer

107 Replies

@Ray since you are using ppr, I think you could use `unstable_noStore` on a component to make it dynamic
are there other ways then using unstable_noStore, beccause it's a production app
@B33fb0n3 are there other ways then using unstable_noStore, beccause it's a production app
maybe disable ppr then, it is still experimental
you mean by setting this to false?
const nextConfig = {
  experimental: {
    ppr: true, <-------
  },
}

Currently this ppr: true is not inside my nextConfig
where can I check that?
Because it's an experimental feature and my app is a production app, I haven't looked into PPR yet :/
@B33fb0n3 and then it's automatically ppr?
no, not ppr, I was wrong, I mix the icon of ssg and ppr
oh ok. The page inside the @modal/[id] is a Client Component. With the params and searchparams it should be dynamic 🤔
It looks like:
'use client'

export default function ConfirmDialog({params: {id}, searchParams: {lang, status, email}}) {
    const {toast} = useToast();

    ...
}
@B33fb0n3 oh ok. The page inside the @modal/[id] is a Client Component. With the params and searchparams it should be dynamic 🤔
I think the route is dynamic as long as you don't set the dyanmicParams to false
since you using generateStaticParams on the [lang], so it show the page is SSG on the build log
ohh so the /admin/ is SSG, but the @modal is dynamic. And that's not possible, right?
it is dynamic now I think?
@B33fb0n3 ohh so the /admin/ is SSG, but the @modal is dynamic. And that's not possible, right?
are you getting 404 when navigating to admin/[id]?
@Ray it is dynamic now I think?
it's currently static, because the lang variable is pre defined and there are no other variables in it:
@Ray are you getting 404 when navigating to `admin/[id]`?
I don't.
I get a 500 | Internal Server Error
you should create admin/[id]/page.tsx
and return null
that works! No error. But also the "old page" won't be rendered. Inside my layout the modal will be rendered on top of the page. When I go to admin/[id], the modal isn't on top. Normally a parallel route is on top of another 🤔
normally the parallel route would be rendered "inside" the same route. So by navigating to /admin the page.js should be rendered (modal shouldn't be rendered, because there is no matching route). When I navigate to /admin/[id] there is a matching route and {children} and also the {modal && modal} should be rendered (because there is a matching route)
when adding the [id] as own route this "own route" will be rendered
@B33fb0n3 when adding the [id] as own route this "own route" will be rendered
yea, so you should do return null for your case
you want to render a /admin/[id] in a modal right?
currently it looks like that:
export default function IdPage() {
    return null
}
@Ray you want to render a /admin/[id] in a modal right?
yes. I am on the /admin page and there are Link-Components to /admin/[id]. When clicking a link a modal (on the same page) will open (through route) and you can do stuff inside the modal. The page in the background stays the same
It is. It's easily possible with clientside states, but I don't want to use them
When I navigate to /admin/[id] there is a matching route and {children} and also the {modal && modal} should be rendered (because there is a matching route)
because you didn't have /admin/[id] which is the entry point of the parallel route. so you will get 404 with just @modal/admin/[id]
and the reason why you get 500 is, you are trying to use searchParams.lang on a 404 route
it seems like what you try to tell me makes sense, but I currently can't follow you... are you able to write it a little differently?
@B33fb0n3 it seems like what you try to tell me makes sense, but I currently can't follow you... are you able to write it a little differently?
a parallel route require a route with one or more slot and you just created the slot without the route
if the route doesn't exist, it return 404.
oh ok. I thought that only applied to intercepting routes?
I just followed [this example](https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#examples) and couldn't find a route for example for "login" or for "signup" (in [this example](https://nextjs.org/docs/app/building-your-application/routing/parallel-routes#examples)) that is defined twice
The default.js handles the content when there is no route available
@Ray oh the default.js only handle unmatched slots not route
Oh, I see. How to get this working (I can just show the local result, because on localhost it works and on vercel not): https://youtu.be/fdsgIpKbCiU
@Ray how does it look like on vercel?
when I am at /admin it looks the same and when I navigate to a /admin/[id] I get the 500 Internal Server Error Page. The error in the background is [this](https://paste.gg/p/B33fb0n3/30ad8ff9aaa14edf955027f0af9d3929)
@Ray check the build log on vercel and see if you have the route for /admin/[id]
I just checked and can confirm the route /[lang]/landingpages/wishvideo/admin/[id] has been built
@B33fb0n3 I just checked and can confirm the route /[lang]/landingpages/wishvideo/admin/[id] has been built
I just test building on vercel and got this error
Unable to find lambda for route: /[lang]/admin/default
it build fine if I don't static generate for the lang
@Ray I just test building on vercel and got this error `Unable to find lambda for route: /[lang]/admin/default`
did you also added the staticParams functions (to the root layout)?
export async function generateStaticParams() {
    return i18n.locales.map((locale) => ({lang: locale}))
}
lol
so you may want to contact vercel support
ok, I will do that. Thanks 👍
@B33fb0n3 ok, I will do that. Thanks 👍
yea, try without generateStaticParams and see if it work
@Ray yea, try without `generateStaticParams` and see if it work
it works without it. On the other hand I have so many sites that can be easily build statically (and also should) so I need that. Maybe there is some way to optout specific routes from it like we saw with force-dynamic or noStore which both don't work..
are you able to create a web version of your code? I can take a look what I have differently
command not found
do I need to install something?
I can offer you one of these:
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
@Ray yes npm i -g vercel
build complete. The build progress works fine. No errors
it can build with 14.0.4
are you using 14.0.4?
@Ray does the page work?
yea it works
@Ray are you using 14.0.4?
currently I am using "next": "14.1.0",
that doesn't. The page itself works fine, but not the switch with the parallel route
I have no problem with 14.0.4 on vercel
did you also added the staticParams functions (to the root layout)?
export async function generateStaticParams() {
    return i18n.locales.map((locale) => ({lang: locale}))
}
How does it look here with you?
look like this with 14.1
and inside your /admin/default is the parallel route in the layout?
and your @modal/[id] also access the searchparams?
@B33fb0n3 and your @modal/[id] also access the searchparams?
yea
export default function Page({
  params,
  searchParams,
}: {
  params: { id: string };
  searchParams: { q: string };
}) {
  return (
    <div>
      modal {params.id} <br /> searchParams {searchParams.q}{" "}
    </div>
  );
}
try 14.0.4 if you are on 14.1
it is not working for me with 14.1 on vercel
The red page will be rendered (in the background) when navigating to an id and the green one, when you haven’t chosen one, correct?
Yea
And when navigating to /admin/[id] the red outlined page.js is in the background, right?
the red one only render when you are on /[lang]/admin/[id]
@B33fb0n3 And when navigating to /admin/[id] the red outlined page.js is in the background, right?
no it won't render when you are on /[lang]/admin/[id]
@Ray the red one only render when you are on `/[lang]/admin/[id]`
Ok, if I do it the same (with the extra route for [id] outside the modal) it also works for me, but it changes the background. In my video (localhost) you can see, that the background doesn’t change
it only render when you are on /[lang]/admin
I think you should use intercepting route if you want /[lang]/admin in the background
or you have to move @modal to the root
@Ray I think you should use intercepting route if you want `/[lang]/admin` in the background
I think these kind of routes are kinda confusing for me. I tried to rebuild the example and tried to make it dynamic but I guess it’s not that easy as it sounds like :/
@Ray or you have to move `@modal` to the root
to the root?
app/@modal
Isn’t it the same problem?
app/@modal/[id] is dynamic
app/………./admin/ is static
no, app/@modal this is a slot
but I think you want intercepting route if you want the previous page stay in background
@Ray but I think you want intercepting route if you want the previous page stay in background
an intercepting route? Which route would be intercepted? Because currently there is no own route for a specific id and I haven't planed it yet
@Ray `wishvideo/admin/@modal/(.)[id]`
if I try it like that I get the error that you already mentioned:
I also tried it with (..)[id] because the [id]-Route isn't in the same folder and got the same error
@B33fb0n3 I also tried it with (..)[id] because the [id]-Route isn't in the same folder and got the same error
yeah, that's why I said you should contact vercel support
14.0.4 build fine but not 14.1
14.1 build fine if not generate the params for lang
14.1 build fine on locally with and without the lang params generated
I now tried using 14.0.4 but that also doesn't work for me. Same error with "Unable to find ...". I can't contact vercel, because of my current plan
how does your route look like now
I got it build on vercel with 14.1 by adding export const dynamic = "force-dynamic"; to admin/layout.tsx
Answer
@Ray how does your route look like now
I first tried the force-dynamic with the intercepting route and it works without errors (building and using) and after that I tried the same with just the modal with [id] and nothing more (https://ibb.co/bbWKMyS) and that also works without problems. Working with 14.1.0
I checked the build log and the "dynamic page" is now static lol and with that the searchparams aren't read... 😦

UPDATE:
Fixed the searchparams thing by changing the "lang" variable to "language" and added the intercepting route. Through the intercepting route change the route will be dynamically handled (also through the force-dynamic from the layout) and the intercepting layers the modal on top of the page. The id route just returns null