[GH-ISSUE #990] next/image: only fire onError once per image #215

Closed
opened 2026-05-06 12:38:15 +02:00 by BreizhHardware · 0 comments

Originally created by @github-actions[bot] on GitHub (Apr 30, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/990

Upstream change

Next.js fixed next/image firing onError multiple times for the same failure in vercel/next.js#93209 (commit 70d9876).

Files changed upstream

  • packages/next/src/client/image-component.tsx (+40 / -22)
  • New e2e test: test/e2e/app-dir/next-image-events/ covering the fulfilled and rejected paths and asserting onError / onLoad fire exactly once

Why this matters for vinext

vinext shims next/image. Whatever event-firing semantics our shim has should match Next.js: onLoad fires once on success, onError fires once on failure, and React strict-mode double-invocation or re-render churn must not fire either handler more than once for a single load attempt. User code commonly assumes single-fire semantics for analytics, retry, and fallback logic; firing onError twice can double-count failures or cause infinite retry loops.

Action

  • Audit shims/next-image.* (or wherever next/image is implemented) for how it tracks load/error state across re-renders
  • Port the upstream fix: ensure onError (and onLoad) fires at most once per src per mount
  • Port the upstream test cases from test/e2e/app-dir/next-image-events/ — both the fulfilled (success) and rejected (failure) paths, including invalid src, broken URL, and CSP-blocked scenarios as covered upstream
  • Add a comment in the test linking back to test/e2e/app-dir/next-image-events/next-image-events.test.ts

References

Originally created by @github-actions[bot] on GitHub (Apr 30, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/990 ## Upstream change Next.js fixed `next/image` firing `onError` multiple times for the same failure in [vercel/next.js#93209](https://github.com/vercel/next.js/pull/93209) (commit [70d9876](https://github.com/vercel/next.js/commit/70d98765fc1b6daaf3988808b7b7970d764db453)). ## Files changed upstream - `packages/next/src/client/image-component.tsx` (+40 / -22) - New e2e test: `test/e2e/app-dir/next-image-events/` covering the `fulfilled` and `rejected` paths and asserting `onError` / `onLoad` fire exactly once ## Why this matters for vinext vinext shims `next/image`. Whatever event-firing semantics our shim has should match Next.js: `onLoad` fires once on success, `onError` fires once on failure, and React strict-mode double-invocation or re-render churn must not fire either handler more than once for a single load attempt. User code commonly assumes single-fire semantics for analytics, retry, and fallback logic; firing `onError` twice can double-count failures or cause infinite retry loops. ## Action - Audit `shims/next-image.*` (or wherever `next/image` is implemented) for how it tracks load/error state across re-renders - Port the upstream fix: ensure `onError` (and `onLoad`) fires at most once per `src` per mount - Port the upstream test cases from `test/e2e/app-dir/next-image-events/` — both the `fulfilled` (success) and `rejected` (failure) paths, including invalid src, broken URL, and CSP-blocked scenarios as covered upstream - Add a comment in the test linking back to `test/e2e/app-dir/next-image-events/next-image-events.test.ts` ## References - Upstream PR: https://github.com/vercel/next.js/pull/93209 - Upstream commit: https://github.com/vercel/next.js/commit/70d98765fc1b6daaf3988808b7b7970d764db453
BreizhHardware 2026-05-06 12:38:15 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#215
No description provided.