diff --git a/apps/public-docsite-v9/src/Concepts/Theming.mdx b/apps/public-docsite-v9/src/Concepts/Theming.mdx index 0b116fa1418cc..446b7c2644a76 100644 --- a/apps/public-docsite-v9/src/Concepts/Theming.mdx +++ b/apps/public-docsite-v9/src/Concepts/Theming.mdx @@ -112,6 +112,10 @@ export const customDarkTheme = createDarkTheme(customBrandRamp); A theme is a flat object containing `{ [token name]: CSS value }` pairs. You can copy the object and overwrite any tokens you wish. +Theme names and values are developer-authored CSS. If theme customization is based on dynamic data, validate it against +an application-specific schema before constructing the theme. Fluent UI contains generated declarations structurally, +but does not determine whether a valid CSS value or URL is appropriate for your application. + ```tsx import { webLightTheme, Theme } from '@fluentui/react-components'; diff --git a/apps/public-docsite-v9/src/Utilities/Theme/createCSSRuleFromTheme/createCSSRuleFromThemeDescription.md b/apps/public-docsite-v9/src/Utilities/Theme/createCSSRuleFromTheme/createCSSRuleFromThemeDescription.md index 2d6e57860012b..dc977f1871e2f 100644 --- a/apps/public-docsite-v9/src/Utilities/Theme/createCSSRuleFromTheme/createCSSRuleFromThemeDescription.md +++ b/apps/public-docsite-v9/src/Utilities/Theme/createCSSRuleFromTheme/createCSSRuleFromThemeDescription.md @@ -1 +1,5 @@ This API allows you to create CSS from a theme and apply this CSS, for example, to ``. + +The selector and theme are developer-authored CSS. Validate dynamic data against an application-specific schema before +using it to construct a theme. The generated declarations are structurally contained, but the API does not determine +whether a valid CSS value or URL is appropriate for your application. diff --git a/change/@fluentui-react-provider-8f64011f-66bb-4fae-bf5e-e52d91e39408.json b/change/@fluentui-react-provider-8f64011f-66bb-4fae-bf5e-e52d91e39408.json new file mode 100644 index 0000000000000..ed3af4a6b461b --- /dev/null +++ b/change/@fluentui-react-provider-8f64011f-66bb-4fae-bf5e-e52d91e39408.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix: structurally validate serialized theme tokens", + "packageName": "@fluentui/react-provider", + "email": "paulmardling@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/docs/react-v9/contributing/patterns/extending-tokens.md b/docs/react-v9/contributing/patterns/extending-tokens.md index f26008de479f0..1fc1e94679843 100644 --- a/docs/react-v9/contributing/patterns/extending-tokens.md +++ b/docs/react-v9/contributing/patterns/extending-tokens.md @@ -4,6 +4,9 @@ It's often useful for an app to extend the base set of tokens from Fluent UI. ⚠ Warning that adding more tokens adds more CSS variables which can effect run time performance as each DOM Node carries all the tokens. +Theme names and values are developer-authored CSS. Validate dynamic data against an application-specific schema before +using it to construct or extend a theme. + ```tsx import { makeStyles, themeToTokensObject, webLightTheme, FluentProvider, Theme } from '@fluentui/react-components'; diff --git a/packages/react-components/react-provider/library/src/components/FluentProvider/FluentProvider-node.test.tsx b/packages/react-components/react-provider/library/src/components/FluentProvider/FluentProvider-node.test.tsx index 3bca12bf969f9..31496aace8e63 100644 --- a/packages/react-components/react-provider/library/src/components/FluentProvider/FluentProvider-node.test.tsx +++ b/packages/react-components/react-provider/library/src/components/FluentProvider/FluentProvider-node.test.tsx @@ -76,4 +76,28 @@ describe('FluentProvider (node)', () => { " `); }); + + it('contains theme entries in the server style element', () => { + const theme = { + customToken: 'url(resource/*);token/**/)', + validToken: 'green', + } as unknown as PartialTheme; + + const html = renderToStaticMarkup(); + + expect(parseHTMLString(html)).toMatchInlineSnapshot(` + "
+ +
" + `); + expect(html.match(/