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

Next/Dynamic Preloads Missing CrossOrigin Setting

When using next/dynamic with assetPrefix and crossOrigin configured, automatically injected preload links for dynamic chunks lack the crossorigin attribute, causing browser warnings and potential duplicate fetches.

mediumConfidence 85%Next.jsServer ActionsApp RouterAffected V16.2.3

Origin Analysis

In packages/next/src/shared/lib/lazy-dynamic/preload-chunks.tsx, the ReactDOM preload call does not include the crossOrigin option, so the generated <link rel=preload> omits the crossorigin attribute even when crossOrigin is set in next.config.js.
1. In next.config.js set assetPrefix to a different domain and crossOrigin: 'anonymous'. 2. Use next/dynamic to lazy load a component. 3. Build and open the page. 4. Inspect the HTML for the preload link of the dynamic chunk; note missing crossorigin attribute. 5. Observe browser console warning about preload credentials mismatch.

Fixing Code Block

// packages/next/src/shared/lib/lazy-dynamic/preload-chunks.tsx import { preload } from 'react-dom' export function preloadChunks(chunks: string[]) { const crossOrigin = process.env.__NEXT_CROSS_ORIGIN for (const chunk of chunks) { preload(chunk, { as: 'script', ...(crossOrigin ? { crossOrigin } : {}), }) } }
The fix reads the crossOrigin value from the Next.js runtime environment variable (process.env.__NEXT_CROSS_ORIGIN, which is populated from next.config.js) and conditionally adds it to ReactDOM.preload options. This ensures the emitted preload link includes the correct crossorigin attribute, matching the script tag generated by next/dynamic and avoiding credential mode mismatches.

Edge Case Audit

This patch relies on process.env.__NEXT_CROSS_ORIGIN being defined by Next.js at build time; if unused in older versions the variable may be undefined, in which case the behavior is unchanged. The change is safe for concurrency and SSR but should be rolled back by removing the added crossOrigin option and rebuilding if any unexpected CORS issues occur. The patch is local to node_modules and will be overwritten on upgrade; use patch-package or wait for an official fix.

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