MithrilJS / mithril.js

A JavaScript Framework for Building Brilliant Applications
https://mithril.js.org
MIT License
14.02k stars 925 forks source link

Error handling: Duplicated components after an error is thrown in a view #2645

Open raykyri opened 3 years ago

raykyri commented 3 years ago

This is somewhat a duplicate of #2273, but I also haven't seen it mentioned in the thread or anywhere else (or maybe I missed it):

When an error is thrown in a view in Mithril, the diffing engine will often get confused and start rendering multiple copies of the same component to the page.

This seems unexpected, and I haven't seen it mentioned anywhere else. Am I doing something wrong?

osban commented 3 years ago

@raykyri not sure why you'd get an error thrown in a view, but maybe you could post some simplified code (ideally in a flems, possibly reproducing the error)?

lucastorri commented 3 years ago

Hi All!

I believe I have an example. It is quite non-sensical, but we had something similar in real code:

https://flems.io/#0=N4IgZglgNgpgziAXAbVAOwIYFsZJAOgAsAXLKEAGhAGMB7NYmBvAHgBMIA3AAgjYF4AOiAwAHUcID0APkog4MWNWIR6CRCAAMiAIwBWEAF8K6bLg34AVgip0GTYnm7OXzu3GLdOGKAFd43PzcyJr4AEwU3KEAnJGhepEAchiJALoA3IJorq7eAE5ePv6BhX7wIRlZOS753HS+DCWamdnV3FVt7p4AguIlwB1tXhAwAO6I3AAUAJSB0twDrUPOeTDEvnnZWJODy87CHJzCFLt726d77fKKMMrHF3uLl2301IQYaADmMBOTMLP8eaTbxlEowfDEDB5b7EfAg-zTE5LZ7cYwPZbw+D4LBiSbAgHzc4gWiiFT0Y5eabTdHVRE0nLnZHPYS+KD3JmXTFwbG4-FzBb0oYQMBTeoMADU4u48wAzNwAGTy3hwZKJfHUjko7irdabbiMrVDYRQCDsw1tImiPK0T6rOBwCnAfUYAAeEx0mk0kUxEx4ACpuB7NKjvRrza5pi1w9xFAptWsNtkdFHDYYwyj03tI-S0ZrUS0sl1tbRaJ4gmxaNRfDgGPgYQBRWA14gAIQAngBJNg7ETiYTZtBYbG0BrESbW0uRXqiAdyBRKMlodQgGWIAAcRhMIEwODw+Go9rkdkYzA0RlSVBNaAA1upUNuzHgsBBiIQ8tA5BtyBoSMRRHBEEkSQGlEa9Pn3WgsEkZ9X3fKAAAEwnwUIABZoJfN9oGxCA0CsGwQGINtRHMeRqHfUlz0MIA

If you change the option in the select a few times, you'll see that new items in the list are being added and the old ones are not removed. The stack trace is not helpful, because it happens inside mithril and not in the user's code.

Thank you!

ArthurClemens commented 3 years ago

It seems to me that the issue is that key is missing in the li items.