Preact: Recycling is broken with any type of user input elements

Created on 19 Dec 2016  路  4Comments  路  Source: preactjs/preact

_This issue was noticed in both Preact 6 & 7, i.e. not a regression in 7._

Recycling is broken with any type of user input elements (<select>, <input>, etc.): when element is recycled it persists all input data in it, i.e. selected item, inputed text, etc. So when such element is restored to back to the DOM it has all those values/data set.

Here is a reduced test case with <select> element (also happens with <input>): https://goo.gl/5il3be

Reproduction:

Click toggle to show <select>
Then select "Value 2"
Then click toggle again to hide <select>
Then click toggle again to show <select>

Expected: Value 1 selected
Result: Value 2 selected

Here is a React version which works as expected: https://codepen.io/anon/pen/LbMKON
Here is the same example with Inferno: https://jsfiddle.net/o01mvsyn/44/ It also works as expected

The Wreckoning bug

Most helpful comment

Yup, I'm thinking the cases where component recycling isn't handling things and instead element recycling is taking over are actually the exact cases that get messed up by element recycling, haha. Dug into the implications of removing the recycler on the diff algo last night and I think it's actually going to have almost no effect for most applications because this line is already handling the most common case.

All 4 comments

My suggestion here is to have at least an option to disable recycling completely or for individual components. @developit was thinking about removing recycling completely in Preact 8.

@developit So recycling is there in a first place to reduce nodes/memory allocation and have less GC work, right? How often that happens in normal diffing when only couple things change at a time?

I main problem with such recycling is that I detach whole sub tree with kind-of-popup elements and need it fresh intentionally since it mostly consists from form elements.

Yup, I'm thinking the cases where component recycling isn't handling things and instead element recycling is taking over are actually the exact cases that get messed up by element recycling, haha. Dug into the implications of removing the recycler on the diff algo last night and I think it's actually going to have almost no effect for most applications because this line is already handling the most common case.

Fixed in 8.

Was this page helpful?
0 / 5 - 0 ratings