fix(md-exports): Stabilize cache keys by stripping build-specific elements#16079
Merged
fix(md-exports): Stabilize cache keys by stripping build-specific elements#16079
Conversation
…ments Next.js build output contains non-deterministic elements (scripts, CSS/font links, style tags) that change between builds even when content is unchanged. This caused cache misses on every build. Changes: - Add stripUnstableElements() to remove scripts, /_next/ links, and style tags - Use stripped HTML for both cache key calculation AND parsing (faster) - Bump CACHE_VERSION to 4 to invalidate old cache entries The regex approach is safe since input is trusted Next.js build output, and worst case for any edge cases is a cache miss (current behavior anyway). Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
sergical
approved these changes
Jan 20, 2026
Member
sergical
left a comment
There was a problem hiding this comment.
gonna approve to be non-blocking. couple of comments:
- would love to see a subsequent build with a change that verifies its working
- you brought up a good point about adding metrics and potentially having some alerts setup if the cache percentage starts degrading but i am not sure we have access to our SDK at build time
thanks for taking this on!
This was referenced Jan 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes unstable cache keys in the markdown export script that caused cache misses on every build.
Problem
Next.js build output contains non-deterministic elements that change between builds even when content is unchanged:
<script>tags with RSC/Flight payloads and JS chunk references<link>tags referencing/_next/static/(CSS, fonts, JS preloads with content hashes)<style>tags withhrefattribute (inlined CSS with build hashes)The previous approach hashed the raw HTML for cache keys, causing instability. An earlier fix stripped scripts via regex but was removed due to CodeQL warnings.
Solution
stripUnstableElements()function that uses regex to remove build-specific elementsCACHE_VERSIONto invalidate old cache entriesThe regex approach is safe since: