-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
chore: move out Fela to a separate package #13602
Conversation
a635658
to
e703e01
Compare
import { CreateRenderer } from '@fluentui/styles'; | ||
import * as React from 'react'; | ||
|
||
export const RendererContext = React.createContext<CreateRenderer>(createFelaRenderer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to have only the context now without any additional custom hooks/providers.
const felaParam: RendererParam = { | ||
theme: { direction }, | ||
const rendererParam: RendererParam = { | ||
direction, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a unified RendererParam
it will be strange to pass theme.direction
.
@@ -41,7 +43,6 @@ const stylesCache = new WeakMap<ThemePrepared, Record<string, ICSSInJSStyle>>(); | |||
const resolveStyles = ( | |||
options: ResolveStylesOptions, | |||
resolvedVariables: ComponentVariablesObject, | |||
renderStylesInput?: (styles: ICSSInJSStyle) => string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was used only for tests actually, but as we already using renderRule
from options.renderer
I decided to remove it to simplify the logic.
export type RendererRenderRule = (rule: () => ICSSInJSStyle, param: RendererParam) => string; | ||
export type Renderer = Omit<FelaRenderer, 'renderRule'> & { | ||
renderRule: RendererRenderRule; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move out to @fluentui/styles
, not sure that it's a right place, but:
- it's definitely not a part of
react-bindings
- it should be available for both renderer packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise we can have a circular dependency:
@fluentui/react-northstar-emotion-renderer: error TS6202: Project references may not form a circular graph. Cycle detected: /mnt/work/1/s/packages/fluentui/react-northstar-emotion-renderer/tsconfig.json
@fluentui/react-northstar-emotion-renderer: /mnt/work/1/s/packages/fluentui/react-bindings/tsconfig.json
@fluentui/react-northstar-emotion-renderer: /mnt/work/1/s/packages/fluentui/react-northstar-fela-renderer/tsconfig.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theme?: ThemeInput; | ||
}; | ||
|
||
export type StylesContextValue<R = Renderer> = { | ||
export type StylesContextValue = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types were simplified as now we have a single Renderer
type.
e703e01
to
88ea366
Compare
@@ -1,6 +1,8 @@ | |||
import { ICSSInJSStyle } from '@fluentui/styles'; | |||
import * as CSS from 'csstype'; | |||
// @ts-ignore | |||
import { expandProperty } from 'inline-style-expand-shorthand'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package doesn't have typings :(
@@ -5,7 +5,7 @@ | |||
// | |||
|
|||
import { ICSSInJSStyle } from '@fluentui/styles'; | |||
// eslint-disable-next-line import/no-extraneous-dependencies | |||
// @ts-ignore | |||
import cssifyDeclaration from 'css-in-js-utils/lib/cssifyDeclaration'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No typings :(
"fela-plugin-placeholder-prefixer": "^10.6.1", | ||
"fela-plugin-rtl": "^10.6.1", | ||
"fela-utils": "^10.6.1", | ||
"inline-style-expand-shorthand": "^1.2.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These deps were moved to @fluentui/react-northstar-fela-renderer
88ea366
to
9b85309
Compare
9b85309
to
b4945d0
Compare
</Provider> | ||
); | ||
return null; | ||
// TODO: fix this feature |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable resolver feature is now broken and should be fixed separately.
* Caution! Infinite recursion is possible in case if style object has links to self in the props | ||
* tree. | ||
*/ | ||
const felaDisableAnimationsPlugin = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All plugins received a small refactor:
- were simplified where options are not required
- typings improved
Actually the main reason to do it: it's avoid fighting with typings.
propertyWithInvalidValue: 'rgba(', | ||
}; | ||
|
||
expect(sanitize(style, { skip: ['propertyWithInvalidValue'] })).toEqual(style); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature was removed to simplify the returned signature. Was never used anywhere.
packages/fluentui/react-northstar/src/utils/mergeProviderContexts.ts
Outdated
Show resolved
Hide resolved
Asset size changesUnable to find bundle size details for Baseline commit: eb0a36e Possible causes
Recommendations
|
75ccc1c
to
3c94456
Compare
packages/fluentui/react-northstar/test/specs/utils/felaRenderer-test.tsx
Outdated
Show resolved
Hide resolved
@@ -25,6 +25,9 @@ | |||
}, | |||
{ | |||
"path": "../react-component-ref" | |||
}, | |||
{ | |||
"path": "../react-northstar-fela-renderer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question - do we have/can we add any way to enforce project references to be up-to-date?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about it, but if there will be a missing reference it will throw.
packages/fluentui/react-northstar-fela-renderer/test/felaInvokeKeyframesPlugin-test.ts
Show resolved
Hide resolved
@@ -27,7 +12,7 @@ const felaFocusVisibleEnhancer = (renderer: Renderer) => { | |||
renderer._emitChange = (change: RendererChange) => { | |||
if (change.type === RULE_TYPE && change.selector.indexOf(':focus-visible') !== -1) { | |||
// Fela uses objects by references, it's safe to override properties | |||
change.pseudo = change.pseudo ? change.pseudo.replace(':focus-visible', ':focus') : undefined; | |||
change.pseudo = change.pseudo ? change.pseudo.replace(':focus-visible', ':focus') : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strict typings are better as it should be a string and will default to an empty string:
https://github.com/robinweser/fela/blob/97148419e7941dbd5867b35df6ac4de6c5ed3e55/packages/fela/src/createRenderer.js#L224
https://github.com/robinweser/fela/blob/97148419e7941dbd5867b35df6ac4de6c5ed3e55/packages/fela/src/createRenderer.js#L302-L309
...luentui/react-northstar/test/specs/utils/mergeProviderContexts/mergeProviderContexts-test.ts
Outdated
Show resolved
Hide resolved
…erContexts/mergeProviderContexts-test.ts Co-authored-by: Miroslav Stastny <mistastn@microsoft.com>
Pull request checklist
$ yarn change
Description of changes
BREAKING CHANGES
This PR changes design of
renderer
injection to Fluent UI Northstar. Therenderer
prop was removed fromProvider
component, now we acceptcreateRender
factory via a React context.Before
After
(!) There are no breaking changes if you never used the
renderer
prop onProvider
.Details ❔
The previous design with
renderer
was created before we started to support multiple documents and blocks us from introducing custom renderers. That's why we decided to go with a factory that will allow us to create renderers on demand.This PR also updates
Renderer
type and unifies its usage across Fluent Northstar code. This will allow us to introduce different renderers expect Fela.Out of scope ✂️
This PR will not remove the dependency from
react-fela
and itsThemeContext
which we are using everywhere. This thing should be tackled separately.