Skip to content

Cap default image intrinsic width to ~900px in remark-image-processing #17367

@sentry-junior

Description

@sentry-junior

Summary

Doc images default to rendering at their native pixel dimensions (e.g. 2942px wide), relying on CSS width: 100%; height: auto to scale them down for display. While this works visually on narrow viewports, next/image still generates srcset entries at the native intrinsic size, so oversized images get fetched unnecessarily. There is no enforced display cap globally.

Current behavior

  • remark-image-processing.js reads native image dimensions and encodes them as #WIDTHxHEIGHT URL fragments (e.g. img.png#2942x1360)
  • DocImage passes those dimensions directly to next/image as width and height
  • Images render at CSS 100% width, but next/image uses the intrinsic dimensions for srcset generation — so a 2942px image produces a 2942px srcset entry
  • A manual inline override exists (![alt =800x](./img/foo.png)) but is opt-in per image, meaning most images have no cap

Gap

  • Display looks fine at a glance, but next/image optimization is based on intrinsic size, not rendered size
  • No global max-width cap means large images bloat network payloads
  • A reasonable default of ~900px intrinsic width would cover the full docs content column width without unnecessary overhead
  • 242 images are currently >200KB (29 are >500KB), many of which encode intrinsic widths well above any realistic display width

Options

  1. Cap intrinsic width in remark-image-processing.js — when computed width exceeds a threshold (e.g. 900px), clamp it and scale height proportionally before writing the #WIDTHxHEIGHT fragment. This is the cleanest fix and affects all images automatically.
  2. Apply a CSS max-width to DocImage — prevents display overflow without changing srcset generation. Simpler but doesn't fix the next/image optimization gap.
  3. Both — cap intrinsic dimensions in the remark plugin AND add a CSS max-width as a safety net.

Option 1 or 3 is preferred. A max-width of 900px was suggested as the default.

Action taken on behalf of Evan Purkhiser.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions