next-sitemap icon indicating copy to clipboard operation
next-sitemap copied to clipboard

Dynamic rendering pages are not included in sitemap (Next 13)

Open pranavks opened this issue 1 year ago • 6 comments

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

  1. Use any dynamic function like cookies() or headers() in a page. This will opt the route into dynamic rendering at request time.
  2. These pages are not included in sitemap.

Expected behavior Dynamically rendered routes should be included in sitemap.

Screenshots image These dynamically rendered pages come under λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps) in the next build's report.

pranavks avatar Dec 07 '23 14:12 pranavks

@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 avatar Dec 17 '23 16:12 Hydrock

@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.

pranavks avatar Dec 17 '23 18:12 pranavks

Is this problem related to these following section on readme

totofk avatar Dec 18 '23 02:12 totofk

@totofk No

pranavks avatar Dec 18 '23 04:12 pranavks

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

SVendittelli avatar Dec 24 '23 14:12 SVendittelli

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.

dannyDNS avatar Feb 12 '24 21:02 dannyDNS

Closing this issue due to inactivity.

github-actions[bot] avatar Apr 13 '24 04:04 github-actions[bot]