Commit d61e0aa
fix: Block MDX compilation at Vercel runtime to protect release registry (#15953)
## Summary
This PR blocks MDX compilation from running at Vercel runtime, which was
causing:
1. **Registry overload**: Every runtime MDX compilation fetches from
`release-registry.services.sentry.io`, causing traffic spikes that
crashed the registry
2. **esbuild errors**: Runtime compilation fails with "read-only file
system" errors (DOCS-915, 4.9M+ events)
## Root Cause Analysis
When users hit URLs that don't exist (404s) or certain edge cases in
Next.js routing, the page component tries to render before falling back
to not-found. This triggers:
1. `getFileBySlugWithCache()` is called for a non-existent path
2. Cache check is skipped (only runs when `CI` env var is set)
3. MDX compilation is attempted via `bundleMDX()`
4. `remarkVariables` plugin fetches from release registry
5. esbuild tries to write to `/var/task/public/mdx-images` (read-only on
Lambda)
6. Error is thrown, registry has been hammered
## The Fix
Add a guard at the start of `getFileBySlug()` that throws immediately if
we're at Vercel runtime:
```typescript
const isVercelRuntime = process.env.VERCEL && !process.env.CI && process.env.NODE_ENV !== 'development';
if (isVercelRuntime) {
throw new Error(`[MDX Runtime Error] Attempted to compile MDX at Vercel runtime for slug "${slug}"...`);
}
```
## Why This Is Safe
- All 9229 docs pages are statically generated during CI builds
(`force-static` + `generateStaticParams`)
- MDX compilation at runtime was **never intended** to work - the build
dependencies are excluded from the Lambda bundle
- This just makes the failure explicit and fast, protecting the registry
- Local development and CI builds are unaffected
## Fixes
- DOCS-915 (4.9M events)
- DOCS-9H5, DOCS-9N0, DOCS-9HB (related ENOENT errors)
---------
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>1 parent 623aaa9 commit d61e0aa
2 files changed
Lines changed: 58 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
177 | 193 | | |
178 | 194 | | |
179 | 195 | | |
| |||
269 | 285 | | |
270 | 286 | | |
271 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
272 | 304 | | |
273 | 305 | | |
274 | 306 | | |
| |||
487 | 519 | | |
488 | 520 | | |
489 | 521 | | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
490 | 546 | | |
491 | 547 | | |
492 | 548 | | |
| |||
0 commit comments