Skip to content

Sitemap index route passes empty string instead of undefined, breaking sitemap-index.xml loading #442

@RobertoArmas

Description

@RobertoArmas

Describe the Bug

When loading sitemap-index.xml, the sitemap index does not load correctly because the route handler falls back to an empty string ('') for the sitemap ID, while the downstream sitemap service expects id === undefined.

In packages/nextjs/src/route-handler/sitemap-route-handler.ts, the current fallback is :

const id = req.nextUrl.pathname.match(/^/sitemap-(\d+).xml$/i)?.[1] || '';

However, in packages/content/src/site/sitemap-xml-service.ts around line 96, the logic expects id to be undefined, not an empty string. Because of that, the sitemap index scenario is not handled correctly, and sitemap-index.xml does not load as expected.

To Reproduce

Request sitemap-index.xml
The request goes through sitemap-route-handler.ts
The handler derives id from the pathname
Since the pathname does not match /sitemap-{number}.xml, id falls back to ''
The sitemap service receives '' instead of undefined
The sitemap index logic is skipped or handled incorrectly

Expected Behavior

sitemap-index.xml does load properly.

Possible Fix

Do not fall back to an empty string. Let id remain undefined when the pathname does not match a numbered sitemap route.

For example:

const id = req.nextUrl.pathname.match(/^/sitemap-(\d+).xml$/i)?.[1];

Notes
This mismatch between route handler behavior and sitemap service expectations causes the sitemap index scenario to never occur correctly.

Provide environment information

  • Sitecore Version: Sitecore AI
  • Content SDK Version: 2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions