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

[react-jss] Big Refactor #949

Merged
merged 39 commits into from
Jan 16, 2019
Merged

[react-jss] Big Refactor #949

merged 39 commits into from
Jan 16, 2019

Conversation

kof
Copy link
Member

@kof kof commented Dec 26, 2018

What would you like to add/fix?

Corresponding issue (if exists):

Henri added 4 commits December 11, 2018 15:15
* Update to new react context for the jss context

* Fixed types

* Fix some tests

* Remove unnecessary cloning

* Fix JssProvider

* Update logic of merging context

* Fix a few issues and tests

* Make getTheme non public

* Update warning inside JssProvider

* Remove duplicate beforeEach

* Update size-snapshot

* Fix a few bugs

* Created a Managers type

* Create sheetOptions prop type definition

* Removed meta property from sheet options shape

* Fix creating a new generateId for every render

* Move media into it's own prop

* Added changelog

* Rename to JssContextSubscriber

* Moved context to jssContext prop instead of spreading it
* Update to new react context for the jss context

* Fixed types

* Fix some tests

* Remove unnecessary cloning

* Fix JssProvider

* Update logic of merging context

* Fix a few issues and tests

* Make getTheme non public

* Update warning inside JssProvider

* Remove duplicate beforeEach

* Update size-snapshot

* Fix a few bugs

* Remove inject option

* Fix

* Always inject the theme

* Only inject theme when injectTheme is true
@HenriBeck HenriBeck changed the title React jss/update [react-jss] Big Refactor Dec 27, 2018
changelog.md Show resolved Hide resolved
docs/react-jss.md Show resolved Hide resolved
docs/react-jss.md Outdated Show resolved Hide resolved
docs/react-jss.md Show resolved Hide resolved
In case you need to access the theme but not render any CSS, you can also use `withTheme`. It is a Higher-order Component factory which takes a `React.Component` and maps the theme object from context to props. [Read more about `withTheme` in `theming`'s documentation.](https://github.com/iamstarkov/theming#withthemecomponent)
#### Accessing the theme inside the styled component

Pass the `injectTheme` option to `withStyles` so your theme will be injected into your wrapped component.
Copy link
Member Author

Choose a reason for hiding this comment

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

Arn't we injecting the theme anyways if styles is a function?

Copy link
Member

Choose a reason for hiding this comment

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

No only if injectTheme is true

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I got confused by the example, it shows the theme being injected in to styles function but doesn't show it in the react component which made me assume we need injectTheme to pass it to the styles function.

theme is getting passed to the styles function always! If no that would be evtl a problem.
theme is not getting passed with props to the user component by default, for this one needs injectTheme option, right? we need to make that difference clear in the docs if technically we are on the same page.

packages/react-jss/src/types.js Outdated Show resolved Hide resolved
theming?: Theming<Theme>,
inject?: Array<'classes' | 'themes' | 'sheet'>,
injectTheme?: boolean,
jss?: Jss
} & StyleSheetFactoryOptions
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to use spread operator instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I use spread currently most of the time, btw they do exactly the same thing, right?

Copy link
Member

Choose a reason for hiding this comment

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

Not quite. Disjunction has own use cases. Not sure how it work in this case. For example before 0.90 we may get non-nullable shape via $Shape<T> | {}.

packages/react-jss/src/withStyles.js Show resolved Hide resolved
@@ -0,0 +1,259 @@
// @flow
import React, {Component, type ComponentType, type Node} from 'react'
Copy link
Member

Choose a reason for hiding this comment

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

I personally prefer import * as React from 'react';. This is obvious end of react transition to esm. However we will be able to achieve this only in react v19 in the best way.

Copy link
Member Author

@kof kof Jan 13, 2019

Choose a reason for hiding this comment

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

Why? Is it just taste? I prefer to always use specific named imports instead of an object that has everything. Shouldn't this get us some optimizations once react has esm bundle?

Copy link
Member

Choose a reason for hiding this comment

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

Nope. Rollup expands namespaces with usages, so in the end you see the same expanded set of named imports.
With default export you get a bloat with whole react api object.
And named exports are more natural in context of react stuff. Default exports is again a legacy of cjs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you make an example please? I didn't get it.

Copy link
Member

Choose a reason for hiding this comment

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

import * as React from 'react';

React.Component;
React.createContext;

is expanded into

import {Component, createContext} from 'react';

Component;
createContext;

This is super nice optimisation feature of rollup. Webpack don't do this and instead duplicates React.createElement everywhere which increase bundle size a lot. Guys invents babel/webpack plugins for this.

For me it's just absurd. Webpack makes me said last months. It has fast enough development mode but production is far from perfect.

Copy link
Member

Choose a reason for hiding this comment

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

I personally don't use default export. But I ask only to stop import react as default to reduce bundle size and simplify future transition.

Copy link
Member Author

Choose a reason for hiding this comment

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

What exactly is the impact in bundle size when default export is used?

Copy link
Member

Choose a reason for hiding this comment

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

React.default.createElement instead of just createElement for example. Doesn't solve the problem for webpack though.

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 size is not going away with uglify?

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps something like unsafeGetters option will help. Or may broke something.

packages/react-jss/package.json Outdated Show resolved Hide resolved
@kof kof merged commit 56e451e into master Jan 16, 2019
@HenriBeck HenriBeck deleted the react-jss/update branch January 16, 2019 20:27
bhupinderbola pushed a commit to bhupinderbola/jss that referenced this pull request Sep 17, 2019
* [WIP] Update to new react context for the jss context (cssinjs#924)

* Update to new react context for the jss context

* Fixed types

* Fix some tests

* Remove unnecessary cloning

* Fix JssProvider

* Update logic of merging context

* Fix a few issues and tests

* Make getTheme non public

* Update warning inside JssProvider

* Remove duplicate beforeEach

* Update size-snapshot

* Fix a few bugs

* Created a Managers type

* Create sheetOptions prop type definition

* Removed meta property from sheet options shape

* Fix creating a new generateId for every render

* Move media into it's own prop

* Added changelog

* Rename to JssContextSubscriber

* Moved context to jssContext prop instead of spreading it

* [react-jss] Remove inject option (cssinjs#934)

* Update to new react context for the jss context

* Fixed types

* Fix some tests

* Remove unnecessary cloning

* Fix JssProvider

* Update logic of merging context

* Fix a few issues and tests

* Make getTheme non public

* Update warning inside JssProvider

* Remove duplicate beforeEach

* Update size-snapshot

* Fix a few bugs

* Remove inject option

* Fix

* Always inject the theme

* Only inject theme when injectTheme is true

* Upgrade theming package (cssinjs#942)

* Add forwardRef support (cssinjs#943)

* [react-jss] Merge classes instead of overwriting (cssinjs#946)

* Add forwardRef support

* Add support for merging the classes

* Fix path of test file

* Remove jsdoc comment

* Implement custom memoize-one

* Convert function to arrow function

* Fix

* Update some of the tests

* Update dynamic styles tests

* Fix SSR tests

* Add theme inject tests

* Add merge classes tests

* Remove dependency of react-dom

* Fix an issue with memoizing and memoize the context

* Remove createHoC file and remove injectSheet to withStyles

* Update TS types

* Update TS types

* Fix flow types

* Fix react-jss types

* Rename injectSheet to withStyles in docs

* Fix react-jss types

* Update changelog.md

* Rename class and

* Fix tests

* Fix a few typos in docs

* Fix changelog

* Use javascript for codeblocks instead of js

* Upgrade theming

* Fix type import

* Update size-snapshot

* Fix docs

* Update size-snapshot

* Upgrade theming to v3.0.2

* Use travis_wait for test command

* Remove travis_wait command

* Update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants