Files
supabase/apps/docs/components/Image.tsx
Danny White 0e5c073b46 fix(docs): unblock prerender by closing Image JSX without blank lines (#48465)
## What kind of change does this PR introduce?

Bug fix

## What is the current behavior?

Docs production builds can fail during prerender with:

`TypeError: Cannot read properties of undefined (reading 'children')`

Seen on `/guides/ai/going-to-prod` (and the same pattern exists on
several other guides).

Root cause: blank lines inside MDX JSX such as `<Image ...>` make the
MDX parser treat the element as closed early, which corrupts the AST.
Separately, `apps/docs/components/Image.tsx` forwarded accidental
`children` (and could overwrite `src`) onto `next/image`.

## What is the new behavior?

- Remove blank lines before the closing `/>` on the affected guide MDX
files so the JSX stays one element.
- Make the docs `Image` wrapper drop `children` and keep `src` from
props only, so a bad MDX tree is less likely to crash the build.

## Additional context

Split out of #48428 so that PR stays focused on Admonition/Alert
typography.

### To test

1. Check out this branch and run the docs app locally (`apps/docs`), or
wait for the Vercel docs preview on this PR.
2. Confirm these pages render without a prerender / `children` crash:
-
[/docs/guides/ai/going-to-prod](https://docs-git-fix-docs-image-mdx-blank-lines-supabase.vercel.app/docs/guides/ai/going-to-prod)
-
[/docs/guides/ai/engineering-for-scale](https://docs-git-fix-docs-image-mdx-blank-lines-supabase.vercel.app/docs/guides/ai/engineering-for-scale)
-
[/docs/guides/ai/choosing-compute-addon](https://docs-git-fix-docs-image-mdx-blank-lines-supabase.vercel.app/docs/guides/ai/choosing-compute-addon)
-
[/docs/guides/ai/vector-indexes/hnsw-indexes](https://docs-git-fix-docs-image-mdx-blank-lines-supabase.vercel.app/docs/guides/ai/vector-indexes/hnsw-indexes)
-
[/docs/guides/database/orioledb](https://docs-git-fix-docs-image-mdx-blank-lines-supabase.vercel.app/docs/guides/database/orioledb)
-
[/docs/guides/database/connecting-to-postgres](https://docs-git-fix-docs-image-mdx-blank-lines-supabase.vercel.app/docs/guides/database/connecting-to-postgres)
-
[/docs/guides/telemetry/reports](https://docs-git-fix-docs-image-mdx-blank-lines-supabase.vercel.app/docs/guides/telemetry/reports)
3. Spot-check that the guide images still show at the expected size (no
broken/missing images from the `Image` wrapper change).
4. Confirm Docs CI / Vercel docs build passes on this PR (this was the
failure mode on master-ish builds).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added zoomable behavior to the Disk Size chart, with optimized light
and dark theme images.

* **Bug Fixes**
* Improved image rendering in documentation pages by handling captions,
styling, and MDX content more reliably.
* Corrected image markup formatting across multiple guides to ensure
content parses and displays correctly.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-31 10:27:07 +10:00

76 lines
1.8 KiB
TypeScript

'use client'
import { useTheme } from 'next-themes'
import NextImage, { ImageProps as NextImageProps } from 'next/image'
interface StaticImageData {
src: string
height: number
width: number
blurDataURL?: string
blurWidth?: number
blurHeight?: number
}
interface StaticRequire {
default: StaticImageData
}
type StaticImport = StaticRequire | StaticImageData
type SourceType =
| string
| {
dark: string | StaticImport
light: string | StaticImport
}
export interface ImageProps extends Omit<NextImageProps, 'src'> {
src: SourceType
caption?: string
containerClassName?: string
}
/**
*
* This is a shrunk version of the `ui` package Image component. Because of
* Cumulative Layout Shift caused by problems stated in this PR
* https://github.com/supabase/supabase/pull/43026/ that's affecting hash
* navigation, and the need to support captions and light/dark image versions.
*
* Ideally we should solve these issues in that component and re-use it again,
* making sure it doesn't affect other projects consuming the component.
*
*/
const Image = ({
src,
alt = '',
className,
style,
containerClassName,
caption,
// MDX can pass whitespace-only children (e.g. a blank line before `/>`);
// never forward those to next/image.
children: _children,
...rest
}: ImageProps) => {
const { resolvedTheme } = useTheme()
const source =
typeof src === 'string' ? src : resolvedTheme?.includes('dark') ? src.dark : src.light
return (
<figure className={containerClassName}>
<NextImage
key={resolvedTheme}
alt={alt}
src={source}
className={className}
style={style}
{...rest}
/>
{caption && <figcaption className="text-center">{caption}</figcaption>}
</figure>
)
}
export default Image