Skip to content

fix(sitemap): don't drop lastmod for an epoch (0) timestamp#12212

Merged
slorber merged 1 commit into
facebook:mainfrom
durvesh1992:fix/sitemap-lastmod-epoch
Jul 9, 2026
Merged

fix(sitemap): don't drop lastmod for an epoch (0) timestamp#12212
slorber merged 1 commit into
facebook:mainfrom
durvesh1992:fix/sitemap-lastmod-epoch

Conversation

@durvesh1992

Copy link
Copy Markdown
Contributor

Motivation

createSitemapItem decides a route's <lastmod> from route.metadata.lastUpdatedAt (a numeric timestamp, e.g. derived from front matter last_update: {date: ...}). Two checks use truthiness on that number:

// getRouteLastUpdatedAt
if (route.metadata?.lastUpdatedAt) { ... }            // 0 is falsy → skipped
// getRouteLastmod
return lastUpdatedAt ? formatLastmod(...) : null;      // 0 → null

So a legitimate timestamp of 0 (1970-01-01T00:00:00Z) is treated as "no value" and the <lastmod> is silently omitted. The adjacent === null early-return already shows the intent to distinguish absent from present — the truthiness checks defeat that for 0.

Fix

Use != null in both places so 0 is preserved (while still treating null/undefined as absent).

Test plan

pnpm vitest run packages/docusaurus-plugin-sitemap

Added a regression test (lastUpdatedAt: 0lastmod: '1970-01-01') that fails before this change and passes after. Full sitemap package: 53 tests pass.

getRouteLastUpdatedAt/getRouteLastmod used truthiness checks on the
numeric lastUpdatedAt, so a legitimate timestamp of 0 (1970-01-01, e.g.
from front matter last_update: {date: 1970-01-01}) was treated as 'no
value' and the <lastmod> entry was silently omitted. The adjacent
=== null guard already shows the intent to distinguish absent from
present. Use != null so 0 is preserved.

Adds a regression test (fails before / passes after).
@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label Jun 29, 2026
@netlify

netlify Bot commented Jun 29, 2026

Copy link
Copy Markdown

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 15ac020
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a42f75471e7ac000835085b
😎 Deploy Preview https://deploy-preview-12212--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Jul 9, 2026
@slorber

slorber commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Hmmm, ok to merge this but really wonder what the use case for having a lastmod with epoch 0 ?

Is this only theoretical and for correctness, or do you plan to use this in practice?

@slorber slorber added the to backport This PR is planned to be backported to a stable version of Docusaurus label Jul 9, 2026
@slorber slorber merged commit be38778 into facebook:main Jul 9, 2026
38 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release. to backport This PR is planned to be backported to a stable version of Docusaurus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants