fix(ui): fall back when token/chain logo image fails to load#1049
fix(ui): fall back when token/chain logo image fails to load#10490xkeccak wants to merge 3 commits into
Conversation
ChainTokenIcon only guarded against the literal 'missing.png' URL, so a token logo that 404s or is blocked by CORS rendered a broken-image icon even though a symbol-letter fallback already exists. ChainIcon had the same gap for chain logos. Track an image load error per component via onError and fall back to the token symbol avatar (ChainTokenIcon) or render nothing (ChainIcon).
|
@0xkeccak is attempting to deploy a commit to the Uneven Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
I think the only additional thing is to make sure it resets when the icon url changes right? Did you test that scenario? |
Track the errored src instead of a boolean flag, so when the component re-renders with a different tokenlogoURI/chain icon URL the fallback clears and the new logo is attempted. Prevents a previously-broken URL from suppressing a valid new one on the same component instance.
|
Good catch. Switched from a boolean flag to tracking the errored On testing: I didn't find a component test setup in |
One last request that was flagged from the AI code review:ChainIcon returning null breaks row alignment in lists (the one change I'd request) ChainIcon is used in list rows like ChainFilterRow.tsx:115 (<ChainIcon ... width={24} height={24} /> followed by the chain name) and in ChainShortcuts, ChainFilterSidebar, etc. On error the component now renders nothing, so that one row's label shifts left relative to its siblings — a new misalignment the old broken-image at least didn't cause (it still occupied the 24px box). Minimal fix: keep the outer sized div and hide only the |
Problem
In the swap/bridge UI,
ChainTokenIconandChainIconrender a raw<img>with no error handling. They only guard against the literalmissing.pngURL, so a token or chain logo whose URL looks valid but fails to load at runtime (404, dead CDN, or CORS-blocked) renders the browser's broken-image placeholder.ChainTokenIconalready has a perfectly good fallback right below the image — the token-symbol letter avatar — but it never triggers on a load failure, only when the URL is absent or equalsmissing.png.Fix
Track an image load error per component via
onError:ChainTokenIcon— on image error, fall back to the existing token-symbol avatar instead of a broken image.ChainIcon— on image error, render nothing instead of a broken-image box.Minimal change, no API surface change.
Testing
pnpm --filter @relayprotocol/relay-kit-ui typecheck✅pnpm --filter @relayprotocol/relay-kit-ui lint✅pnpm run build:ui✅@relayprotocol/relay-kit-uipatch).