← Back to context

Comment by mg

15 hours ago

> If you interpolate it, you have to escape manually

Well, for some definition of "manually".

If you have untrusted variables to interpolate, you can do

    this.innerHTML = html`Hello ${name}!`

Where html is a function that escapes the variables.

The arguments brought forward against web components all seem to fall under "But it does not contain every functionality you want to use out of the box". Personally, I don't think browsers should provide more and more functionality, but rather a good base to build upon.

The reason react sites are bloated is because there are a lot of things that are easy to do once you have better DX, there is nothing stopping you from making completely static sites with no js (solid-js 2.0 has a whole "htmx-like" mode that lets you have good interactivity even with js disabled).

WebComponents are useful for cases where you want something slightly more integrated than an iframe or want to make a library of small widgets

Oh great, so where does DOM provide that function?

  • The great thing with software is you can write your own functions. It would look something like this:

        function html(strings, ...values) {
          let result = strings[0];
          for (let i = 0; i < values.length; i++) {
            result += escapeHtml(values[i]);
            result += strings[i + 1];
          }
          return result;
        }