Skip to content

fix(site): restore docs-sitemap.xml#3821

Merged
jasonbahl merged 1 commit into
mainfrom
fix/docs-sitemap
May 11, 2026
Merged

fix(site): restore docs-sitemap.xml#3821
jasonbahl merged 1 commit into
mainfrom
fix/docs-sitemap

Conversation

@jasonbahl
Copy link
Copy Markdown
Collaborator

Summary

https://www.wpgraphql.com/docs-sitemap.xml was returning 500 Internal Server Error in production. Reproduced locally and confirmed the cause: the deploy env's GITHUB_TOKEN is invalid (revoked / expired), so Octokit's call to GitHub's contents API in getAllDocMeta() returns 401 Bad credentials, the exception bubbles out of getServerSideProps, and Next renders the error page.

Fix

  1. src/lib/parse-mdx-docs.ts: only pass auth to Octokit when GITHUB_TOKEN is a non-empty trimmed string. A missing or blank token now falls back to unauthenticated GitHub requests (60 req/hr plenty for an SSR sitemap and dev-time doc fetches). Previously, a blank token was still passed and produced the same 401 a revoked token produces.

  2. src/pages/docs-sitemap.xml.ts: wrap getAllDocUri() in a try/catch. If anything in the GitHub chain still fails (rate limit, network, downstream API change), log the error and emit a valid empty instead of crashing.

Test plan

…KEN)

Production was returning 500 for /docs-sitemap.xml because the deploy
env has a revoked or invalid GITHUB_TOKEN. Octokit was sending it on
every request, GitHub replied "Bad credentials" (401), the exception
bubbled out of getServerSideProps, and Next rendered the error page.

Two layers of defense:

1. parse-mdx-docs.ts: only pass `auth` to Octokit when the token is a
   non-empty trimmed string. A missing/blank/invalid-because-empty
   token now falls back to unauthenticated GitHub requests (60 req/hr,
   plenty for a sitemap and dev-time doc fetches). Removing the env
   var entirely is now a clean way to recover from a bad token.

2. docs-sitemap.xml.ts: wrap getAllDocUri() in try/catch. If anything
   in the GitHub chain still fails at runtime (rate-limit, network,
   downstream API change), log the error and emit a valid empty
   <urlset> rather than 500.

Verified locally: with no token, the sitemap populates with 51 real
doc URIs. With an invalid token, it returns 200 with an empty but
well-formed sitemap, and the error is logged to the server.

To populate the production sitemap, either set a valid read-only PAT
on GITHUB_TOKEN in the deploy env, or unset it to use unauth requests.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 11, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
wpgraphql-com Ready Ready Preview, Comment May 11, 2026 5:29pm

@jasonbahl jasonbahl merged commit 3fb0b3d into main May 11, 2026
41 checks passed
@jasonbahl jasonbahl deleted the fix/docs-sitemap branch May 11, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant