Back to Fluentui

UnprocessedStyles

apps/public-docsite-v9/src/Concepts/UnprocessedStyles.mdx

4.40.2-hotfix25.7 KB
Original Source

import { Meta, Source } from '@storybook/addon-docs/blocks';

<Meta title="Concepts/Developer/Unprocessed Styles" />

Unprocessed Styles (Raw Modules)

Overview

Fluent UI v9 components now ship with raw module alternatives to solve CSS style conflicts in multi-bundle applications. This feature addresses critical issues where Griffel-processed styles clash when multiple application bundles are loaded simultaneously.

The Problem: Style Clashes in Multi-Bundle Apps

Modern applications often split code into multiple bundles (main app bundle, CDN bundles, micro-frontends, etc.). When each bundle contains pre-processed Griffel styles, CSS class conflicts can occur:

html
<!-- Main bundle styles -->
<style>
  .order0 {
    padding: 10px;
  }
  .order1 {
    padding-left: 5px;
  }
</style>

<!-- CDN bundle styles (loaded later) -->
<style>
  .order0 {
    padding: 10px;
  } /* Overrides main bundle! */
</style>

<!-- Result: Expected padding-left: 5px, but got padding: 10px -->
<div className="order0 order1"></div>

The Solution: Raw Modules with Style Prefixing

Raw modules contain unprocessed Griffel styles that can be configured with unique prefixes at build time, preventing CSS conflicts:

html
<!-- With prefixed styles -->
<style>
  .main-order0 {
    padding: 10px;
  }
  .main-order1 {
    padding-left: 5px;
  }
</style>

<style>
  .cdn-order0 {
    padding: 10px;
  } /* No conflict! */
</style>

How to Use Raw Modules

Configure your bundler to prioritize .raw.js extension resolution:

Webpack Configuration:

js
// webpack.config.js
module.exports = {
  resolve: {
    extensions: ['.raw.js', '...'],
  },
};

Vite Configuration:

js
// vite.config.js
export default {
  resolve: {
    extensions: ['.raw.js', '.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
  },
};

Package Support Status

PackageShips Processed StylesRaw Modules AvailableVersion
@fluentui/react-components⚠️ Yes✅ Availablev9.67.0+
@fluentui-contrib/*✅ No✅ Not neededN/A
@fluentui-copilot/*⚠️ Yes✅ Availablev0.28.4+, Older major version back-ports / v0.26.2-hotfix.1, v0.25.3-hotfix.1
@fluentui/react-icons⚠️ Yes✅ Availablev2.0.307+
@fluentui/react-charts⚠️ Yes✅ Availablev9.2.0+
MSFT Design react-icons⚠️ Yes❌ Not planned-

Benefits

  • ✅ Backward Compatible: Existing apps continue to work without changes
  • ✅ Zero Breaking Changes: Raw modules are opt-in via bundler configuration
  • ✅ Performance: Avoids CSS specificity hacks and runtime overhead
  • ✅ Future-Proof: Enables style prefixing and better multi-bundle support

Learn More