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

Turbopack HMR Fails To Update Server Component Using Singleton Registry On MacOS

When using a singleton pattern to register server components, Turbopack HMR does not update the content in the browser, while webpack works correctly. The issue occurs on macOS with Next.js 16.3.0.

mediumConfidence 80%Next.jsApp RouterPages RouterRoute HandlersAffected V16.3.0

Origin Analysis

Turbopack's HMR mechanism does not properly invalidate module-level singleton caches when a module is hot-replaced. The singleton registry retains the old component reference, preventing the updated component from being rendered. Webpack's HMR handles module replacement differently, leading to correct updates.
1. Use a macOS device. 2. Run npm install. 3. Run npm run dev (Turbopack). 4. Edit components/problem-server-component.tsx and save. 5. Observe that the UI does not update immediately. 6. Edit components/working-client-component.tsx and save; observe that client component updates. 7. Stop and run npm run dev:webpack. 8. Repeat step 4 and notice that HMR works with webpack.

Fixing Code Block

// Fix: Remove the singleton registry and directly export/import the component. // problem-server-component.tsx export default function ProblemServerComponent() { return <div>Updated text from HMR</div>; } // page.tsx (or parent component) import ProblemServerComponent from './problem-server-component'; export default function Page() { return <ProblemServerComponent />; }
Directly exporting and importing the component allows Turbopack to track the module dependency and update the exported reference during HMR. The singleton registry bypasses the module export system, leaving stale references that HMR cannot refresh.

Edge Case Audit

Removing the singleton pattern may eliminate intentional shared state or instance uniqueness. If singleton behavior is required, consider using React's cache() for server components or await an official Turbopack fix. This workaround only affects development HMR and has no impact on production builds. Rollback: revert to the original singleton code after upgrading Next.js to a version that fixes the underlying HMR 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