Skip to content

Commit 453cdba

Browse files
authored
fix(docs): sort the sitemap's entries so the route is a function of the content (#200)
Fixes #194 Two consecutive builds of an identical, untouched tree emitted different bytes for the same 346 sitemap entries. source.getPages() enumerates in file-read completion order, so docs entries moved between builds in contiguous chunks while the advertised set stayed exactly the same. deploy-docs.yml publishes on every push to main, so the served sitemap.xml changed bytes on deploys that changed no content, and anything downstream treating "bytes changed" as "content changed" was reading noise. Sorting by url before returning makes the route a pure function of the content. One statement; the builder and the staticPaths/docPaths composition are untouched and the ordering is plain lexicographic. The comparator is code-unit, not localeCompare: localeCompare depends on the runtime's ICU data and default locale, so it would move the irreproducibility from across-builds to across-machines — invisibly, since any single machine would still look perfectly stable. Verified by the card's own reproduction inverted: pre-fix builds 60a0416c vs f261b188 (differ), post-fix builds 84ec138c vs 84ec138c (byte-identical). The advertised set is unchanged — the sorted-url-blocks digest holds at a57adad5 on all four builds, the same value the card recorded. The locale-surface gate is green for the same reason as before, measured rather than asserted: its stdout is byte-identical when run against the pre-fix and post-fix artifacts.
1 parent 9a1a7ad commit 453cdba

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎apps/docs/app/sitemap.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,15 @@ export default function sitemap(): MetadataRoute.Sitemap {
5252
}
5353
}
5454

55-
return entries;
55+
// Sort by url so the route is a function of the content rather than of the
56+
// build. `source.getPages()` enumerates in file-read completion order, which
57+
// varies between builds of an identical tree: two consecutive builds of an
58+
// untouched tree emitted different bytes for the same 346 entries, so every
59+
// `deploy-docs.yml` push rewrote the served sitemap whether or not any
60+
// content changed. Entry order carries no meaning to a crawler; the point is
61+
// that the bytes stop carrying noise. Compared by code unit rather than with
62+
// `localeCompare`, whose result depends on the runtime's ICU data and default
63+
// locale — a machine-dependent comparator would reintroduce exactly the
64+
// irreproducibility this removes.
65+
return entries.sort((a, b) => (a.url < b.url ? -1 : a.url > b.url ? 1 : 0));
5666
}

0 commit comments

Comments
 (0)