Live data from Hacker News

HTML Web Components

blog.jim-nielsen.com

71–80 of 247 posts

Re: HTML Web Components

#71

> But the unique power of web components (in the browser) is that they can render before JavaScript. React components cannot do this — full stop. Unless you... server-side render them. Then your definition of "render" needs to change

At least you can server render web comppnents.

You actually can't yet do that reliably. Declarative Shadow DOM is not yet supported by Firefox. https://caniuse.com/declarative-shadow-dom

Re: HTML Web Components

#72

React Component is a function. HTML web component is NOT a function. You don't just compare those things, they work and compose differently. I would rather combine them: A html web component renderer for React.

So when react components were classes they were comparable, but now that react components are functions they are not?

Re: HTML Web Components

#73
post #32

Earlier quoted context omitted.

I think there's a lot of value for classic server-side web applications rather than SPAs. That handles routing, state, etc. I'm personally a fan and hope that the server-based application renaissance happens as some predict.

Most people using react aren't building SPAs. Vue/React can be used the same way as jquery, which is to add enhanced UI functionality that server-side HTML views simply can't offer. The best example is a multi-select box, or a searchable select box with autocomplete (what W3 calls the combobox pattern https://www.w3.org/WAI/ARIA/apg/patterns/combobox/ ) which in jquery was usually via https://select2.org/ For example…

> Most people using react aren't building SPAs

> People still abuse React/Vue of course and the trend is 100% moving back to "mostly static" rather than slow SPAs

I'm not seeing this at all, in fact I can't remember the last React project I worked on that wasn't a full blown SPA. I don't see anyone starting or advocating for static sites with islands unless they're using a framework like Astro or something.

Do you have any example sites or codebases using this approach?

Re: HTML Web Components

#74

I'm not sure I buy the "React is replacement, not augmentation" argument. At the end of the day/render, React still renders HTML elements... with javascript event handlers. Wrapping an ' ' in a React component doesn't mean I've taken away any functionality of 'img'. I just add to it -- augmentation. Maybe the author has worked in different React codebases than I have, but in my experience, we use built-in browser fun…

In some cases, react seems to go out of its way to make the built-in functionality harder to access. For instance, if you assign "onchange" to an , react will give you the "input" event, not the "change" event. (Actually, it gives a neither. It gives you a "synthetic" event that's closer to input than change) What if you know what you're doing, and you actually wanted "change"? You have to use an element ref an attac…

You can access the `nativeEvent` property on the event object[0] if you prefer

[0]: https://react.dev/reference/react-dom/components/common#reac...

Re: HTML Web Components

#75

> But the unique power of web components (in the browser) is that they can render before JavaScript. React components cannot do this — full stop. Unless you... server-side render them. Then your definition of "render" needs to change

Sorta-- that means you render it at least twice. 1. You convert the JavaScript/JSX into HTML on the server and send it down (along with multiple blobs of JSON/code to re-hydrate). 2. The browser parses all the HTML and added JSON/code. 3. The browser then re-hydrates the page via JavaScript loading all of the JSON/code and computing everything (rendering it again).

>The browser then re-hydrates the page via JavaScript loading all of the JSON/code and computing everything (rendering it again).

isn't this exactly what's going on under the hood with web components? if you send an html page including , the browser is going to draw the tag and treat the tag as a no-op because it doesn't know what to do with that. then your javascript kicks in and transforms the tag into whatever the javascript defines it as, at which point it will get re-rendered.

Re: HTML Web Components

#77

I'm not sure I buy the "React is replacement, not augmentation" argument. At the end of the day/render, React still renders HTML elements... with javascript event handlers. Wrapping an ' ' in a React component doesn't mean I've taken away any functionality of 'img'. I just add to it -- augmentation. Maybe the author has worked in different React codebases than I have, but in my experience, we use built-in browser fun…

When I read that I thought about the reverse: putting React inside other HTML. In my experience React works wonderfully when you’re using it from top to bottom (replacing your entire page structure) but it can be difficult to fit into an existing structure when you’re trying to do things like server side rendering.

Re: HTML Web Components

#78

I was interested to see this article explain what `user-avatar` actually did/provided but it never did. Does it just have styles in it? If so why wouldn't I just use css classes? I also think having a `user-avatar` take a `src` prop makes way more sense than having to add an `img` tag inside it everywhere I use it. In that case what am I saving? What is reusable? Vue/React/Angular don't seem like they are trying to "…

>"with no "Batteries included" and feel like they don't really help you build web _apps_ like the frameworks do."

Define _app_. React doesn't have batteries, it has composability. Web Components do too but you have to know how (it's a lot easier in React, just return (html)) but in Web Components, you can register your custom element and provide the functionality that you call "batteries". [1] So if you don't care about attributes and just want semantic composable things, just call it whatever you want to. . Conceptually it's a web component that extends HTMLDivElement.

[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_compone...

Re: HTML Web Components

#79

I'm not sure I buy the "React is replacement, not augmentation" argument. At the end of the day/render, React still renders HTML elements... with javascript event handlers. Wrapping an ' ' in a React component doesn't mean I've taken away any functionality of 'img'. I just add to it -- augmentation. Maybe the author has worked in different React codebases than I have, but in my experience, we use built-in browser fun…

In some cases, react seems to go out of its way to make the built-in functionality harder to access. For instance, if you assign "onchange" to an , react will give you the "input" event, not the "change" event. (Actually, it gives a neither. It gives you a "synthetic" event that's closer to input than change) What if you know what you're doing, and you actually wanted "change"? You have to use an element ref an attac…

it's a well known thing in react (preact does it well https://preactjs.com/guide/v10/differences-to-react/#use-oni...), and probaly a design mistake on their side (now too late to change), I can't think of other cases like that

Re: HTML Web Components

#80
post #32

Earlier quoted context omitted.

I think there's a lot of value for classic server-side web applications rather than SPAs. That handles routing, state, etc. I'm personally a fan and hope that the server-based application renaissance happens as some predict.

Most people using react aren't building SPAs. Vue/React can be used the same way as jquery, which is to add enhanced UI functionality that server-side HTML views simply can't offer. The best example is a multi-select box, or a searchable select box with autocomplete (what W3 calls the combobox pattern https://www.w3.org/WAI/ARIA/apg/patterns/combobox/ ) which in jquery was usually via https://select2.org/ For example…

Not elegant but we use a websocket for search in htmx.
Post reply on HN