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

data binding issue with array #88

Closed
aaronpankratz opened this issue Jul 31, 2018 · 9 comments
Closed

data binding issue with array #88

aaronpankratz opened this issue Jul 31, 2018 · 9 comments

Comments

@aaronpankratz
Copy link

Hi,
I have a list defined in an angular directive with a react component embedded using react2angular. When I update the list, the data binding doesn't seem to propagate down to the react component. Any ideas?

https://react2angular-binding-issue-ey652s.stackblitz.io

@aaronpankratz aaronpankratz changed the title possible data binding issue data binding issue with array Jul 31, 2018
@aaronpankratz
Copy link
Author

Looks like changing the array itself updates the react component but changing the contents of the array does not.

@ajdaniel
Copy link

ajdaniel commented Aug 8, 2018

This is because of the React Component's implementation of prop change detection. If you pass in a react PureComponent, or do not implement a suitable shouldComponentUpdate then react will only re-render when the prop reference changes. You should take a look at the React docs for change detection and PureComponent here: https://reactjs.org/docs/react-api.html#reactpurecomponent.

In summary. The issue lies with your component, not react2angular and your React component needs to react to deep prop changes.

@aaronpankratz
Copy link
Author

Thank you for the explanation and reference documentation! Makes sense.

@everdimension
Copy link

@ajdaniel As far as I can see, the component in question doesn't implement neither PureComponent, nor shouldComponentUpdate

Therefore it's not the react component that prevents rerendering

It seems that the angular component doesn't trigger a rerender for some reason.

@everdimension
Copy link

After looking at the source code, I believe the problem lies here: https://github.com/coatue-oss/ngcomponent/blob/master/index.ts#L42

So basically the ngcomponent lib that react2angular uses implement something similar to a PureComponent. And this conflict with the react paradigm where we just rerender everything without comparing props by default.

@ajdaniel
Copy link

ajdaniel commented Oct 23, 2018

@everdimension well spotted. Yes, this is a replica of PureComponent which means it is only checking if the prop value has changed. This means for example: if a prop is an array, and an item is pushed to that array, the component will not re-render.

I think react2angular should probably not have an opinion on this, as the user should create their own implementation of shouldComponentUpdate() and have total control.

@everdimension
Copy link

everdimension commented Oct 23, 2018

@ajdaniel

I think react2angular should probably not have an opinion on this

I agree, but currently it does. Which is a problem.
react2angular should not block rerendering by making a shallow comparison.

But at the moment, it seems to be impossible to make a component update after pushing an element to the array because the inner logic of ngcomponent will block rerender.

@ajdaniel
Copy link

@everdimension as this issue is now closed, can you please raise a new issue detailing this information, and stating that we should address this. The solution is yet unknown, but we should track this in a new issue. Thank you.

@everdimension
Copy link

Ok, sure!

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

No branches or pull requests

3 participants