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%NextTurbopackHydrationAffected 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

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state