-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Clean up <ThemeProvider> and various CSS related stuff #5611
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
compulim
merged 63 commits into
microsoft:main
from
compulim:feat-clean-up-theme-provider
Oct 14, 2025
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
69a334f
Clean CSS injection
compulim f88316d
Clean up nonce usage
compulim 2b4cacb
Remove nonce from <ThemeProvider>
compulim d590d10
Rename <WebChatTheme> to <Inject*CSS>
compulim 14ebc9a
Clean up
compulim a741a60
Add comment
compulim 1a74333
Add comment
compulim b890931
Fix identifier
compulim bfd5f2d
Remove nonce requirement
compulim 1c606e9
Direct inject after building style elements
compulim 474af5a
Add entry
compulim 67600b7
Remove launcher experience
compulim 30aaac5
Fix imports
compulim 948bf37
Fix imports
compulim 1c9e842
Fix tests
compulim 4bfc718
Better imports
compulim 7b2f79f
Use Happy DOM
compulim 0016d4c
Return children as-is
compulim 6f13288
Merge branch 'main' into feat-clean-up-theme-provider
compulim 9399590
Remove unnecessary files
compulim a986552
Dedupe across instances
compulim 4bd60d9
Add test
compulim 3559026
Use hooks
compulim fd4ae05
Mvoe from hook to leaf node
compulim 382ba4b
Move to create CSS function
compulim 3170c13
Fix tsup
compulim e23d3b3
Allow rectifying twice
compulim 41066ad
Mark nonce as optional
compulim b60ae40
Reverse order
compulim e44e898
Add component
compulim 74b2dde
Add /component
compulim 7f65a52
Remove snapshots
compulim acba8f0
Fix script-0.mjs
compulim f45fc60
Fix script-0.mjs
compulim 8b4e058
Fix styleOptions
compulim d361f11
Allow cascaded rectify style options
compulim c27f54e
Separate stylesRoot from fluent-theme
compulim 8ccf86a
Mark stylesRoot as optional
compulim 8264448
Componentize <InjectStyleElements>
compulim 5ddcf8c
Fix --watch 200
compulim 68ad21f
Fix flakiness
compulim ac14353
Fix test
compulim 0f96477
Fix test
compulim 15b68c3
Fix --watch 200
compulim 7b10338
Move stylesheet to bottommost on re-inject
compulim 597141b
Fix hideScrollToEndButton
compulim 6a5fc7b
Fix hideScrollToEndButton
compulim c7b2465
Clean up
compulim b7e5c80
Clean up
compulim 75ddff7
Clean up
compulim ae1c734
Rename *CSS -> *Stylesheet
compulim 8693e87
Componentize as <FluentThemeStylesheet>
compulim 2c0dbeb
Merge branch 'main' into feat-clean-up-theme-provider
compulim 7b14061
Rename to <CSSCustomPropertiesContainer>
compulim d8899c7
Fix tests
compulim 015793b
Fix styleRoots and import hooks
compulim 58aec61
Add importmap for hook
compulim a461ee0
Merge branch 'main' into feat-clean-up-theme-provider
compulim e4c0709
Move InjectStyleElements to styles package
compulim 77aba36
Yellow instead of white
compulim 55274ef
Add styles as devDependencies
compulim fb6c67f
Fix import map
compulim fa184dc
Retrigger checks
compulim 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
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
Binary file removed
BIN
-2.29 KB
...-inject-styles-change-nonce-js-use-inject-styles-should-change-nonce-2-snap.png
Binary file not shown.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
File renamed without changes
File renamed without changes
77 changes: 77 additions & 0 deletions
77
__tests__/html2/hooks/useInjectStylesElements/changeRoot.html
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,77 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="text/babel" data-presets="env,stage-3,react"> | ||
| const { | ||
| testHelpers: { createDirectLineEmulator }, | ||
| WebChat: { | ||
| internal: { InjectStyleElements } | ||
| } | ||
| } = window; | ||
|
|
||
| function createStyle(body) { | ||
| const styleElement = document.createElement('style'); | ||
|
|
||
| styleElement.dataset['testid'] = 'style'; | ||
| styleElement.innerHTML = body; | ||
|
|
||
| return styleElement; | ||
| } | ||
|
|
||
| run(async function () { | ||
| const { directLine, store } = createDirectLineEmulator(); | ||
|
|
||
| const render = ({ nonce, styleElements, stylesRoot }) => | ||
| new Promise(resolve => | ||
| ReactDOM.render( | ||
| <InjectStyleElements at={stylesRoot} nonce={nonce} styleElements={styleElements} />, | ||
| document.getElementById('webchat'), | ||
| resolve | ||
| ) | ||
| ); | ||
|
|
||
| const styleElement = createStyle('main { background-color: Red!important; }'); | ||
|
|
||
| // WHEN: Inject into default (document.head). | ||
| await render({ styleElements: [styleElement] }); | ||
|
|
||
| // THEN: Should render red. | ||
| await host.snapshot('local'); | ||
|
|
||
| // THEN: Should inject into document.head. | ||
| const styleElementsInHead = document.head.querySelectorAll('style[data-testid="style"]'); | ||
|
|
||
| expect(styleElementsInHead).toHaveLength(1); | ||
| expect(styleElementsInHead[0]).toHaveProperty('textContent', styleElement.textContent); | ||
|
|
||
| // THEN: Should not inject into document.body. | ||
| expect(document.body.querySelectorAll('style[data-testid="style"]')).toHaveLength(0); | ||
|
|
||
| // WHEN: Inject into document.body. | ||
| await render({ styleElements: [styleElement], stylesRoot: document.body }); | ||
|
|
||
| // THEN: Should render red. | ||
| await host.snapshot('local'); | ||
|
|
||
| // THEN: Should inject into document.body. | ||
| const styleElementsInBody = document.body.querySelectorAll('style[data-testid="style"]'); | ||
|
|
||
| expect(styleElementsInBody).toHaveLength(1); | ||
| expect(styleElementsInBody[0]).toHaveProperty('textContent', styleElement.textContent); | ||
|
|
||
| // THEN: Should not inject into document.head. | ||
| expect(document.head.querySelectorAll('style[data-testid="style"]')).toHaveLength(0); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
91 changes: 91 additions & 0 deletions
91
__tests__/html2/hooks/useInjectStylesElements/dupeElement.html
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,91 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script> | ||
| <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
| <style> | ||
| main { | ||
| background-color: Yellow !important; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="text/babel" data-presets="env,stage-3,react"> | ||
| const { | ||
| testHelpers: { createDirectLineEmulator }, | ||
| WebChat: { | ||
| internal: { InjectStyleElements } | ||
| } | ||
| } = window; | ||
|
|
||
| function createStyle(body) { | ||
| const styleElement = document.createElement('style'); | ||
|
|
||
| styleElement.dataset['testid'] = 'style'; | ||
| styleElement.innerHTML = body; | ||
|
|
||
| return styleElement; | ||
| } | ||
|
|
||
| run(async function () { | ||
| const { directLine, store } = createDirectLineEmulator(); | ||
|
|
||
| const render = ({ nonce, styleElements, stylesRoot }) => | ||
| new Promise(resolve => | ||
| ReactDOM.render( | ||
| <InjectStyleElements at={stylesRoot} nonce={nonce} styleElements={styleElements} />, | ||
| document.getElementById('webchat'), | ||
| resolve | ||
| ) | ||
| ); | ||
|
|
||
| const styleElement = createStyle('main { background-color: Red!important; }'); | ||
|
|
||
| await render({ styleElements: [styleElement, styleElement] }); | ||
|
|
||
| // THEN: Should render in red. | ||
| await host.snapshot('local'); | ||
|
|
||
| const allInjectedStyles1 = document.head.querySelectorAll('style[data-testid="style"]'); | ||
|
|
||
| expect(allInjectedStyles1).toHaveLength(1); | ||
| expect(allInjectedStyles1[0]).toHaveProperty('textContent', styleElement.textContent); | ||
|
|
||
| await render({ styleElements: [styleElement, styleElement] }); | ||
|
|
||
| // THEN: Should render in red. | ||
| await host.snapshot('local'); | ||
|
|
||
| const allInjectedStyles2 = document.head.querySelectorAll('style[data-testid="style"]'); | ||
|
|
||
| expect(allInjectedStyles2).toHaveLength(1); | ||
| expect(allInjectedStyles2[0]).toHaveProperty('textContent', styleElement.textContent); | ||
|
|
||
| await render({ styleElements: [styleElement] }); | ||
|
|
||
| // THEN: Should render in red. | ||
| await host.snapshot('local'); | ||
|
|
||
| const allInjectedStyles3 = document.head.querySelectorAll('style[data-testid="style"]'); | ||
|
|
||
| expect(allInjectedStyles3).toHaveLength(1); | ||
| expect(allInjectedStyles3[0]).toHaveProperty('textContent', styleElement.textContent); | ||
|
|
||
| await render({ styleElements: [] }); | ||
|
|
||
| // THEN: Should render in white because all stylesheet should have been removed. | ||
| await host.snapshot('local'); | ||
|
|
||
| const allInjectedStyles4 = document.head.querySelectorAll('style[data-testid="style"]'); | ||
|
|
||
| expect(allInjectedStyles4).toHaveLength(0); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
File renamed without changes
File renamed without changes
File renamed without changes
|
compulim marked this conversation as resolved.
|
File renamed without changes
Oops, something went wrong.
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.