completefrontend
Open lab My progress
THE WEB COMPONENTS FIELD GUIDE

A preview of web components in frameworks and on servers

Use web components in React, Vue, Angular, and Svelte, and in server HTML. See how React 19 sets properties and how declarative shadow DOM needs no JavaScript.

By the end, you can
  • 01
    Use one tag in any frameworkPass data to a custom element and hear its events in React 19, and say what Vue, Angular, and Svelte need.
  • 02
    Send components from a serverExplain how tags in server HTML come to life when their script loads, and how declarative shadow DOM shows a component first.
  • 03
    Plan for no JavaScriptPut real content inside a tag, so the page still works when the script is slow or never arrives.

Can you use web components in any framework?

Ravi's star rating is a hit at Leaf and Kettle. He built it in lesson 1.3, as one tag: <tea-rating>. Now everyone wants it. Asha's online shop is built with React. The staff page uses Vue. Two partner cafés use Angular and Svelte. And the menu page comes from the shop's server, as finished HTML.

So Ravi has two questions. Will one tag work in all four frameworks? And on the menu page, what does a customer see before the rating's script arrives?

Yes, one tag works everywhere. A web component is an HTML element, so React, Vue, Angular, and Svelte can all put it on a page, pass it data, and listen for its events. A server can send it too. The browser shows what is inside the tag at once, and upgrades the tag when its script loads.

How can one tag fit so many tools? Each framework does three jobs with an element. Here they are, done by hand:

Three jobs, done by handPop out in the code editor (opens in a new tab)HTML
<p>No rating yet.</p> <script src="tea-rating.js"></script><script>  const rating = document.createElement("tea-rating");  rating.setAttribute("value", "4");  rating.addEventListener("rating-change", (event) => {    document.querySelector("p").textContent = `You gave it ${event.detail} stars.`;  });  document.body.prepend(rating);</script>
ResultLoading…
  • Line 1 is a paragraph for the result.
  • Line 3 loads tea-rating.js, the rating's file from lesson 1.3. It defines the tag.
  • Line 5 makes a new <tea-rating> element. That starts job one.
  • Line 6 passes data in: the value attribute, set to 4. That's job two.
  • Lines 7 to 9 listen for the rating-change event. When it comes, line 8 writes the number into the paragraph. That's job three.
  • Line 10 puts the rating at the top of the page. Job one is done.

The result shows five stars, four of them filled. Click the fifth star. The paragraph says You gave it 5 stars.

Three jobs any framework does with a tag. One: createElement makes a tea-rating for the page. Two: setAttribute value 4 passes data in, and four of five stars fill. Three: addEventListener hears the rating-change event coming back.1. put it on the pagecreateElement()<tea-rating>2. pass data insetAttribute("value", "4")★★★★☆3. listen for its eventsaddEventListener()rating-change
The example above does each job by hand. React, Vue, Angular, and Svelte each do the same three jobs for you, in their own way.

Every framework that builds HTML does these three jobs. Each has its own way to write them. React writes value={stars}, and Vue writes :value="stars". In the end, both set the same attribute on the same element. Why it matters: a tag that handles these three jobs works in all of them.

Real-life analogyA travel adapter that fits every socket

Asha visits three countries. Each one has a different wall socket. She packs her kettle and one travel adapter. The adapter fits every socket, so the same kettle makes tea in every hotel.

In real life: Asha's kettle
In JavaScript: The rating's code, in tea-rating.js
In real life: The adapter's standard pins
In JavaScript: An HTML element: attributes, properties, and events
In real life: Sockets in different countries
In JavaScript: React, Vue, Angular, Svelte, and plain HTML
In real life: Plugging in at each hotel
In JavaScript: Each framework doing its three jobs with the tag
The main idea

A web component is an HTML element, so any framework can use it. The framework puts it on the page, passes data in as attributes or properties, and listens for its events. A server can send it as plain HTML, and the browser upgrades it when its script loads.

This is the last lesson of stage 1, and a preview. It shows each idea once, with a small example. Stages 9 and 10 go deeper, and a section below maps them.

How do you use web components in React?

Start with Asha's shop. Lesson 1.3 already put the rating in a React component. React 19 set value as an attribute. It heard rating-change through onrating-change: on, then the event's exact name. Numbers and text are easy. But what about a whole tea, as an object?

An attribute only holds text, as lesson 2.2 showed. An object has to go in a property. So here is a small tea card with one property, tea:

tea-card.js, a card with a tea propertyJavaScript
class TeaCard extends HTMLElement {
  set tea(value) {
    this.textContent = `${value.name}: brew for ${value.minutes} minutes`;
  }
}

customElements.define("tea-card", TeaCard);
  • Line 2 is a setter: a function that runs when code writes card.tea = …. It gets the new value.
  • Line 3 writes the tea's name and brewing time into the card.
  • Line 7 defines the tag.

Now the React side. It passes a tea object to the card:

An object for the tea card, in ReactPop out in the code editor (opens in a new tab)JSX
import "./tea-card.js"; export default function Menu() {  const tea = { name: "Green tea", minutes: 3 };  return (    <section>      <h2>Today's tea</h2>      <tea-card tea={tea} />    </section>  );}
ResultLoading…
  • Line 1 imports tea-card.js. That runs its define() line before React draws anything.
  • Line 4 makes a tea object, with a name and the minutes.
  • Line 8 passes the whole object to the card.

The result shows Green tea: brew for 3 minutes. The object arrived whole. How did React know to use a property? Before it sets a prop, React 19 asks the element one question. Do you have a property with this name? In JavaScript, that's "tea" in card. If the answer is yes, React sets the property. If not, it sets an attribute. The React team's post on React 19 gives this rule.

How React 19 passes tea to a custom element. React asks whether "tea" is in the card. Yes: it sets the property, card.tea = tea, and the setter runs. No: it sets the attribute tea="[object Object]", and the card stays empty.tea={tea}"tea" in cardyescard.tea = teathe setter runsnotea="[object Object]"the card stays empty
React checks the element when it sets the prop. A defined tea-card has a tea property. A tag that is still waiting for its file has none.

The answer depends on timing. A tag only has its class's properties once it's defined. Switch line 1 off, and watch:

Playground: load the card's file first, or not
An object for the tea card, in ReactPop out in the code editor (opens in a new tab)JSX
import "./tea-card.js"; export default function Menu() {  const tea = { name: "Green tea", minutes: 3 };  return (    <section>      <h2>Today's tea</h2>      <tea-card tea={tea} />    </section>  );}
ResultLoading…
Try it yourself
React sets the tea property, and the card shows Green tea: brew for 3 minutes

Line 1 runs tea-card.js before React draws anything. So the tag is defined, and it has a tea property. React checks for it, finds it, and sets the property. The object arrives whole, and the setter writes the text.

Only line 1 changes. The card's class is in the tea-card.js tab. Pop the result out and inspect the card in DevTools to see its tea attribute, or its missing one.

With the file not loaded, the card is empty. React found no tea property, so it wrote an attribute. Pop the result out and inspect the card in DevTools. It has tea="[object Object]": the object, squashed into text. Why it matters: when you pass objects, load the component's file before React renders it.

Real-life analogyA courier checks for a parcel box

A courier brings a parcel to a house. First, she checks the door for a parcel box. If there is one, the parcel goes in whole. If there isn't, she can only push a note through the letterbox: "A parcel came." The note is not the parcel.

In real life: The courier
In JavaScript: React
In real life: The parcel
In JavaScript: The tea object
In real life: Checking the door for a parcel box
In JavaScript: "tea" in card
In real life: The parcel box
In JavaScript: A tea property, from the defined class
In real life: A note through the letterbox
In JavaScript: An attribute: text only, like [object Object]

Older React didn't ask. The React team's post says custom elements were hard to use before React 19, because React treated these props as attributes. React 19 changed that. It passes every test on Custom Elements Everywhere, a site that tests how frameworks treat custom elements. Lesson 25.1 in stage 10 covers older React too.

How do you use web components in Vue, Angular, and Svelte?

The staff page uses Vue, and the partner cafés use Angular and Svelte. Each one does the same three jobs, in its own syntax. Pick a framework to see the review from lesson 1.3 in it:

Playground: one rating, three more frameworks
The review in Vue, TeaReview.vueVue
<script setup>
import { ref } from "vue";
import "./tea-rating.js";

const stars = ref(4);
</script>

<template>
  <tea-rating :value="stars" @rating-change="stars = $event.detail"></tea-rating>
  <p>Vue has {{ stars }} stars.</p>
</template>
Try it yourself
Vue checks for a property, then falls back to the attribute

Line 3 loads the rating's file. Line 5 keeps the number in a ref, a box Vue watches. On line 9, :value passes the number in. Vue looks for a value property on the element, finds none, and sets the attribute. @rating-change listens for the event, and $event is the event itself.

Each version loads the same tea-rating.js and keeps the number of stars in its own state. Only the way the template talks to the tag changes.

Each version loads tea-rating.js, passes 4 in, and listens for rating-change. Svelte needs nothing more. Vue and Angular need one setting.

Telling Vue and Angular which tags are custom elements

Vue and Angular check each tag that isn't plain HTML against their own components. tea-rating isn't one of them. Vue still renders it as a custom element. But in development, it warns Failed to resolve component: tea-rating. The fix is a build setting, isCustomElement. It tells Vue's compiler which tags to leave to the browser:

Tell Vue which tags are custom elements, in vite.config.jsJavaScript
import vue from "@vitejs/plugin-vue";

export default {
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => tag.startsWith("tea-"),
        },
      },
    }),
  ],
};
  • Line 1 loads Vue's plugin for Vite, the build tool.
  • Line 8 is the setting. Vue calls it with each tag's name. It returns true for tags that start with tea-, so Vue leaves those to the browser.

Angular is stricter. Without a setting, the build stops with 'tea-rating' is not a known element. The Angular version above fixes it on line 6, with schemas: [CUSTOM_ELEMENTS_SCHEMA]. That schema allows tags and properties with a hyphen that aren't Angular components. It doesn't load anything. The import on line 2 still does that.

Real-life analogyA front desk with a guest list

A hotel's front desk checks every visitor against its staff list. A stranger gets stopped and asked who they are. So the manager leaves a note at the desk: "Guests whose names start with tea- are expected. Let them through."

In real life: The front desk
In JavaScript: Vue's or Angular's compiler
In real life: The staff list
In JavaScript: The framework's own components
In real life: Stopping a stranger
In JavaScript: Angular's build error, or Vue's warning
In real life: The manager's note
In JavaScript: isCustomElement or CUSTOM_ELEMENTS_SCHEMA

How data goes in

Data goes in a little differently in each framework. Read each row across: one framework, then how data goes in, how you listen, and what to set up.

How each framework talks to a custom element
FrameworkHow data goes inHow you listen for an eventSetup
React 19A property when the element has one. Otherwise, an attribute.onrating-change={…}: on, then the event's exact name.None. Load the tag's file before React renders it.
Vue 3A property when the element has one. Otherwise, an attribute. .prop forces a property.@rating-change="…".isCustomElement in the build settings stops a warning.
AngularA property, always. [attr.value] sets an attribute instead.(rating-change)="…".schemas: [CUSTOM_ELEMENTS_SCHEMA], or the build fails.
Svelte 5A property when the element has a setter. Otherwise, an attribute. Before the tag is defined, objects still go in as properties.onrating-change={…}: on, then the event's name.None.

Angular is the odd one out. Its square brackets always set a property, as its binding guide says. tea-rating has no value property, so the Angular version uses [attr.value] to set the attribute. Why it matters: in Angular, check the component's docs to see whether a setting is a property or an attribute.

Vue can force the other choice. Angular's attr. forces an attribute, and Vue's .prop modifier forces a property. Vue's guide suggests it for an element where the in check finds nothing, but the data must still go in a property:

Force a property in Vue with .propVue
<tea-card :tea.prop="tea"></tea-card>
<tea-card .tea="tea"></tea-card>

Line 1 sets the card's tea property, whatever the check says. Line 2 is the short way to write the same thing.

How well does each framework do? Custom Elements Everywhere runs the same tests against each one, in Chrome and Firefox. The tests pass in text, numbers, true or false, arrays, and objects. They also listen for events with names written in different ways. Its page lists the version it tested and the score:

  • React ^19: 100%.
  • Vue ^3.2.38: 100%.
  • Angular 16.2.10: 100%.
  • Svelte 4.2.19: 100%.

Vue's own guide quotes its perfect score. Stage 10 has a lesson for each framework, with forms, types, and older versions.

Can web components be server-side rendered?

Now the menu page. Here the shop's server builds the page and sends it as finished HTML. This is called server-side rendering: the page is turned into HTML before it leaves the server.

To the browser, HTML from a server is just text. It reads it from top to bottom and builds the page. A custom tag in that text is a tag like any other. It waits, as in lesson 1.1, until its class is defined. Here is the menu's rating as the server sends it. The button stands in for a slow network:

A rating as the server sends it, with the script on a slow networkPop out in the code editor (opens in a new tab)HTML
<h2>Green tea</h2><tea-rating value="4">Rated 4 out of 5</tea-rating><button>Load the script</button> <script>  const button = document.querySelector("button");  button.addEventListener("click", () => {    import("./tea-rating.js");    button.disabled = true;  });</script>
ResultLoading…
  • Lines 1 and 2 are the server's HTML: a heading and the rating. The rating has a sentence inside it, Rated 4 out of 5.
  • Line 3 is a button, so you choose when the script arrives.
  • Line 8 calls import(). It loads tea-rating.js and runs it, as if the file had just come over the network.
  • Line 9 turns the button off. The file only needs to load once.

Before you click, the result shows Rated 4 out of 5. The tag isn't defined yet, so the browser shows the text inside it. Click Load the script. The browser upgrades the tag, and five star buttons take the sentence's place. The sentence is still inside the tag. The rating's shadow root has no slot for it, so it isn't shown anymore.

So a server-rendered page works with custom tags as they are. But the reader only sees stars after the script runs. Can the server send the stars too?

Sending the shadow root from the server

It can, with declarative shadow DOM. You met it in lesson 1.2: a <template> with a shadowrootmode attribute. The browser turns it into a shadow root while it reads the HTML. No JavaScript runs. Here the server sends the rating's stars inside one:

The stars, sent in a declarative shadow rootPop out in the code editor (opens in a new tab)HTML
<h2>Green tea</h2><tea-rating value="4">  <template shadowrootmode="open">    <span role="img" aria-label="Rated 4 out of 5">★★★★☆</span>  </template></tea-rating><button>Load the script</button> <script>  const button = document.querySelector("button");  button.addEventListener("click", () => {    import("./tea-rating.js");    button.disabled = true;  });</script>
ResultLoading…
  • Line 2 opens the rating.
  • Line 3 is the template. shadowrootmode="open" makes it the rating's shadow root.
  • Line 4 is what goes inside: the stars, as text. role="img" and aria-label give screen readers words for them, Rated 4 out of 5.
  • Lines 7 to 15 are the same button and loader as before.

Before you click, the stars are already there. They came with the HTML. Now click Load the script. Line 6 of tea-rating.js calls attachShadow(). The element already has a shadow root from the HTML. So the browser empties that root and hands it back, as web.dev's guide explains. The class fills it with five buttons, and the stars become clickable.

Why it matters: the reader sees the component's real look at once, even on a slow phone. Stage 9 shows how a class can keep the server's shadow root instead of emptying it. That's called hydration.

Real-life analogyA shop window set up the night before

Leaf and Kettle sets up its shop window the night before. At dawn, people walking past already see the teapots and the prices. At nine, the staff arrive and unlock the till. Nobody builds the window again. Now people can also buy.

In real life: The window, set up the night before
In JavaScript: The shadow root, written in the server's HTML
In real life: People walking past at dawn
In JavaScript: Readers, before any script runs
In real life: The staff arriving at nine
In JavaScript: tea-rating.js loading
In real life: Unlocking the till
In JavaScript: The class adding buttons you can click

Before declarative shadow DOM, a shadow root needed JavaScript. Svelte's docs warn that custom elements built with Svelte aren't suited to server rendering, because their shadow DOM is invisible until JavaScript loads. The web.dev guide calls declarative shadow DOM the way to bring shadow DOM to the server.

React on the server

Frameworks can render on the server too. React 19 has a rule for custom elements there. This code runs in Node:

React rendering two custom elements on the serverJSX
import { renderToString } from "react-dom/server";

const tea = { name: "Green tea", minutes: 3 };
const page = (
  <main>
    <tea-card tea={tea} />
    <tea-rating value={4} onrating-change={() => {}} />
  </main>
);

console.log(renderToString(page));
  • Line 1 imports renderToString(). It turns React elements into a string of HTML.
  • Line 6 passes the tea object to the card.
  • Line 7 passes the number 4, and a function for the event, to the rating.
  • Line 11 prints the HTML.

It prints <main><tea-card></tea-card><tea-rating value="4"></tea-rating></main>. The number became the text "4". The object and the function are gone. The React team's post gives the rule. On the server, text, numbers, and true become attributes. Objects, functions, and false are left out. HTML is only text, so there's nowhere to put an object. Why it matters: whatever a reader must see before JavaScript runs has to be text, in an attribute or inside the tag.

Tools that send HTML first

Some tools are built around this idea. Astro renders its own components to HTML, on the server or at build time. By default, they add no JavaScript to the page. Its docs show a custom element for the parts that need clicks. The page sends the tag with real HTML inside, and a small class adds the behavior.

Eleventy's WebC turns components into plain HTML at build time. It keeps the custom tag in the output when the component has CSS or JavaScript of its own. Its docs call WebC components progressive enhancement friendly, an idea the next section explains. Stage 9 compares these tools.

Do web components work without JavaScript?

Scripts don't always arrive. A train goes into a tunnel. A network blocks a file. A script has a bug. So a careful page starts with HTML that works on its own. Then JavaScript makes it better, where it can. That's called progressive enhancement.

A custom tag fits this well. Whatever the server puts inside the tag shows until the class arrives. Lesson 1.3 called a tag that wraps working HTML an HTML web component. Zach Leatherman describes these as components that add behavior on top of HTML that already works. Compare three ways to send the rating:

Playground: what the server puts inside the tag
A rating as the server sends itPop out in the code editor (opens in a new tab)HTML
<h2>Green tea</h2><tea-rating value="4">Rated 4 out of 5</tea-rating><button>Load the script</button> <script>  const button = document.querySelector("button");  button.addEventListener("click", () => {    import("./tea-rating.js");    button.disabled = true;  });</script>
ResultLoading…
Try it yourself
Before the script, the reader sees Rated 4 out of 5

The sentence inside the tag shows at once. If the script never loads, the reader still knows the rating. Click Load the script: the shadow root covers the sentence with five star buttons.

Only the rating tag changes. Look at the result before you click Load the script: that is what a reader sees while the script is slow, or if it never comes.

Try each choice, and don't click the button yet. That is the page for a reader whose script never came. The empty tag shows nothing, so that reader never learns the rating. The sentence and the shadow root both tell them. Now click Load the script. All three end up as the same five buttons.

What the reader sees from three kinds of server HTML, before and after the script runs. Empty tag: nothing before, five star buttons after. Text inside: Rated 4 out of 5 before, star buttons after. Shadow root: the stars before, star buttons after.HTML arrivesscript runsempty tagbefore(nothing shows)after★★★★☆text insidebeforeRated 4 out of 5after★★★★☆shadow rootbefore★★★★☆after★★★★☆
Before the script runs, only what is in the HTML can show. After it runs, all three look the same: five buttons, four of them filled.
Real-life analogyA printed menu with a QR code

Each table at Leaf and Kettle has a printed menu. In its corner is a QR code. Scan it with a phone, and you can order from your seat. No phone, or no signal? You can still read the menu, and order at the counter.

In real life: The printed menu
In JavaScript: The HTML inside the tag
In real life: The QR code
In JavaScript: The script that adds the star buttons
In real life: A customer with no signal
In JavaScript: A reader whose script never loads
In real life: Ordering at the counter
In JavaScript: Reading Rated 4 out of 5 anyway

Read each row across: what the server sends, then what the reader sees at each moment.

What the reader sees from each kind of server HTML
What the server sendsBefore the script runsIf the script never loadsAfter the script runs
An empty tagNothing shows.Nothing ever shows.Five star buttons, four filled.
Text inside the tagThe sentence Rated 4 out of 5 shows.The sentence stays.Five star buttons cover the sentence.
A shadow root in the HTMLThe stars show, from the HTML.The stars stay, but nobody can click them.The stars become five buttons.

Why it matters: put the content inside the tag, not only in its script. Lesson 2.4 showed how to style a tag while it waits, and how to keep the page still when it upgrades.

Where the course goes deeper on frameworks and servers

This lesson showed each idea once. Two later stages take them apart, one lesson at a time. Here are their modules and lessons:

  • Stage 9: Server rendering. Send components as HTML with declarative shadow DOM, hydrate them, and use them with server frameworks.
    • Declarative shadow DOM: Declarative shadow DOM, Declarative shadow DOM and HTML APIs, Hydrating custom elements, Sharing styles in server-rendered components, Declarative shadow DOM in practice.
    • Servers and frameworks: Server rendering options, Lit on the server, HTML-first frameworks like Enhance and WebC, Web components in Astro and Next.js, Components that work before JavaScript.
  • Stage 10: Frameworks and libraries. Use web components inside frameworks, make web components from frameworks, and choose a library.
    • Web components inside frameworks: Web components in React, Web components in Vue, Web components in Angular, Web components in Svelte, Solid, and Preact, Types for every framework.
    • Libraries and frameworks that make web components: Custom elements from Vue, Angular, and Svelte, Stencil, FAST and Web Awesome, Design system libraries, Small libraries, Choosing a library, or none.

Before that, stages 2 to 8 teach you to build tags yourself: classes, shadow DOM, styling, accessibility, forms, and Lit. Then you'll bring components of your own to frameworks and servers.

Bring the rating to every Leaf and Kettle site

Ravi's plan is ready. The menu page comes first. Here it is as the server sends it, with three teas:

The menu page, as the server sends itPop out in the code editor (opens in a new tab)HTML
<h1>Leaf and Kettle menu</h1><ul>  <li>Green tea <tea-rating value="4">Rated 4 out of 5</tea-rating></li>  <li>Black tea <tea-rating value="5">Rated 5 out of 5</tea-rating></li>  <li>Mint tea <tea-rating value="3">Rated 3 out of 5</tea-rating></li></ul> <script type="module" src="tea-rating.js"></script>
ResultLoading…
  • Line 1 is the menu's heading.
  • Lines 3 to 5 put a rating next to each tea, with a sentence inside it.
  • Line 8 loads tea-rating.js as a module script. A module script waits until the browser has read the page, as lesson 1.4 showed. So the HTML shows first.

The result shows three rows of stars: 4, 5, and 3 filled. If the script never loads, each row keeps its sentence instead.

Now sort the rest of Ravi's plan. Does each job work as it is, need one setting, or need care?

Works as it is, or not quite?
  • Render <tea-rating> in Asha's React 19 shop
  • Use <tea-rating> in a partner café's Svelte 5 app
  • Send <tea-rating> with a sentence inside, in HTML from the shop's server
  • Use <tea-rating> in a standalone Angular component
  • Use <tea-rating> in the Vue staff page, with no warnings
  • Pass an object to <tea-card> in React while tea-card.js is still loading
  • Pass an object to <tea-card> while React renders on the server
  • Send an empty <tea-rating></tea-rating> from the server
Try it yourself
0 of 8 correct

Drag or tap each job into the group it belongs to.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Common mix-ups

  • "React doesn't support web components." No. React 19 sets properties when the element has them, and listens for custom events with on and the event's name. It passes every Custom Elements Everywhere test. The old trouble was React 18 and earlier.
  • "You need a wrapper library to use a web component in a framework." No. React 19, Vue, Angular, and Svelte all score 100% on Custom Elements Everywhere with the tag itself.
  • "Vue's Failed to resolve component warning means the tag is broken." No. Vue still renders it as a custom element. isCustomElement only skips Vue's search, and the warning.
  • "CUSTOM_ELEMENTS_SCHEMA loads the component." No. It only lets Angular's compiler accept tags with a hyphen. You still load the file that defines the tag.
  • "Web components can't be server-rendered." No. A server can send any tag, and declarative shadow DOM sends its shadow root in the HTML too. It works in every major browser.
  • "A server-rendered component shows nothing until its JavaScript loads." No. Text inside the tag shows at once, and so does a declarative shadow root.

Practice exercises

Answer first, then use the hints. The live results let you check yourself.

Exercise 1 · Warm-upA string for a property

This React component passes a string to the tea card, not an object. What does the card show?

import "./tea-card.js"; export default function Menu() {  return <tea-card tea="Green tea" />;}
ResultLoading…

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upWhat the server keeps

    This code runs on a server with React 19. What does it print?

    Starter codeJSX
    import { renderToString } from "react-dom/server";
    
    const html = renderToString(
      <tea-rating value={3} hidden={false} tea={{ name: "Mint tea" }} />
    );
    console.log(html);

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeA rating that works without its script

      Make the rating readable before its script loads. Edit line 1 so the page says how many stars it has. What does your page show before you click Load the script?

      <tea-rating value="3"></tea-rating><button>Load the script</button> <script>  const button = document.querySelector("button");  button.addEventListener("click", () => {    import("./tea-rating.js");    button.disabled = true;  });</script>
      ResultLoading…

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeFind the bug in the Angular review

        This standalone Angular component won't build. What do you add to the @Component?

        Starter codeAngular
        import { Component } from "@angular/core";
        import "./tea-rating.js";
        
        @Component({
          selector: "tea-review",
          template: `<tea-rating [attr.value]="4"></tea-rating>`,
        })
        export class TeaReview {}

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeSend the stars in the HTML

          Write a declarative shadow root, so the rating shows its stars before any script runs. How many filled stars show before you click?

          <tea-rating value="3"></tea-rating><button>Load the script</button> <script>  const button = document.querySelector("button");  button.addEventListener("click", () => {    import("./tea-rating.js");    button.disabled = true;  });</script>
          ResultLoading…

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeTurn JavaScript off

            In Chrome, pop out the result of the declarative shadow root example. Turn JavaScript off in DevTools, and reload. How many filled stars do you see?

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, ask: is this a property or an attribute, and what is in the HTML before the script runs?

              The frameworks and servers quiz · 7 questionsScore: first tries count
              1. Question 1 of 7React 19 renders <tea-card tea={tea} />, and tea-card.js loaded first. What does React do with tea?

                Choose an answer to see the explanation.

              2. Question 2 of 7What does this React server code print?

                Read the code, then predictJSX
                import { renderToString } from "react-dom/server";
                
                const tea = { name: "Green tea", minutes: 3 };
                const page = (
                  <main>
                    <tea-card tea={tea} />
                    <tea-rating value={4} onrating-change={() => {}} />
                  </main>
                );
                
                console.log(renderToString(page));

                Choose an answer to see the explanation.

              3. Question 3 of 7In development, Vue prints Failed to resolve component: tea-rating. What does it mean?

                Choose an answer to see the explanation.

              4. Question 4 of 7A standalone Angular component uses <tea-rating>, and the build fails with 'tea-rating' is not a known element. What do you add?

                Choose an answer to see the explanation.

              5. Question 5 of 7tea-rating reads its value attribute and has no value property. Which Angular binding fills the stars?

                Choose an answer to see the explanation.

              6. Question 6 of 7A server sends <tea-rating> with <template shadowrootmode="open"> inside. When does the reader see the template's stars?

                Choose an answer to see the explanation.

              7. Question 7 of 7The rating's script never loads. Which HTML from the server still tells the reader the rating?

                Choose an answer to see the explanation.

              Key takeaways

              • A web component is an HTML element. Any framework can put it on a page, pass it data, and listen for its events.
              • React 19 sets a property when the element has one, and an attribute otherwise. Load the tag's file before React renders it.
              • Vue needs isCustomElement to skip a warning, and Angular needs CUSTOM_ELEMENTS_SCHEMA to build. Svelte needs nothing.
              • HTML from a server is just HTML. A custom tag shows what's inside it, then upgrades when its script loads.
              • Declarative shadow DOM sends a component's shadow root in the HTML, so it shows before any JavaScript runs.
              • Put real content inside the tag, so the page still works when the script is slow or never comes.

              Remember the one-liner.
              One tag works in every framework and from any server: put real HTML inside it, and let the script make it better.

              Sources

              The facts on this page come from these docs, posts, and source files:

              Coming next: Your first custom element, the start of stage 2. You'll write your own class for a tag, step by step.

              CompleteFrontend Clear concepts. Working examples.