Clean up <ThemeProvider> and various CSS related stuff#5611
Clean up <ThemeProvider> and various CSS related stuff#5611compulim merged 63 commits intomicrosoft:mainfrom
Conversation
|
While we're not on the path to implement Previous implementation was fairly easy to update to the pattern. How about this one? |
Agree, dev tools don't show the CSS is a huge obstacles for debugging. For 3P, all CSS injections will be done by Inside To support |
Changelog Entry
Added
<ThemeProvider>and various CSS related code, in PR #5611, by @compulimDescription
This is for paving the way to host a new experience working side-by-side with existing experience. We need CSS Modules to work with the new experience.
Also took some time to audit the usage of nonce and clean it up so it's easier to audit.
Design
New
<StyleOptionsComposer>Slowly refactoring things out of
<Composer>.<Composer>is still the root of everything (except<ThemeProvider>which could be parent of<Composer>.)All rectification logic is being refactored. We should slowly revisit it by using valibot to fill optional fields and for rectifications.
The current rectification logic does not take cascading into account. We need some modifications.
Hook vs component
useInjectStylesis replaced by<InjectStyleElements>for cleaner DOM related manipulation.<InjectStyleElements>is a leaf node component withoutchildrenprops<InjectStyleElements>will handle duplications, including handling same instance of<link rel="stylesheet">/<style>with and without nonceAs a result,
useCSSCustomProperties()is also becoming<CustomPropertiesContainer>.CSS injection order
Instead of saving all CSS injections into context, to save some logics, we are injecting CSS when the
<InjectStyleElements>is mounted. Ordering is important.Will be injected in the following order to honor CSS cascading:
Note:
stylesB1is afterstylesA2because it is deeper in the treestylesA1get moved afterstylesB1because of dedupe while keeping "deeper element is injected later"Also thought about using
createPortal()to inject DOM, but it is not available in React 16.8.6.Fixed bugs
<style>element twice, it should not mount it twiceSpecific Changes
<StyleOptionsComposer>out of<API.Composer><WebChatTheme>-><ComponentStylesheet>/<DecoratorStylesheet>createStyles->createComponentStyleElements/createDecoratorStyleElementsuseInjectStyleElements(styleElements)-><InjectStyleElements nonce={} styleElements={}>useCSSCustomProperties()-><CSSCustomPropertiesContainer>--watch 200esbuild --watch --watch-delay 200tsup.watch({ delay: 200 })CHANGELOG.mdI have updated documentationReview Checklist
Accessibility reviewed (tab order, content readability, alt text, color contrast)Browser and platform compatibilities reviewedCSS styles reviewed (minimal rules, noz-index)Documents reviewed (docs, samples, live demo)Internationalization reviewed (strings, unit formatting)package.jsonandpackage-lock.jsonreviewedSecurity reviewed (no data URIs, check for nonce leak)