Repository navigation
Studio: mascot images degrade gracefully instead of showing alt text - #6146
Conversation
Mascots loaded from raw public-folder URLs with no error handling, so a missing or unreachable file (version skew during updates, subpath mounts, transient blips) painted the alt text, like the empty mascot on the training start overlay. A shared MascotImg now resolves against BASE_URL, retries once with a cache-buster, then swaps to a 4 KB fallback sloth bundled as a data URI that cannot 404. Applied to the chat greeting, 404 page, training start overlay, auth form, onboarding splash and wizard.
There was a problem hiding this comment.
Code Review
This pull request introduces a new MascotImg component to replace standard img tags for mascot images across the application. This component handles asset resolution against the deploy base and implements a graceful degradation strategy, retrying failed loads with a cache-buster before falling back to a bundled inline mascot. Feedback suggests refactoring MascotImg to leverage React's key prop behavior to reset state automatically when the src changes, rather than manually tracking state during render.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| export function MascotImg({ | ||
| src, | ||
| alt = "", | ||
| ...rest | ||
| }: { src: string } & Omit<ComponentProps<"img">, "src" | "onError">) { | ||
| const [stage, setStage] = useState<Stage>("primary"); | ||
| // Reset during render when the source changes (greeting sloths rotate). | ||
| const [lastSrc, setLastSrc] = useState(src); | ||
| if (src !== lastSrc) { | ||
| setLastSrc(src); | ||
| setStage("primary"); | ||
| } | ||
|
|
||
| const url = publicAssetUrl(src); | ||
| const effectiveSrc = | ||
| stage === "primary" | ||
| ? url | ||
| : stage === "retry" | ||
| ? `${url}${url.includes("?") ? "&" : "?"}retry=1` | ||
| : fallbackMascot; | ||
|
|
||
| return ( | ||
| <img | ||
| draggable={false} | ||
| {...rest} | ||
| src={effectiveSrc} | ||
| alt={alt} | ||
| onError={() => setStage((s) => (s === "primary" ? "retry" : "fallback"))} | ||
| /> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Instead of manually tracking lastSrc in state and performing a state update during render (which can be harder to reason about and is less idiomatic), we can leverage React's built-in key prop behavior. By splitting MascotImg into a lightweight wrapper and an inner component, and passing key={src} to the inner component, React will automatically reset the inner component's state (including stage) whenever src changes.
type MascotImgProps = { src: string } & Omit<ComponentProps<"img">, "src" | "onError">;
export function MascotImg({ src, ...props }: MascotImgProps) {
return <MascotImgInner key={src} src={src} {...props} />;
}
function MascotImgInner({
src,
alt = "",
...rest
}: MascotImgProps) {
const [stage, setStage] = useState<Stage>("primary");
const url = publicAssetUrl(src);
const effectiveSrc =
stage === "primary"
? url
: stage === "retry"
? `${url}${url.includes("?") ? "&" : "?"}retry=1`
: fallbackMascot;
return (
<img
draggable={false}
{...rest}
src={effectiveSrc}
alt={alt}
onError={() => setStage((s) => (s === "primary" ? "retry" : "fallback"))}
/>
);
}
There was a problem hiding this comment.
Good suggestion, switched to the key remount so React resets the retry state per source and the manual previous-src tracking is gone. Re-verified with the blocked-asset test: normal loads come from the public folder and forced 404s still end on the bundled fallback.
|
pre-commit.ci run |
# Conflicts: # studio/frontend/src/features/studio/training-start-overlay.tsx
What this does
Some users hit an empty mascot with raw alt text on the training start screen (and potentially anywhere a sloth renders). Mascots were plain
<img>tags pointing at public-folder URLs with no error handling, so any failed load painted the alt text and stayed that way.Why the image can fail
unsloth studio updateswaps the frontend on disk, or a customfrontend_pathmissing public assets: the file 404s./...paths break when Studio is mounted behind a subpath; some call sites already prefixedBASE_URL, others did not.<img>never retries.Fix
A shared
MascotImgcomponent used by every mascot call site (chat greeting, 404 page, training start overlay, auth form, onboarding splash, onboarding wizard, artifact generating panel):import.meta.env.BASE_URLand URI-encodes the spaced sloth filenames, one code path for all call sites.Testing
tsc -bandvite buildpass; biome and eslint clean on the new files apart from the codebase-standard react-refresh warning for the exported helper.