feat: image error placeholder + scroll-to-top on navigation

Image bubbles previously used the raw filename as alt text, so a failed
asset load exposed the file name in the broken-image box. Add a reusable
BubbleImage that renders an empty alt and falls back to a neutral
placeholder (ImageOff icon) on error; use it in the album, image, and
image-with-text bubbles, and drop the filename from their aria-labels.

Also add a global ScrollToTop that resets the window on route change so
desktop navigation matches mobile (e.g. clicking a category card no
longer lands at the bottom of the new page). Hash navigations are skipped
so #post-<id> deep-link scrolling still works.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
TerryM
2026-05-29 13:09:09 +08:00
parent 4464e6fdc5
commit 559c4f19c8
6 changed files with 80 additions and 11 deletions

View File

@@ -0,0 +1,46 @@
import { ImageOff } from "lucide-react";
import { useEffect, useState } from "react";
type BubbleImageProps = {
src: string | undefined;
className?: string;
loading?: "lazy" | "eager";
};
/**
* Thumbnail <img> for message bubbles. Renders with an empty alt (decorative)
* and, if the asset fails to load, falls back to a neutral placeholder instead
* of the browser's broken-image box — which would otherwise expose the raw
* file name via alt text.
*/
export function BubbleImage({ src, className, loading }: BubbleImageProps) {
const [failed, setFailed] = useState(false);
// Reset when the source changes so a reused element re-attempts the new src.
useEffect(() => {
setFailed(false);
}, [src]);
if (!src || failed) {
return (
<div
className={`flex items-center justify-center bg-gradient-to-br from-neutral-800 to-neutral-900 ${
className ?? ""
}`}
aria-hidden
>
<ImageOff className="h-8 w-8 text-neutral-600" />
</div>
);
}
return (
<img
src={src}
alt=""
loading={loading}
className={className}
onError={() => setFailed(true)}
/>
);
}