State is getting confused for multiple instances of the same component type #2995
Replies: 5 comments 6 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.
-
|
At some point I discovered that if you have an array of mithril components of the same type, Mithril apparently feels free to share state. Assigning a key to these components solves this problem. Apologies for not closing this earlier. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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