perf: cap markdown image transform width + eager-load blog hero images#1023
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
tanstack-com | a11730e | Commit Preview URL Branch Preview URL |
Jul 02 2026, 06:04 PM |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds ChangesEager First Image Loading
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Two small, independent perf fixes for markdown-rendered images:
Cap the Cloudflare Images transform width for markdown images without explicit dimensions.
MarkdownImgpreviously passedwidth=undefinedstraight through to the image transform URL when a markdown image had no explicit width and no inferrable dimension, letting Cloudflare serve an unbounded/full-resolution transform. Now falls back toDEFAULT_TRANSFORM_WIDTH = 1200in that case only. Cloudflare Images' defaultfit=scale-downnever upscales, so this only shrinks the upper bound — it cannot make any image blurrier or larger than before.Eager-load the first image in blog posts instead of lazy-loading it. Blog post hero images were marked
loading="lazy"like every other markdown image, so the browser deprioritized fetching the LCP candidate on every blog page. Added an opt-ineagerFirstImageprop (wired only fromblog.$.tsx, not any docs route) that walks the parsed markdown AST once, finds the first image reachable through plain paragraphs/headings, and renders just that one image withloading="eager"/fetchPriority="high".Why this design
useMemo— no mutable ref, no per-render side effects. An earlier ref-based version was caught by a critic review as having a concurrency bug (stale ref reads across StrictMode/concurrent re-renders could silently promote the wrong image); this version can't have that bug class because there's no mutable shared state.src/blog/*.md: every post with a body image reaches it through plain paragraphs only, so this is safe today. A new test (tests/blog-hero-image.test.ts) asserts this invariant going forward — if a future post's structure breaks the walker, the test fails loudly instead of the optimization silently degrading to lazy-loading.findFirstImageSrclives insrc/utils/markdown/(notMarkdown.tsx) so it's a pure function importable by the plain Node test runner without pulling in React/JSX/asset imports.Known limitation (documented, not fixed)
If a single document used the exact same image
srctwice, both occurrences would be marked eager (value-based comparison, not position-based). Checked all 56 current blog posts — zero duplicatesrcvalues exist today. Not fixing proactively since it can't happen with current content and the markdown renderer's component API doesn't expose per-node identity to make a position-based fix straightforward.Summary by CodeRabbit