-
Notifications
You must be signed in to change notification settings - Fork 59
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
Problem with data from a component being sent to another #123
Comments
This works now :) Just make sure you update metal-incremental-dom to rc.42 and metal.js to rc.4. |
I still seem to be getting the issue. Not with that example though. Let me see if I can nail down another example and share it with you |
In our project we are seeing issues with the code below <a class="view-port">
// playable is a boolean
{playable &&
<div class="play-overlay">
// Icon has default state of size="large"
<Icon multiplier={3} name="play" />
</div>
}
</a>
<div class="controls">
<div class="viewer-control right" data-onclick={this.handleNext}>
<Icon display="secondary" multiplier={2} name="arrow-right-rod" size="small" />
</div>
<div class="viewer-control left" data-onclick={this.handlePrevious}>
<Icon display="secondary" multiplier={2} name="arrow-left-rod" size="small" />
</div>
</div>
{
display: 'secondary',
multiplier: 3,
name: 'play',
size: 'small',
} It seems to be somehow picking up the config of the other two This make sense? |
We talked offline about this, so I'll try to document the results of the conversation here. It's not very easy to figure out if a component instance can be reused or not after an update. By default, That means that in the example above Metal.js would have created two This can be fixed by giving more hints to Metal.js about how to reuse the components, through That said, this use case wouldn't have required extra information if implemented using React. That's because they use a different approach for reusing components. They also use the order in which they appear, but not the order inside the whole parent component, they take into account the order inside the parent element instead. Since the conditional When first solving this issue I studied React's approach and thought about changing Metal.js to follow it instead, but it would be a lot of work and I'm not entirely sure that it would be worth it. As I said, by using In the end I think we should take the opportunity that we now have more people using Metal.js to observe how often we need to use Let me know if anyone has any questions or suggestions about this! |
It seems like to be safe, as an application developer, you would probably always want to add a Unless it's obvious when you need it, which I guess would be when you have conditionally rendered sub-components? But even then, it seems somewhat error prone to me. |
It's safer to use As I said, React has this same problem, requiring you to use It's just impossible to guarantee 100% via jsx to which existing instance you're referring to. We can have logic to try to cover as many cases as possible, but without hints like Basically, React's logic reuses components less, since they limit reuse within a parent element, but that also causes them to lose internal state of components more often, due to not reusing them, which would happen less with Metal.js. I suspect that React's logic may be better in most common cases, but since I'm not sure I'd rather not change this right now, but wait and observe a little longer instead. |
That makes sense. I still think it will be a "gotcha" for newcomers to the framework, but since we know why now, its not an urgent thing for us. Update: I was talking with @bryceosterhaus, and I now realized I skimmed over your distinction between parent element and parent component. Either way, I think this will probably be a problem for developers. |
This example doesn't render the expected output when the button is first clicked. It will render 1 bar for the second element instead of just 1.
That's because some config data of the third component (which was the second one before the button was clicked) is being wrongly passed to it. Need to investigate and fix this.
The text was updated successfully, but these errors were encountered: