Coder Social home page Coder Social logo

When using a "computed key" in classList, a following `class` declaration overwrites the classes set by `classList` about solid HOT 4 OPEN

danieltroger avatar danieltroger commented on June 15, 2024
When using a "computed key" in classList, a following `class` declaration overwrites the classes set by `classList`

from solid.

Comments (4)

ryansolid avatar ryansolid commented on June 15, 2024 1

Technically as far is it concerned class is reactive here because you are using props.class syntax. It can't know that it isn't. Reactive class means there is always potential for it to overwrite. We can't do inline optimizations on classList with computed keys currently. I suppose the compiler could be more optimized. But this is generally the problem with reactive class + classList and why there is intention to do something about classList in the future.

from solid.

danieltroger avatar danieltroger commented on June 15, 2024

Hmm, I thought the rules was that one can use classList and class together as long as only one is reactive.

We can't do inline optimizations on classList with computed keys currently.

But I didn't know about this :( Why is it not possible? I need computed keys to get dashes in the class lol.

If I was solid I'd tackle the problem by splitting class by (space) and then feeding the output into classList, what's wrong with that approach? Is it really so important to accurately reflect double spaces and other imperfections in the class attribute value? (Like class1 class2 instead of class1 class2)

Edit:

I need computed keys to get dashes in the class lol.

I'm obviously stupid, I can just do { "stuff-with-dashes": true }

from solid.

ryansolid avatar ryansolid commented on June 15, 2024

To be fair computed property compilation is probably possible if the computed property itself isn't dynamic (a signal or member expression). Also a literal could be eliminated too. These are all optimization edge cases. I just bailed out the optimization sooner because of sake of time and some complexity I hit.

That being said this behavior due to the way class + classList work in general is sort of by design. Poor design, perhaps but it is the way it works right now. I can't compile this problem away in the general sense and it is something that is known issue. Nothing to fix right now other than hope to change the design in the future.

from solid.

danieltroger avatar danieltroger commented on June 15, 2024

Nothing to fix right now other than hope to change the design in the future.

That's totally fair. Thanks for the information! But I still wonder about your reasoning regarding why not split class into classList in the JSX transformation output for now to fix all the bugs, at the expense of some performance?

from solid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.