Skip to content

Comments

fix: optimized the docs images#291

Merged
MathurAditya724 merged 2 commits intomainfrom
fix/docs-image-load
Feb 24, 2026
Merged

fix: optimized the docs images#291
MathurAditya724 merged 2 commits intomainfrom
fix/docs-image-load

Conversation

@MathurAditya724
Copy link
Member

@MathurAditya724 MathurAditya724 commented Feb 24, 2026

Summary

The landing page was loading ~6.5 MB of unoptimized PNG background images. Files in public/ are served as-is by Astro, bypassing its image optimization pipeline entirely.

This PR moves the images into src/assets/ and uses Astro's getImage() API to produce optimized WebP versions at build time — 93% total size reduction with zero visual change.

Changes

  • Moved images from docs/public/docs/src/assets/ so they enter Astro's optimization pipeline
  • Created FeatureVisual.astro — wraps the feature section backgrounds using getImage() to produce WebP at build time
  • Updated Terminal.astro — same getImage() pattern for the hero bg.png
  • Updated index.mdx — uses <FeatureVisual image={...}> instead of raw inline background-image URLs

Size reduction

Image Before (PNG) After (WebP) Reduction
section-bg-1 1,591 kB 98 kB 94%
section-bg-2 1,466 kB 68 kB 95%
section-bg-3 1,382 kB 57 kB 96%
bg 2,040 kB 228 kB 89%
Total 6,479 kB 451 kB 93%

Test plan

  • Verify the landing page loads correctly at the PR preview
  • Confirm background images render identically to main
  • Check Network tab to verify WebP is served instead of PNG

@github-actions
Copy link
Contributor

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/pr-preview/pr-291/

Built to branch gh-pages at 2026-02-24 16:49 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • (brew) Handle root-owned config dir from sudo installs by BYK in #288
  • (setup) Show actual shell name instead of "unknown" for unsupported shells by BYK in #287
  • Optimized the docs images by MathurAditya724 in #291

Internal Changes 🔧

  • Only showing status about changed files in codecov by MathurAditya724 in #286

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 3639 uncovered lines.
✅ Project coverage is 75.35%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    75.35%    75.35%        —%
==========================================
  Files          115       115         —
  Lines        14760     14760         —
  Branches         0         0         —
==========================================
+ Hits         11121     11121         —
- Misses        3639      3639         —
- Partials         0         0         —

Generated by Codecov Action

Comment on lines +10 to +14
const { image, class: className } = Astro.props;

const optimized = await getImage({
src: image,
format: 'webp',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The getImage() function may not prepend the base path to image URLs, causing broken images in deployments with a non-root base path, such as PR previews.
Severity: MEDIUM

Suggested Fix

Manually prepend the base path to the URL generated by getImage(). The base path can be accessed via import.meta.env.BASE_URL. Ensure the final URL is correctly constructed before being used in the inline style.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: docs/src/components/FeatureVisual.astro#L10-L14

Potential issue: The refactoring from manual URL concatenation to using Astro's
`getImage()` function introduces a potential issue in deployments with a non-root base
path. The `getImage()` function may not automatically prepend the configured `base` path
(e.g., `/pr-preview/pr-123/`) to the `src` attribute of the optimized image. This would
result in broken image links because the browser would try to fetch them from the root
of the domain. This issue would manifest in specific environments like PR previews,
which are configured to use a sub-path, while production deployments to the root domain
would appear to work correctly.

Did we get this right? 👍 / 👎 to inform future reviews.


<div
class:list={['feature-visual', className]}
style={`background-image: url('${optimized.src}');`}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The getImage() function does not prepend the site's base path, causing background images to fail to load when the site is deployed on a subpath.
Severity: MEDIUM

Suggested Fix

Manually prepend the import.meta.env.BASE_URL to the src property of the object returned by getImage(). Ensure a trailing slash is handled correctly to construct the valid, full image path for use in the CSS url(). For example: const baseUrl = import.meta.env.BASE_URL; const base = baseUrl.endsWith('/') ? baseUrl : baseUrl + '/'; const finalSrc = base + optimized.src.replace(/^\//, '');

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: docs/src/components/FeatureVisual.astro#L21

Potential issue: The refactoring to use Astro's `getImage()` function for background
images removes the explicit handling of the site's base path. The `getImage()` function
does not automatically prepend the `base` path configured in `astro.config.mjs`.
Consequently, when the documentation site is deployed to a non-root path (e.g., for PR
previews like `/pr-preview/pr-291/`), the generated image URLs will be incorrect. The
browser will attempt to load images from the root of the domain, resulting in 404 errors
and missing background images on affected pages.

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member

@betegon betegon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks man! really appreciate it <3

@MathurAditya724 MathurAditya724 merged commit 9d95888 into main Feb 24, 2026
24 checks passed
@MathurAditya724 MathurAditya724 deleted the fix/docs-image-load branch February 24, 2026 17:01
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.

2 participants