State is getting confused for multiple instances of the same component type #2995
Replies: 4 comments 5 replies
-
What's your component code look like? This so far only makes sense if your view state is managed outside of your component (a massive anti-pattern, by the way). |
Beta Was this translation helpful? Give feedback.
-
Is |
Beta Was this translation helpful? Give feedback.
-
Here is the gist of what I am doing (skipping the styling):
The problem is that clicking on the button in Alice displays the thank you in Bob. |
Beta Was this translation helpful? Give feedback.
-
I made the smallest change to your example just to get it to work in a code playground. And I can't reproduce the bug: But also there's a few things in your example that seem odd.
I don't know if that helps, but I think if you adapt your source accordingly your bug will probably disappear. |
Beta Was this translation helpful? Give feedback.
-
Suppose I have several different components with this basic structure:
where Feedback is displayed over the entire Container when the user is done interacting with the Body. (By using position: absolute and z-index:2)
In almost all cases, this works as expected. For example, the general case might be this:
This works. However, this doesn’t:
In other words, if I have two instances of the same component type, things break down. What happens? Feedback for ComponentType1-2 is displayed on top of ComponentType1-1.
Code-wise, Feedback is set as the results of a timer. Something like this:
But somehow, the state getting changed is for the wrong component.
Is there any reason why multiple instances of a Mithril component would get their states confused like this? And if so, is there a way to prevent this confusion?
Beta Was this translation helpful? Give feedback.
All reactions