ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
865 stars 124 forks source link

incorrect compilation when spreading inline objects with getters with computed property names #118

Closed otonashixav closed 2 years ago

otonashixav commented 2 years ago

When spreading an object with computed keys, the object is wrongly assumed to be static and transformed as such.

Reproduction

Expected

I ran into this code recently: https://playground.solidjs.com/?hash=-743945147&version=1.3.9; notice due to how mergeProps and Dynamic work, the textarea is recreated whenever props.value changes. There are a few areas where compilation is broken or could be better with regards to inline objects:

Bugs:

  1. Objects with computed properties should be wrapped in a thunk as otherwise reactivity from the computed property names is lost.; Minimal Reproduction: https://playground.solidjs.com/?hash=-1317144494&version=1.3.9

Possible improvements:

  1. Static properties should be wrapped in getters to avoid unnecessary subscriptions. The thunk can be removed if all the properties have static names and are wrapped in getters.; Minimal Reproduction: https://playground.solidjs.com/?hash=650658910&version=1.3.9
  2. Computed properties should be wrapped in getters to avoid unnecessary subscriptions.; Minimal Reproduction: https://playground.solidjs.com/?hash=-1262057988&version=1.3.9

This is obviously quite specific to spreading objects declared inline, since no transformations will be done to explicit mergeProps calls or when spreading objects declared elsewhere.