Enable automatic zooming images#4776
Draft
Duncanma wants to merge 4 commits into
Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📖 Docs PR preview links
|
…ge in <NoZoom></NoZoom>
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.
Zoomable images (Stripe-style click-to-expand)
Summary
Large images in the docs are now click-to-expand, matching the behavior on
Stripe's docs:
zoom-incursor and clicking opens a full-width modal of the image at full resolution.zoom-out; clicking the image, clicking the backdrop, pressingEscape, or the×button closes it and restores the page.The effect is automatic for every image in the docs. Authors do not need to do anything; whether an image is zoomable is decided at runtime by comparing the image's natural pixel width to the width it is actually displayed at.
Opting out:
<NoZoom>Some images are decorative (e.g. the SDK banners on the
/developlanding pages) and should never expand, even though they are downscaled. Wrap them in<NoZoom>to disable the click-to-expand affordance:<NoZoom>is registered globally (src/theme/MDXComponents.tsx), so no import is needed in.mdxfiles. It is also exported fromsrc/componentsfor explicit use.ZoomableImagereads (useNoZoom()); when set, the overflow check never marks the image zoomable, so there is no zoom cursor and no modal.All SDK banners under
docs/develop/**are wrapped in<NoZoom>.What changed
src/components/images/ZoomableImage.tsx(new)src/components/images/ZoomableImage.module.css(new)height: autostyles.src/theme/MDXComponents.tsximgrenderer, so every Markdown image () flows throughZoomableImage; also registers<NoZoom>globally for opt-out.src/components/images/CaptionedImage.jsZoomableImagewhile keeping captions and dark/light support.src/components/images/ZoomingImage.js,EnlargeImage.jssrc/components/images/NoZoom.tsx(new)src/components/index.jsZoomableImageandNoZoom.How overflow is detected
On image load and whenever the column is resized (via a
ResizeObserver), the component comparesimg.naturalWidthto the renderedimg.clientWidth. The image is treated as zoomable only when it is being downscaled (naturalWidth > clientWidth). This is why the same image can be zoomable on a narrow laptop column (~630px) but not on a wide monitor (~1300px), and why high-resolution ("2x") screenshots — the bulk of our images — are zoomable.Aspect-ratio fix (important)
Docusaurus adds intrinsic
widthandheightattributes to Markdown images (to prevent layout shift). The stock theme image applies a class that forcesheight: auto, so the height scales with the width undermax-width: 100%.ZoomableImagenow applies the sameheight: autorule (.imagein its CSS module). Without it, images were rendered at their fitted width but full intrinsic height — visibly squished. If you ever see distorted images, this class is the first thing to check.Benefits
EnlargeImage(opened a raw image in a new tab),ZoomingImage, andCaptionedImage zoom="true"(inline toggles) now share one modal.role="dialog",aria-modal,Escapeto close, focusable close button, and body-scroll lock while open.Note: dark/light images now load on demand (performance trade-off)
CaptionedImagesupports asrcDarkvariant. The behavior changed:<img>were rendered into the DOM and swapped with CSS (visibility). Both files were downloaded up front, so toggling the site theme was instant.useColorMode, so only the current theme's image is downloaded.Trade-off: initial page load fetches one image instead of two (faster, less bandwidth). But if a reader switches the site theme while the page is open, the other variant has not been downloaded yet, so it is fetched on the spot — the swapped image may flash or appear blank for a moment on slow connections or for large files. The fetch is cached after the first switch. This only affects images that actually declare a
srcDark; plain Markdown images have a single source and are unaffected.How to test
yarn startand open a page with large images, e.g./cloud/billingor/develop/go/client/temporal-client.zoom-in. Click → full-width modal opens. Click the image / backdrop /×, or pressEscape→ it closes and the page scroll is restored./codec-server, toggle the navbar theme switch, and confirm the diagrams swap to their dark/light variants and the captions still render. Note the on-demand fetch described above on first toggle.Pages affected
Pages that previously had explicit zoom — now use the shared modal
These already offered some form of "enlarge". Their interaction is now the unified click-to-expand modal.
Newly zoomable pages (44)
Pages that did not previously have any zoom but contain raster images ≥ 800px wide, which now expand when downscaled. Grouped by area; the width shown is the page's largest image.
Best practices
Temporal Cloud
Develop
Develop — dotnet
Develop — go
Develop — java
Develop — python
Develop — ruby
Develop — typescript
Encyclopedia
Evaluate
Production deployment
The page lists above cover raster images (PNG/JPG/etc.), which are the large screenshots that motivated this change. SVG diagrams are vector and stay crisp at any size; they only trigger the zoom affordance if they declare an intrinsic width larger than the column, and expanding them adds little.