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

Next.Js Webpack Mangles @Import Supports() To @Media Supports(), Breaking Conditional CSS

When inlining CSS via Webpack, Next.js incorrectly transforms @import supports(display:flex) into @media supports(display:flex) instead of @supports(display:flex), causing conditional rules to be ignored by browsers.

mediumConfidence 85%Next.jsReact Server ComponentsHydrationAffected V16.2.0-Canary.29

Origin Analysis

The CSS import inlining logic in Next.js's Webpack pipeline fails to distinguish between media and supports conditions in the @import at-rule, mistakenly wrapping the imported content in a @media rule with a supports(...) parameter rather than a dedicated @supports rule.
1. Create a Next.js project with a CSS file containing '@import url("./other.css") supports(display: flex);'.\n2. In other.css, define a rule that should apply under the supports condition (e.g., h1 { color: red !important; }).\n3. Run 'npm run build && npm run start' or 'npm run dev'.\n4. Load the page and observe the h1 color is not red; inspect the compiled CSS in the network tab to see the erroneous @media supports(...) wrapper.

Fixing Code Block

// Create postcss.config.js at project root module.exports = { plugins: [ require('./postcss-fix-import-supports.js') ] }; // Create postcss-fix-import-supports.js at project root const postcss = require('postcss'); module.exports = postcss.plugin('postcss-fix-import-supports', () => { return (root) => { root.walkAtRules('media', (atRule) => { if (atRule.params.startsWith('supports(')) { atRule.name = 'supports'; atRule.params = atRule.params.slice('supports('.length, -1); } }); }; });
This hotfix adds a PostCSS plugin that runs after Next.js's built-in CSS processing. It detects any @media rule whose parameters begin with 'supports(' and rewrites it to a proper @supports rule by changing the at-rule name and stripping the redundant wrapper. This restores the expected browser interpretation of the conditional CSS.

Edge Case Audit

The fix is a global post-processing patch that blindly converts any @media supports(...) into @supports(...). While standard CSS does not define @media supports, custom build outputs or future changes may rely on that syntax. It only addresses the symptom and not the root cause in the import inlining logic. Users should remove this patch once an official fix is released and thoroughly test all CSS outputs to avoid unintended rule alterations. Rollback is as simple as deleting the two files.

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