Next.js Discord

Discord Forum

How to tell if a page is dynamic or static?

Unanswered
Golden northern bumble bee posted this in #help-forum
Open in Discord
Golden northern bumble beeOP
How can I check it? I want to be sure that getServerSideProps() was used, and not the getStaticProps()

19 Replies

wdym? you can't see the codebase?
Golden northern bumble beeOP
Hi @James4u , no, I don't see it, it's a library and can be used from different places
I need a programmatic way to detect it
not much following, those functions used in page router
what did you mean by a library?
Golden northern bumble beeOP
Just a function, which cannot see the code.
Sorry mate I don't think I am following you
Golden northern bumble beeOP
no no, not together.
Ok, let me clarify...
1) getStaticProps leaves the page static, so it won't be able to use publicRuntimeConfig for example because it cannot get updated from the server-side, right?
2) getServerSideProps() generates a dynamic page so server can inject/update any publicRuntieConfig variables.
I need to make a watchdog-function that detects static pages and SHOUTS loudly
Because today I spent 7 bloody hours to track down why my vars were not updated and to end up with finding the root page which used getStaticProps
I think the best place for this watchdog would be _app.js because you need to write it once
The best I can think about right now - is to invent an always non-empty watchdog variable to then read its value and crash if it's empty
Golden northern bumble beeOP
Hm... interesting: router.isRouter seems to always be false for static pages.
Chub mackerel
Maybe try to use this function and build the app.. it shows if the page is static or dynamic
Golden northern bumble beeOP
No, it won't work
isReady was on server only, while i need to check it on client