next-sitemap
next-sitemap copied to clipboard
Dynamic rendering pages are not included in sitemap (Next 13)
Describe the bug Routes which are dynamically rendered (server side rendered) due to the use of Nextjs's Dynamic Functions are not included in sitemap.
Version : Next 13.5.1
To Reproduce
- Use any dynamic function like cookies() or headers() in a page. This will opt the route into dynamic rendering at request time.
- These pages are not included in sitemap.
Expected behavior Dynamically rendered routes should be included in sitemap.
Screenshots
These dynamically rendered pages come under
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
in the next build
's report.
@pranavks may watch this https://youtu.be/FukseskiIkE?si=8pJrBw0tZTxJAykW&t=1485
I think it's logical that dynamic routes are not generated in the sitemap, because the plugin simply does not know the id of existing records at the stage. Otherwise, at the assembly stage, planin would have to go to the database for data. In any case, you would have to configure everything manually. I think the video above shows a great example of how to do it correctly and without additional plugins.
It seems that if you use getStaticPaths (https://snappify.com/blog/how-to-generate-a-sitemap-for-your-nextjs-application#dynamic-routes) you can generate the sitemap correctly
But it still doesn't solve the problem. If you have a dynamic site, the content on your site is constantly being generated, and you do not plan to rebuild the project, then the sitemap will remain unchanged - this is not what we expect
The sitemap must be dynamic
@Hydrock The issue is not with "Dynamic routes" which we create using square brackets in folder name.
This is regarding "Routes which are dynamically rendered at request time" (Server side rendered routes) because of the use of Next 13's "Dynamic Functions". These can be either static or dynamic routes.
And the list of server side rendered routes are available in the next build
command's report in command line (where we can see all the list of urls which are generated using generateStaticParams
). So next-sitemap should be able to get these urls and add them to sitemap.
Is this problem related to these following section on readme
@totofk No
I am also running into this issue, static vs dynamic rendering of server components is covered in these Next.js docs:
- https://nextjs.org/learn/dashboard-app/static-and-dynamic-rendering
- https://nextjs.org/docs/app/building-your-application/rendering/server-components#dynamic-rendering
Same here.
We're using dynamic rendering to enable different features based on authentication status, but these are public pages that we'd like to have in the sitemap.
Closing this issue due to inactivity.