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

SegmentViewNode Produces Unique Key Error When Passing Shared Object Reference

Passing a shared object reference in multiple props through a 'use cache' boundary causes React to emit a unique key warning at the SegmentViewNode level, even though the data contains no React elements.

mediumConfidence 85%Next.jsnext buildApp RouterAffected V16.2.0-Canary.48

Origin Analysis

Next.js Cache Components serialization mishandles shared object references, incorrectly treating object/array props as React children lists when reconstructing the tree, leading to missing keys in SegmentViewNode.
Create a 'use cache' page that imports a client component. Pass the same object reference in two props (e.g., item and items array containing the same object). Run dev server and observe the console warning.

Fixing Code Block

"use cache"; import { Display } from "./client"; export default async function Page() { const baseItem = { id: "1", name: "Apple", tags: ["fruit"] }; return ( <Display item={structuredClone(baseItem)} items={[structuredClone(baseItem)]} /> ); }
Deep-copy the shared object before passing it in each prop position using structuredClone. This ensures each prop receives a distinct object reference, preventing the internal serialization from misinterpreting the props as a list of children and thus suppressing the key warning.

Edge Case Audit

This workaround adds cloning overhead, which may impact performance for large or frequently rendered objects. structuredClone may not be available in older browsers or Node versions (though next dev requires modern Node). It also loses non-cloneable values (functions, symbols) and breaks reference equality if downstream code relies on identity. Rollback: remove the deep clones after upgrading to a Next.js version that fixes the underlying issue.

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