Why is the /app/not-found.tsx page processing for every request to an app router page?
Unanswered
Little yellow ant posted this in #help-forum
Little yellow antOP
The page loads just fine but if you put console logs into that file you can see it is at least processed and I am baffled as to why.
12 Replies
Brown bear
Could you share your app folder structure and what routes this is occuring on? That could help
Brown bear
Huh... I just tried it myself and I see what you mean
Little yellow antOP
Thank you for trying it! I can't think of a good reason for it to be doing that. I would love it if someone explained it because it just seems like a waste of processing power to me.
@Little yellow ant Thank you for trying it! I can't think of a good reason for it to be doing that. I would love it if someone explained it because it just seems like a waste of processing power to me.
Maybe its to preload things just in case if you call notFound()
@Little yellow ant The page loads just fine but if you put console logs into that file you can see it is at least processed and I am baffled as to why.
Dwarf Hotot
It is because not found run to check that the page exists or not then redirection run which is checked by next.config.js then the page and other things run.
Not found run before the page in precautions to check that the page exists or not
Not found run before the page in precautions to check that the page exists or not
Little yellow antOP
Checking for the page to exist is one thing. Processing it is another. Besides, why would the not found page matter if the actual page / route exists?
Still seems like a step that doesn't need to be there and is a waste of processing power. Which really starts to matter on hosting providers that charge for cpu usage.
Even if it is checking if it exists, this could done during startup. There has to be something I'm missing about this.
Little yellow antOP
Will do!
Brown bear
Yeah, I tried digging into this but could not figure out exactly what's going on inside nextjs that causes this. Who know that nextjs internals would be comlicated 😜
@Little yellow ant Even if it is checking if it exists, this could done during startup. There has to be something I'm missing about this.
Dwarf Hotot
I thought this is the correct explanation, but if you find anything just ping me 😁