AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Next/Image Crashes Production SSR: DeviceSizes.Sort() Mutates Frozen Config Arrays

In Next.js 16 production SSR, next/image's internal useMemo calls .sort() directly on config.deviceSizes and config.qualities. The config object is deeply frozen by the got library, causing TypeError: Cannot assign to read only property '0'. This crashes server rendering for any page using next/image.

highConfidence 92%NextAffected V16.2.6

Origin Analysis

Next.js image-component.js mutates config arrays in place via c.deviceSizes.sort() and c.qualities?.sort(). In production, next.config.js is deep-frozen (by got deepFreeze), so the arrays are read-only. The mutation attempt throws a TypeError during SSR React rendering.
1. Create a Next.js 16 app with next/image. 2. Deploy to production (e.g. Vercel) with default next.config.js. 3. Load a page containing next/image. 4. Observe SSR failure: TypeError: Cannot assign to read only property '0' of object at Array.sort in image-component.js.

Fixing Code Block

Edge Case Audit

Cloning arrays on each render adds minor memory and CPU overhead. Ensure the patched file survives rebuilds (use patch-package or apply in node_modules after install). If c.qualities is undefined, the fallback preserves the original value. Rollback: remove the patch or replace with original code if official fix ships. Upgrading Next.js may overwrite the hotfix.

Ecosystem Topology