Commit ba53daa
fix(md-exports): Stabilize cache keys by stripping build-specific elements (#16079)
## 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 with `href` attribute (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
- Add `stripUnstableElements()` function that uses regex to remove
build-specific elements
- Use stripped HTML for both cache key calculation AND unified pipeline
processing (faster parsing)
- Bump `CACHE_VERSION` to invalidate old cache entries
The regex approach is safe since:
- Input is trusted (Next.js build output, not user input)
- Worst case for any regex edge cases is a cache miss (current behavior
anyway)
- Stripped content is irrelevant for markdown generation (we only use
title, canonical link, and main content)
Co-authored-by: Claude <noreply@anthropic.com>1 parent 9f98b14 commit ba53daa
1 file changed
Lines changed: 39 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
410 | 440 | | |
411 | 441 | | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
416 | 446 | | |
417 | 447 | | |
418 | 448 | | |
| |||
437 | 467 | | |
438 | 468 | | |
439 | 469 | | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
446 | 473 | | |
447 | 474 | | |
448 | 475 | | |
| |||
500 | 527 | | |
501 | 528 | | |
502 | 529 | | |
503 | | - | |
| 530 | + | |
504 | 531 | | |
505 | 532 | | |
506 | 533 | | |
| |||
0 commit comments