Skip to content

Fixed issue for dynamic props update#28

Merged
lttb merged 5 commits intocssinjs:masterfrom
wellguimaraes:master
Jun 16, 2017
Merged

Fixed issue for dynamic props update#28
lttb merged 5 commits intocssinjs:masterfrom
wellguimaraes:master

Conversation

@wellguimaraes
Copy link
Copy Markdown
Contributor

@wellguimaraes wellguimaraes commented May 30, 2017

{
  color: props => props.active ? 'red' : 'black',

  // it was crashing by having this conditional rule here
  '@media screen': {
    background: props => props.active ? 'white' : 'gray'
  }
}

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling fb8cd97 on wellguimaraes:master into d3a578a on cssinjs:master.

@wellguimaraes wellguimaraes changed the title Fixed issue while updating dynamic props for conditional rules Fixed issue for dynamic props update May 30, 2017
Copy link
Copy Markdown
Member

@lttb lttb left a comment

Choose a reason for hiding this comment

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

@wellguimaraes, thank you for this fix, that's great!

Comment thread src/styled.js Outdated
if (rule.name)
this.sheet.update(rule.name, props)
else
this.sheet.update(props)
Copy link
Copy Markdown
Member

@lttb lttb May 31, 2017

Choose a reason for hiding this comment

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

The problem here is that in this case we update the whole StyleSheet, and it will reduce performance significantly. That's why we update by the name, otherwise we can replace all that code with just this.sheet.update :).
Another problem with such update is that we will rerender rules for other instances, that were not really updated.

But this solution should work:

if (rule.name) this.sheet.update(rule.name, props)
if (rule.rules) rule.rules.update(props)

Conditional rules has their own RulesContainer in rules, so with .update we should iterate only for needed rules.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@kof what do you think?

@lttb
Copy link
Copy Markdown
Member

lttb commented May 31, 2017

There are also some issues with codestyle.
That's strange that pre-commit linting dit not work 🤔

Anyway I'll setup linting by CI too

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 12601ea on wellguimaraes:master into f35db97 on cssinjs:master.

lttb
lttb previously approved these changes May 31, 2017
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 8bc484b on wellguimaraes:master into f35db97 on cssinjs:master.

Comment thread src/tests/functional.spec.jsx Outdated

const wrapper = mount(<Button spaced />)

expect(styled.mountSheet().toString()).toMatchSnapshot()
Copy link
Copy Markdown
Member

@lttb lttb May 31, 2017

Choose a reason for hiding this comment

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

we should use assertSheet here. but I checked that getCss returns empty media query rule for function values like:

.button-1-id{padding:10px;}@mediascreen{.button-1-id{}}

for static values it's ok.

need to understand why dynamic properties didn't render with values for conditional rules

Comment thread src/tests/functional.spec.jsx Outdated
wrapper.unmount()
})

it('should update all dynamic props', () => {
Copy link
Copy Markdown
Member

@lttb lttb May 31, 2017

Choose a reason for hiding this comment

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

I think it would be better to name this test like 'should update dynamic props for conditional rules'

@lttb
Copy link
Copy Markdown
Member

lttb commented May 31, 2017

@wellguimaraes please rebase your branch by origin, I've fixed Travis config and eslint checks

Comment thread src/tests/functional.spec.jsx Outdated

expect(styled.mountSheet().toString()).toMatchSnapshot()
wrapper.setProps({spaced: false})
expect(styled.mountSheet().toString()).toMatchSnapshot()
Copy link
Copy Markdown
Member

@lttb lttb May 31, 2017

Choose a reason for hiding this comment

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

let's save sheet in variable

@lttb
Copy link
Copy Markdown
Member

lttb commented May 31, 2017

@wellguimaraes It looks like it still does not work for me (with whole sheet update too)

https://codesandbox.io/s/lYL3Jz3l7

@lttb lttb dismissed their stale review May 31, 2017 11:30

need to understand issues with rendering of dynamic conditional rules

@lttb
Copy link
Copy Markdown
Member

lttb commented May 31, 2017

There is an issue w/ jss: cssinjs/jss#511

@cssinjs cssinjs deleted a comment from coveralls Jun 15, 2017
@coveralls
Copy link
Copy Markdown

coveralls commented Jun 15, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling d03282c on wellguimaraes:master into 084d92a on cssinjs:master.

@coveralls
Copy link
Copy Markdown

coveralls commented Jun 15, 2017

Coverage Status

Coverage remained the same at 100.0% when pulling 829864b on wellguimaraes:master into 084d92a on cssinjs:master.

@cssinjs cssinjs deleted a comment from coveralls Jun 15, 2017
@lttb lttb merged commit d2612e9 into cssinjs:master Jun 16, 2017
@lttb
Copy link
Copy Markdown
Member

lttb commented Jun 16, 2017

@wellguimaraes it looks like we have fix it, is it okay now?

it works here: https://codesandbox.io/s/M8o5p00rP

@wellguimaraes
Copy link
Copy Markdown
Contributor Author

awesome!

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