-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: don't force plain themes #1780
Conversation
src/models/ThemeProvider.js
Outdated
@@ -117,7 +114,7 @@ class ThemeProvider extends Component<ThemeProviderProps, void> { | |||
} | |||
return mergedTheme | |||
} | |||
if (!isPlainObject(theme)) { | |||
if (!isObject(theme)) { |
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.
Looks good. Could you add a test that simulates what webpack does to the best of your ability so we know it'll work?
@phyllisstein try merging from master - I turned off danger for the moment. Please do add a CHANGELOG entry though 😃 |
I think we should use this opportunity to get rid of such a small dependency that will likely never change. I think it’d make sense to check for:
Without taking on a small dependency. I’m not even sure if we still need this constraint even? |
Since this test just passed, I take it SC can pretty well handle non-plain objects: it('should [not] allow other complex objects to be passed as themes', () => {
class Theme {
constructor(borderRadius) {
this.borderRadius = borderRadius
}
}
const theme = new Theme('2px')
const Comp1 = styled.div`
border-radius: ${ ({ theme }) => theme.borderRadius };
`
const wrapper = mount(
<ThemeProvider theme={ theme }>
<Comp1 />
</ThemeProvider>
)
expectCSSMatches(`.sc-a {} .b {border-radius:${theme.borderRadius};}`)
}) I'd be happy to remove the check---and the dependency---altogether. If you want to keep it, though, |
If what we have already is enough, let's drop the dep. |
Consider it done! With a few extra tests to boot. |
@phyllisstein great! could you please merge from master to fix CI and add a changelog entry? |
With pleasure. Should be ready to go once tests pass. |
Looks like there were some Flow issues that I'll work on correcting, but also a problem with the bundle size check that I'm less sure how to resolve. |
Heh, Flow is doing its job and preventing you from making the mistakes! Since these tests are intentional, you can put a |
Thanks! With that added and a small bump to the maximum bundle size I think I'm set. |
@@ -180,7 +180,7 @@ | |||
"bundlesize": [ | |||
{ | |||
"path": "./dist/styled-components.min.js", | |||
"maxSize": "16kB" | |||
"maxSize": "16.5kB" |
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.
Hmm why'd we have to bump this? Aren't we using less code now?
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.
The check was failing pretty consistently, but I'm not sure where the extra code came from. I guess the typecheck @kitten suggested ((mergedTheme === null || Array.isArray(mergedTheme) || typeof mergedTheme !== 'object')
) is slightly longer than the original isPlainObject(mergedTheme)
, but I'm not sure if that would've been sufficient to break the test.
@@ -1,7 +1,6 @@ | |||
// @flow | |||
import React, { Component, type Element } from 'react' | |||
import PropTypes from 'prop-types' | |||
import isPlainObject from 'is-plain-object' |
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.
Can this dependency be removed entirely now?
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.
It's also used in utils/flatten.js
to determine whether to try flattening the object or to just call toString
on it. I think in that case it's still necessary that the object be "plain."
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.
Thank you!
Thank you so much for helping us improve styled-components! Based on our Community Guidelines every person that has a PR of any kind merged is offered an invitation to the styled-components organization—that is you right now! Should you accept, you'll get write access to the main repository. (and a fancy |
Neat-o! Thanks for all your help! |
is-plain-object
is still required as an additional dependency, in order to guarantee that objects within rulesets aretoString
ed.Fixes #1776.