-
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
Conversation
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
Adds a new `serverStyle` slot to the `FluentProvider` that is only rendered when the provider is a child of an `SSRProvider`. Also updates `useFluentProviderThemeTag` to return the CSS rule that contains all CSS variables. This PR makes use of dangerous HTML, since react will output certain characters in unicode which can result in invalid CSS, [this approach is also taken by Emotion](https://github.com/emotion-js/emotion/blob/89b6dbb3c13d49ef1fa3d88888672d810853f05a/packages/react/src/emotion-element.js#L72-L78)
Collaborator
📊 Bundle size reportUnchanged fixtures
|
Collaborator
Perf Analysis (
|
| Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
|---|---|---|---|---|---|
| FluentProviderWithTheme | virtual-rerender | 237 | 279 | 10 | Possible regression |
All results
| Scenario | Render type | Master Ticks | PR Ticks | Iterations | Status |
|---|---|---|---|---|---|
| Avatar | mount | 952 | 884 | 5000 | |
| Button | mount | 575 | 584 | 5000 | |
| Field | mount | 1655 | 1603 | 5000 | |
| FluentProvider | mount | 1135 | 1170 | 5000 | |
| FluentProviderWithTheme | mount | 306 | 322 | 10 | |
| FluentProviderWithTheme | virtual-rerender | 237 | 279 | 10 | Possible regression |
| FluentProviderWithTheme | virtual-rerender-with-unmount | 303 | 297 | 10 | |
| InfoButton | mount | 209 | 211 | 5000 | |
| MakeStyles | mount | 1336 | 1316 | 50000 | |
| Persona | mount | 2342 | 2240 | 5000 | |
| SpinButton | mount | 2008 | 1983 | 5000 |
Asset size changesSize Auditor did not detect a change in bundle size for any component! Baseline commit: be0ca69899300abe3c8478c435e0f6837138479b (build) |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 3b7afda:
|
Collaborator
🕵 fluentuiv9 No visual regressions between this PR and main |
packages/react-components/react-provider/src/components/FluentProvider/useFluentProvider.ts
Show resolved
Hide resolved
packages/react-components/react-provider/src/components/FluentProvider/FluentProvider.types.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-provider/src/components/FluentProvider/useFluentProvider.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-provider/src/components/FluentProvider/renderFluentProvider.tsx
Outdated
Show resolved
Hide resolved
...ct-components/react-provider/src/components/FluentProvider/useFluentProviderThemeStyleTag.ts
Show resolved
Hide resolved
packages/react-components/react-provider/src/components/FluentProvider/useFluentProvider.ts
Outdated
Show resolved
Hide resolved
...ct-components/react-provider/src/components/FluentProvider/useFluentProviderThemeStyleTag.ts
Outdated
Show resolved
Hide resolved
...ct-components/react-provider/src/components/FluentProvider/useFluentProviderThemeStyleTag.ts
Outdated
Show resolved
Hide resolved
packages/react-components/react-provider/src/components/FluentProvider/useFluentProvider.ts
Outdated
Show resolved
Hide resolved
...s/react-components/react-provider/src/components/FluentProvider/FluentProvider-node.test.tsx
Outdated
Show resolved
Hide resolved
...s/react-components/react-provider/src/components/FluentProvider/FluentProvider-node.test.tsx
Show resolved
Hide resolved
...s/react-components/react-provider/src/components/FluentProvider/FluentProvider-node.test.tsx
Show resolved
Hide resolved
...s/react-components/react-provider/src/components/FluentProvider/FluentProvider-node.test.tsx
Show resolved
Hide resolved
packages/react-components/react-provider/src/components/FluentProvider/renderFluentProvider.tsx
Outdated
Show resolved
Hide resolved
packages/react-components/react-provider/src/components/FluentProvider/FluentProvider.test.tsx
Outdated
Show resolved
Hide resolved
...s/react-components/react-provider/src/components/FluentProvider/FluentProvider-node.test.tsx
Outdated
Show resolved
Hide resolved
layershifter
approved these changes
Mar 23, 2023
marcosmoura
added a commit
to marcosmoura/fluentui
that referenced
this pull request
Mar 27, 2023
* master: (47 commits) fix: Fix vertical alignment of inline Checkbox when checked vs. unchecked (microsoft#27324) applying package updates Fix: Revert microsoft#26931 change due to new bug it introduced (microsoft#27323) chore(react-infobutton): Renaming content slot to info (microsoft#27316) applying package updates Fix bad release mismatch of react-select (microsoft#27321) applying package updates Fix react-combobox mismatch after bad release (microsoft#27319) docs: add section about media query sorting (microsoft#27307) applying package updates fix: sync packages and changefiles after bad release (microsoft#27317) applying package updates chore(react-datepicker-compat): Cleanup types, unused code, and restore utils tests (microsoft#27297) [Fluent 2 Theme] Fixing link color in dark theme (microsoft#27203) Tree documentation and stories (microsoft#27270) feat: Render theme CSS variables in SSR style element (microsoft#27277) chore (scripts): update create-package plop templates to use swc/helpers in deps (microsoft#27286) fix(DialogContent): adds padding to allow focus visibility (microsoft#27248) Adding Card component style hooks to shared context (microsoft#27295) Virtualizer: Static scroll hooks and embedded scrollview (microsoft#26985) ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Adds a new
serverStyleslot to theFluentProviderthat is only rendered in the server when wrapped by anSSRProvider.Also updates
useFluentProviderThemeTagto return the CSS rule that contains all CSS variables.useFluentProviderThemeTagwill now move any theme style elements from body to head on first render (done to avoid hydration errors). The insertion effect will check to see if its corresponding theme style element has already been rendered by SSR based on thestyleTagId.This PR makes use of dangerouslySetInnerHTML since react will output certain characters in unicode which can result in invalid CSS, this approach is also taken by Emotion
Fixes #25425