News for hackers. Stuff that matters.
Re:Solid.js feels like what I always wanted React to be by TekMol on Tuesday March 01, 2022 @01:27AM (#30510413)
What feels like complete insanity when it comes to React is that it needs compilation to work:

    render() {
        return <div>The count is: {this.state.count}</div>;
    }
This is not Javascript and it will need to be compiled into Javascript before it gets executed.

But you can do the same in Javascript:

    render() {
        return `<div>The count is: ${this.state.count}</div>`;
    }
Using regular Javascript makes my life a thousand times easier than having to go through a compiler to make things work in the browser.
Re:Solid.js feels like what I always wanted React to be by orenelbaum on Tuesday March 01, 2022 @02:12AM (#30510683)
This is another area where Solid has an advantage over React. With React you could use Hyperscript functions so the above JSX would be

React.createElement('div', null, `The count is: {this.state.count}`).

With Solid you get the choice, you could use JSX, Hyperscript functions or template literals like in your example. Solid does recommend using JSX because there are some tradeoffs to using template literals without compilation, but it still maintains almost all of its qualities AFAIK and in the big framework benchmark Solid with template literals is the fastest template literals implementation.

With Solid you don't even have to use any templating languages, you can take care of rendering yourself using the tools that the framework gives you. Solid at its core is more of a capable state management library similar to MobX but designed to be used as the only reactivity engine unlike MobX which is usually used on top of React.

Re:Solid.js feels like what I always wanted React to be by leonardopainter on Tuesday March 01, 2022 @06:20AM (#30512742)
Using template literals to represent html is a security issue. If the state comes from the user, they can add script tags into the html. People try to solve this with tagged templates, but then if you forget the tag, you have a security issue again. Lit checks for this, but the fact that it has to check means it is less secure than not using tagged templates. There are libraries on github for creating sql using tagged templates which have the same security issue. The problem is that if your function works with both tagged templates and plain strings, when you forget to add the tag, you will never know.
Re:Solid.js feels like what I always wanted React to be by TekMol on Tuesday March 01, 2022 @06:27AM (#30512805)

    If the state comes from the user, they
    can add script tags into the html
How is that different with React?

And how is it a problem? A rendering engine would set the html of some element to the html I think?

This ...

    document.body.innerHTML='<script>alert(1)</script>';
...does not execute the script.
Re:Solid.js feels like what I always wanted React to be by leonardopainter on Tuesday March 01, 2022 @06:32AM (#30512857)
Re:Solid.js feels like what I always wanted React to be by leonardopainter on Tuesday March 01, 2022 @06:43AM (#30512944)
In terms of the placeholders in JSX, no they are escaped.
Re:Solid.js feels like what I always wanted React to be by TekMol on Tuesday March 01, 2022 @06:41AM (#30512930)
True.

But the same issue with reacts way.

Re:Solid.js feels like what I always wanted React to be by yulaow on Tuesday March 01, 2022 @03:58AM (#30511463)
Doesn't that make an hard life for the linter that now has to decide which template string represents a (complete) element and which is just text/whatever? I prefer the first solution because it's much simpler to parse
Re:Solid.js feels like what I always wanted React to be by mst on Tuesday March 01, 2022 @02:07PM (#30518553)
You might find this interesting: https://github.com/developit/htm#readme