Current React lifecycle methods problem #54
Description
I've been trying to "fix a bug" when using react-integration
with skatejs
components.
I found what is the problem but I'm not sure how to solve it properly. If anyone have any idea / feedback on this I will appreciate it.
You can see the issue here.
So, if you take a look at the console, that button is rendered once without / with missing values and a second time with all the needed properties.
That MAY cause some weird behaviour (in my case, my component flashes when it is instantiated with attributes that changes a default style applied previously).
If you don't use react-integration it won't happen. So digging a bit inside react-integration
I found that lifecycle methods in react don't work in sync with skate's or at least that is my assumption.
Trying to make this message not too long, the sequence I see is:
- Render
Initial render, that create a react component with onlystyle
prop. This is to avoid dynamically computed properties usingget
andset
-> - componentDidMount
-> - componentWillReceiveProps (called explicitly in
componentDidMount
) This callback adds all the attributes to the currentnode
, wherenode
is the result ofReactDOM.findDOMNode(this)
( see here ). That will trigger another render in skatejs, but not in the tests (look at the props tests if you are interested) because tests are not using skatejs components only native custom elements.
Naturally I will think of this sequence to be:
componentWillMount
(call componentWillReceiveProps
)
->
componentWillReceiveProps
Here it should set all props in the node
->
render
at this point everything should be in place
The problem is, you cannot access findDOMNode
in componentWillReceiveProps
to add all the properties, so this approach I guess is not possible.
Will be looking forward to any ideas / feedback / correction on any wrong information that I may have written.
Thanks!