Module with Hydration
Module with Hydration
About this demo
Built with es
format and included via <script type="module">
with
@@ -39,24 +39,85 @@
the page. Interactivity is then restored to those components once modules (which are
always
deferred) have finished loading.
Performance
You can compare performance in each demo by opening DevTools, disabling cache, and then enabling network throttling - (e.g. try "Fast 3G").
Features
This demo is implemented entirely using Svelte and placed in the page as custom elements (a.k.a. "web components")
- using svelte-retag
. It demonstrates:
- Slots (default and named slots)
- Nesting within slots
- The differences between deferred Modules and IIFE, particularly with regard to CLS (Content - Layout Shift)
- Vite HMR updates (if launched locally)
- SSR/SSG + hydration (experimental)
Note that each counter below takes an initial count
attribute with an award
value, at which
- point a ๐ emoji is first displayed (with randomized emojis after that). Press +
or -
keys on
- your keyboard to quickly increase/decrease the count.
Default: Count starts at 0, award at 100.
Start out just 1 click away from the "award".
View the
+ page
+ source ๐. This demo is implemented entirely using via svelte-retag
with all Svelte components
+ organized on the page using custom elements (or โweb componentsโ). Featuring:
- Slots (default and named slots)
- Nesting within slots
- Context (including nested context, see โExamplesโ tab)
- Vite HMR updates (if launched locally)
- SSR/SSG via hydration (experimental)
Performance
This demo also shows the differences between deferred Modules and IIFE, particularly with regard to CLS (Cumulative + Layout Shift). Use the Demos navigation above and compare each one by opening DevTools, disabling + cache, and then enabling network throttling (e.g. try "Fast 3G").
1337 award
Nested slot: "Total is"
All element attributes in this particular demo are configured to be dynamic. Try editing the
+ pagetitle
in <app-tag pagetitle="...">
above or any of the
+ count
or award
attributes in any of the <counter-tag>
buttons below.
For example: Each counter below takes an initial count
attribute with an award
+ value, at which point a ๐ emoji is first displayed (with randomized emojis after that). Press +
or -
+ keys on your keyboard to quickly increase/decrease the count.
Default: count
starts at 0, award
at 100.
Start out just 1 click away from the award
.
1337 award
Slot: "Total is"
Credit to AmirPournasserian
+ from
+ this StackOverflow post for the original .svelte
components which were then converted to custom
+ elements using svelte-retag
to help demonstrate context. These are implemented purely by arranging the
+ following tags using only HTML and can even be nested, just like in this demo!
<tabs-wrapper> + <tab-list> + <tab-button>Tab 1</tab-button> + <tab-button>Tab 2</tab-button> + </tab-list> + + <tab-panel> + <!-- Content for Tab 1 --> + </tab-panel> + + <tab-panel> + <!-- Content for Tab 2 --> + </tab-panel> +</tabs-wrapper> +
In this example, <tabs-wrapper>
defines the shared context and <tab-button>
+ toggles between each <tab-panel>
within that context.