-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Render theme CSS variables in SSR style element #27277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
4735d90
feat: Render theme CSS variables in new SSR style slot
ling1726 008b7bb
changefile
ling1726 564366c
revert
ling1726 1f9ca81
remove mock
ling1726 73c2314
add explainer
ling1726 12696d3
update md
ling1726 cc23599
add nonce
ling1726 5a5d447
make slot private
ling1726 6a5ad4b
Remove SSR element on first render
ling1726 2bea363
remove changefile
ling1726 f795b08
pr feedback
ling1726 bba6470
update changfile
ling1726 4954b9e
Merge branch 'master' into feat/ssr-css-variables
ling1726 e06aef8
Merge branch 'master' into feat/ssr-css-variables
ling1726 41751a0
stop using query selector
ling1726 d12535a
pass renderer to useFluentpRoviderThemeStyleTag hook
ling1726 53f6ad0
rename rendererAttributes to attributes
ling1726 be47770
simplify logic
ling1726 a38edf8
remove data attribute
ling1726 4bfde2d
use PartialTheme type
ling1726 c184f6c
remove SSRPRovider from tests
ling1726 8ee281a
remove cruft
ling1726 cc056f7
use ternary render
ling1726 46f2b0e
Merge branch 'master' into feat/ssr-css-variables
ling1726 a110b5c
update md
ling1726 db16298
only pass attributes
ling1726 094b7f7
remove ssr provider
ling1726 6c04a92
fix tests
ling1726 3b7afda
update md
ling1726 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-provider-51de7ed7-e932-4b2f-aa6b-c871f1b8c016.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "feat: Render theme CSS variables in SSR style element", | ||
| "packageName": "@fluentui/react-provider", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...eact-components/react-provider/src/components/FluentProvider/FluentProvider-node.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * @jest-environment node | ||
| */ | ||
|
|
||
| // 👆 this is intentionally to test in SSR like environment | ||
|
|
||
| import * as React from 'react'; | ||
| import * as ReactDOM from 'react-dom/server'; | ||
| import { resetIdsForTests, SSRProvider } from '@fluentui/react-utilities'; | ||
| import { FluentProvider } from './FluentProvider'; | ||
| import * as prettier from 'prettier'; | ||
| import { createDOMRenderer } from '@griffel/core'; | ||
| import { RendererProvider } from '@griffel/react'; | ||
| import { PartialTheme } from '@fluentui/react-theme'; | ||
|
|
||
| const parseHTMLString = (html: string) => { | ||
| return prettier.format(html, { parser: 'html' }); | ||
| }; | ||
|
|
||
| describe('FluentProvider (node)', () => { | ||
| const testTheme: PartialTheme = { | ||
| colorNeutralForeground1: 'black', | ||
| colorNeutralBackground1: 'white', | ||
| }; | ||
|
|
||
| afterEach(() => { | ||
| resetIdsForTests(); | ||
| }); | ||
|
|
||
| it('should render CSS variables as inline style', () => { | ||
| const html = ReactDOM.renderToStaticMarkup(<FluentProvider theme={testTheme} />); | ||
|
|
||
| expect(parseHTMLString(html)).toMatchInlineSnapshot(` | ||
| "<div | ||
| dir="ltr" | ||
| class="fui-FluentProvider fui-FluentProvider1 " | ||
| > | ||
| <style id="fui-FluentProvider1"> | ||
| .fui-FluentProvider1 { | ||
| --colorNeutralForeground1: black; | ||
| --colorNeutralBackground1: white; | ||
| } | ||
| </style> | ||
| </div>" | ||
| `); | ||
| }); | ||
|
|
||
| it('renders nonce with SSR style element', () => { | ||
| const nonce = 'random'; | ||
| const renderer = createDOMRenderer(undefined, { | ||
| styleElementAttributes: { nonce }, | ||
| }); | ||
|
|
||
| const html = ReactDOM.renderToStaticMarkup( | ||
| <SSRProvider> | ||
| <RendererProvider renderer={renderer}> | ||
| <FluentProvider theme={testTheme} /> | ||
| </RendererProvider> | ||
| </SSRProvider>, | ||
ling1726 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
ling1726 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| expect(parseHTMLString(html)).toMatchInlineSnapshot(` | ||
| "<div | ||
| dir="ltr" | ||
| class="fui-FluentProvider fui-FluentProvider1 " | ||
| > | ||
| <style nonce="random" id="fui-FluentProvider1"> | ||
| .fui-FluentProvider1 { | ||
| --colorNeutralForeground1: black; | ||
| --colorNeutralBackground1: white; | ||
| } | ||
| </style> | ||
| </div>" | ||
| `); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.