ui icon indicating copy to clipboard operation
ui copied to clipboard

Dynamic attributes lose their value when reused in a new tag

Open amieres opened this issue 7 years ago • 3 comments

I reproduced the error in Try.WebSharper:

http://try.websharper.com/snippet/user3359/0000HD

The dynamic attributes (style:color and disabled in this example) are lost when they are used in a different Button. They are still active, so if the input value changes they show correctly again.

Static attributes work correctly.

amieres avatar Nov 04 '17 01:11 amieres

Yes, that is indeed a known limitation of the current implementation of attributes. A simple workaround here would be to make your dynamic attributes functions, like this: https://try.websharper.com/snippet/0000HM

I do want to look into it and check if we can remove this limitation without any consequences on performance, because that would indeed be an improvement. At first glance, it would mean moving the Sync method here from IAttrNode to Attrs.Dyn, and changing all the classes that implement IAttrNode accordingly.

Tarmil avatar Nov 22 '17 16:11 Tarmil

That would be great if it could be solved.

Thanks for the workaround, one question: does it cause some memory leakage by creating new attributes every time the button is toggled or does GC take care of it?

amieres avatar Nov 22 '17 17:11 amieres

The GC does take care of it.

That being said, it is generally better to make as much of the layout as possible static, and make the dynamic content as localized as possible. Something like this: https://try.websharper.com/snippet/loic.denuziere/0000HO

Tarmil avatar Nov 22 '17 17:11 Tarmil