griffel-styling
Author and debug Fluent UI v9 styles built on the Griffel CSS-in-JS engine. Use when writing or fixing makeStyles, makeResetStyles, mergeClasses, shorthands, tokens, custom style hooks (useXStyles_unstable / CustomStyleHooksProvider_unstable), RendererProvider, CSS Modules cascade layers, Griffel patches, RTL/@noflip handling, build-time style transforms, or when diagnosing override-precedence and class-collision bugs. IGNORE and DO NOT use when editing ./apps/prototype
- License 许可
- CC-BY-4.0
- 最近更新
- 2026-11-06
- Stars
- ★ 2
- Forks
- 1
01 前言 Front Matter
- name
- griffel-styling
- description
- Author and debug Fluent UI v9 styles built on the Griffel CSS-in-JS engine. Use when writing or fixing makeStyles, makeResetStyles, mergeClasses, shorthands, tokens, custom style hooks (useXStyles_unstable / CustomStyleHooksProvider_unstable), RendererProvider, CSS Modules cascade layers, Griffel patches, RTL/@noflip handling, build-time style transforms, or when diagnosing override-precedence and class-collision bugs. IGNORE and DO NOT use when editing ./apps/prototype
02 资源文件 5
- 参考文档advanced-styling-techniques.md6.9 KB
- 参考文档build-time-styles.md8.1 KB
- 参考文档styles-handbook.md25.3 KB
- 参考文档styling-components-basics.md6.7 KB
- 参考文档unprocessed-styles.md5.8 KB
03 SKILL.md 正文
Griffel is Fluent UI v9's CSS-in-JS engine. Read the relevant doc below before writing or debugging makeStyles/mergeClasses code — do not guess at API shape or merge semantics.
Docs index
-
Styles Handbook — The core reference. Explains Griffel's atomic-CSS model,
makeStyles(and its lack of CSS shorthand support, useshorthands.*instead),mergeClasses(Object.assign-like, last argument wins per CSS property, never concatenate class strings),makeResetStyles(single monolithic class for base styles, avoids "rule explosion" from nested selectors/pseudo-classes), RTL auto-flipping (and the@noflipescape hatch + CSS-variable caveat), selector-complexity/performance guidance (avoid wide selectors like> *), and best practices (usetokensnot literal colors, avoid!important, callmergeClassesonce per element). -
Styling Components (Basics) — Quick-start intro to
makeStyles/mergeClasses. Covers the fundamental rule that argument order inmergeClassesdetermines precedence (later args win), how to merge parent-passedclassNamecorrectly (mergeClasses(classes.root, props.className)— props last so callers can override), applying theme tokens, common anti-patterns (string concatenation, wrong merge order), the Griffel DevTools extension for debugging, and how to override styles on stock Fluent components from consumer code viaclassName/slot props. -
Advanced Styling Techniques — How Fluent v9 components call
useXStyles_unstable(state)thenuseCustomStyleHook_unstable('useXStyles_unstable')(state), letting an app-levelCustomStyleHooksProvider_unstableinject theme-wide overrides per component type. Critical rule: custom style hooks must merge asmergeClasses(state.root.className, themeStyles.root, getSlotClassNameProp_unstable(state.root))— theme styles are NOT last; the slot's originalclassNameprop is re-applied after theme styles so a caller'sclassNamealways wins. Also covers why nestedCustomStyleHooksProvider_unstableproviders replace (not merge) values, and the pattern for composing multiple custom style hook sets ("Smart" + "Fancy" → "Smancy") by calling them in sequence, last-called-wins. -
Build-Time Styles — How to move Griffel's runtime style-resolution cost to build time via
@griffel/webpack-loader(apps) or@griffel/babel-preset(libraries), including TypeScript preset config and using a custommoduleSourcewhenmakeStylesis re-exported from a third-party package (relevant for@coreai-ds/react-components's own re-export). Explains what the transform actually does (replacesmakeStylescalls with a lightweight__stylescall + precomputed atomic CSS) and Linaria-based build-time evaluation of style helper code. -
Unprocessed Styles (Raw Modules) — Explains the multi-bundle CSS class-collision problem when several bundles each ship pre-processed Griffel styles (e.g. micro-frontends, CDN bundles), and the
.raw.jsraw-module bundler-resolution mechanism (Webpack/Viteresolve.extensions) that lets each bundle prefix its own class names instead of colliding. Includes a package support-status table for which Fluent packages ship raw modules today.
Known gotchas relevant to this repo
For CSS Modules override/layering work:
- Read Styling with CSS Modules.
- Use an app-owned renderer through
RendererProvider; do not patch sharednode_modulesor add a global Griffel override. - Preserve buckets and tuple metadata, and create the renderer once above
CoreAIFluentProvider. - Check the installed insertion API after Griffel/Fluent upgrades.
- Verify actual computed overrides, responsive rules, and portals in development and production preview. Layer extracted static CSS separately when applicable.
mergeClassesis not real CSS cascade — it resolves per-CSS-property conflicts viaObject.assign-style last-argument-wins, before the browser ever sees the CSS. A losing class's declarations are dropped entirely, even if written with!important.- The canonical, documented merge order for a custom style hook's root slot is
mergeClasses(state.root.className, themeClasses, getSlotClassNameProp_unstable(state.root))per Advanced Styling Techniques — re-applying the slot's original className last so instance-level overrides win over theme styles. Compare this against anyapplyToRoot-style helpers inpackages/react-components/src/components/*.styles.tswhen debugging override-precedence bugs. - This 3-argument pattern gives a full stock default < CoreAI theme < instance className priority, including for properties that stock Fluent's own base styles also set (e.g. Table's
borderCollapse) —getSlotClassNameProp_unstablerecovers only the consumer's original className (captured before Fluent fuses default+instance), so re-applying it last always lets it win regardless of what the fused blob or theme classes contain.
This repo's styling convention
See packages/react-components/code-conventions.md
for the mandatory mergeClasses order used by every custom style hook in
packages/react-components/src/components/*.styles.ts, plus the two
"wrong" 2-tier patterns to avoid.
04 同仓库更多 Skills
coreai-ds-fluentui-react
MANDATORY for @coreai-ds/react-components work. Use the CoreAI documentation MCP to discover components, props, stories, templates, and implementation patterns. If the MCP is unavailable, stop and ask the user to enable or troubleshoot it with you.
state-management
CoreAI Sandbox's simplified TanStack Query + mock-JSON data layer. USE WHEN: editing data-fetching hooks (`app/hooks/use*.ts`), adding mock data in `app/data/`, or wiring a component to query state.
start-app
Start the CoreAI Sandbox dev server and open it using available browser tools. USE WHEN: the user asks you to "start the app", "run the dev server", "open the app", or "launch CoreAI Sandbox".
routing
React Router v7 routing conventions for this SPA. USE WHEN: editing `app/routes.ts`, adding/removing a route, or changing navigation.
react-components
CoreAI Sandbox component usage: import boundaries, CoreAI MCP documentation, and local adapter inspection. USE WHEN: editing any `*.tsx` file, picking a component, or writing component imports.
new-variant
Create a new design variant or alternative for a page using the built-in feature/variant system. USE WHEN: a designer wants to try a different layout, create an "option B" or "version 2", compare designs side by side, add an A/B alternative, or explore an alternate version. Do NOT build a custom toggle solution.