aboutsummaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-10 07:15:12 -0700
committerAdam Soltys <[email protected]>2026-10-10 07:15:12 -0700
commitf76191c9296b1d5110d0360dfb106e9276cdc859 (patch)
tree4b181174592f1496db62eed02542ac61c7e8c69b /src/features
parent572361e2bd1ab16b4618517c2d9531689c6f46a8 (diff)
downloadcoinosv3-f76191c9296b1d5110d0360dfb106e9276cdc859.tar.gz
coinosv3-f76191c9296b1d5110d0360dfb106e9276cdc859.zip
Feed: a slow picture keeps loading in place instead of turning into a link. A feed row waits up to 8 s for its pictures, then freezes as it is; a picture still downloading at that moment (Juraj's 3.5 MB PNG from blossom.primal.net, on a phone) was frozen as its bare URL, and only showed when the post was opened. Now a picture that was merely slow is drawn in a fixed 4:3 box (fitted inside, so nothing moves when it lands) and keeps loading; only a picture that refused to load (an error, not a timeout — mediaFailed) is still a link. tools/slow-image-test.js (a picture served after 11 s; on the old code it was a link).
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vps2H27rhbG9ZqseGfMrc3
Diffstat (limited to 'src/features')
-rw-r--r--src/features/messages.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 4512818..358bd2e 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -6073,6 +6073,7 @@ export function messagesFeature(ctx) {
// a late response is useful on the next visit, not a mid-read replacement.
const READY_MS = 8000;
const mediaReady = new Map(); // URL -> decoded dimensions
+ const mediaFailed = new Set(); // URLs whose picture refused to load (not merely slow)
const mediaWarming = new Map();
// A post's photo is often the camera's original — 3024px wide, twelve
// megapixels — painted into a column a sixth of that. Chrome decodes it
@@ -6160,11 +6161,11 @@ export function messagesFeature(ctx) {
const done = (ok) => {
clearTimeout(timer);
img.onload = img.onerror = null;
- if (ok) mediaReady.set(url, { width: img.naturalWidth, height: img.naturalHeight });
+ if (ok) { mediaReady.set(url, { width: img.naturalWidth, height: img.naturalHeight }); mediaFailed.delete(url); }
resolve();
};
img.onload = () => { (img.decode ? img.decode() : Promise.resolve()).then(() => done(true), () => done(false)); };
- img.onerror = () => done(false);
+ img.onerror = () => { mediaFailed.add(url); done(false); };
img.src = url;
}).finally(() => { if (mediaWarming.get(url) === task) mediaWarming.delete(url); });
task.plain = true;
@@ -7726,7 +7727,17 @@ export function messagesFeature(ctx) {
if (AUDIO_RE.test(url)) return audioNode(url, label);
if (isImage || /\.(png|jpe?g|gif|webp|avif)(\?[^\s]*)?$/i.test(url)) {
const size = feedPaint ? feedMedia(url) : null;
- if (feedPaint && !size) return h('a', { href: url, target: '_blank', rel: 'noopener noreferrer' }, label || url);
+ if (feedPaint && !size) {
+ // a picture that refused to load is a link; one that was merely
+ // slow (a 3.5 MB PNG on a phone outran the row's deadline) keeps
+ // loading inside a box of fixed shape, so nothing moves when it lands
+ if (mediaFailed.has(url)) return h('a', { href: url, target: '_blank', rel: 'noopener noreferrer' }, label || url);
+ return h('img', {
+ src: url, class: 'note-img note-img-late clickable', loading: 'lazy', decoding: 'async', alt: label || '',
+ onClick: (e) => { if (!onPicture(e)) return; e.stopPropagation(); ctx.openImage && ctx.openImage(url); },
+ onError: (e) => { e.target.style.display = 'none'; },
+ });
+ }
// tap it to see it full size (the feed shows it uncropped, but
// height-capped: see .note-img)
const known = size || mediaReady.get(url);