Skip to content
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

Merged
merged 13 commits into from
Jun 16, 2020
Merged

Conversation

layershifter
Copy link
Member

@layershifter layershifter commented Jun 15, 2020

Pull request checklist

  • Addresses an existing issue: Fixes #0000
  • Include a change request file using $ yarn change

Description of changes

BREAKING CHANGES

This PR changes design of renderer injection to Fluent UI Northstar. The renderer prop was removed from Provider component, now we accept createRender factory via a React context.

Before

<Provider renderer={renderer} />

After

<RendererContext.Provider value={() => renderer}>
  <Provider  />
</ProviderContext.Provider>

(!) There are no breaking changes if you never used the renderer prop on Provider.

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 its ThemeContext which we are using everywhere. This thing should be tackled separately.

import { CreateRenderer } from '@fluentui/styles';
import * as React from 'react';

export const RendererContext = React.createContext<CreateRenderer>(createFelaRenderer);
Copy link
Member Author

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,
Copy link
Member Author

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,
Copy link
Member Author

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;
};
Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Contributor

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 = {
Copy link
Member Author

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.

@@ -1,6 +1,8 @@
import { ICSSInJSStyle } from '@fluentui/styles';
import * as CSS from 'csstype';
// @ts-ignore
import { expandProperty } from 'inline-style-expand-shorthand';
Copy link
Member Author

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';
Copy link
Member Author

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",
Copy link
Member Author

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

</Provider>
);
return null;
// TODO: fix this feature
Copy link
Member Author

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 = (
Copy link
Member Author

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);
Copy link
Member Author

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.

@size-auditor
Copy link

size-auditor bot commented Jun 15, 2020

Asset size changes

⚠️ Insufficient baseline data to detect size changes

Unable to find bundle size details for Baseline commit: eb0a36e

Possible causes

  • The baseline build eb0a36e is broken
  • The Size Auditor run for the baseline build eb0a36e was not triggered

Recommendations

  • Please merge your branch for this Pull request with the latest master build and commit your changes once again

@layershifter layershifter force-pushed the chore/move-out-fela branch 4 times, most recently from 75ccc1c to 3c94456 Compare June 15, 2020 12:38
@@ -25,6 +25,9 @@
},
{
"path": "../react-component-ref"
},
{
"path": "../react-northstar-fela-renderer"
Copy link
Member

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?

Copy link
Member Author

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.

@@ -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') : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…erContexts/mergeProviderContexts-test.ts

Co-authored-by: Miroslav Stastny <mistastn@microsoft.com>
@layershifter layershifter merged commit d97ee4e into master Jun 16, 2020
@layershifter layershifter deleted the chore/move-out-fela branch June 16, 2020 10:50
@layershifter layershifter restored the chore/move-out-fela branch June 16, 2020 10:50
@layershifter layershifter deleted the chore/move-out-fela branch June 16, 2020 10:50
@layershifter layershifter mentioned this pull request Jun 23, 2020
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fluent UI react-northstar (v0) Work related to Fluent UI V0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants