shane logsdon · web components
Render on the server.
Hydrate in the browser.
Three small tools for native custom elements: PHP that turns a component's template into HTML, JavaScript that turns that HTML back into a live element, and a JSX factory that writes the component in the first place.
Choose a toolthe shape of it
three pieces, one markup contract- Render
- PHP functions in
slogsdon/web-component-ssrread a template file, fill its slots with data, and print a placeholder element the browser can find again. - Hydrate
web-component-hydrationfinds those placeholders, replaces each one with a real custom element, and lets the element clone its template into an open shadow root.- Author
jsx-for-web-componentsprovides theh()pragma function and aJSXCustomElementbase class so a component's markup can be written as JSX. Its README labels it work in progress.
The three were built as a set: the PHP library's output is exactly the markup the
hydration library looks for, and both use the same two attribute names
(data-template and the template- element id prefix). Each
piece is also usable alone, which is how they are documented here — three pages, one
per tool.
what this is not
no declarative shadow DOMNothing here emits <template shadowrootmode>. Searching the three
repositories at the revisions this site records — shadowrootmode,
declarative — returns no matches in code, tests, or READMEs. The PHP
renderer writes a <div data-template="…"> placeholder plus a
separate <template id="template-…"> for the client; the shadow root
is created by attachShadow({ mode: 'open' }) in a constructor, in the
browser, after the script has loaded. The JSX library has a static-markup renderer,
but it serialises an element's shadow children inline as light DOM rather than as a
declarative shadow root.
So the server-rendered HTML is a placeholder a script replaces, not a shadow tree the browser adopts. If the script never runs, a reader sees the placeholder's copied children, not a styled component. That is the trade these tools were written to make, and this site does not claim more for them than that.
status
2018–2019 code, 2026 doc linkThe code in all three is from 2018 and 2019: the JSX factory last changed on 2018-12-29 (1.2.1), the hydration library on 2019-08-06 (1.0.5), and the PHP library on 2019-08-06. Each repository has one later commit, dated 2026-05-08, which adds a homepage link and touches no code. Treat all three as published, unmaintained examples rather than as an actively developed framework, and treat the JSX library as the README itself labels it: WIP.
The PHP package is registered on Packagist as slogsdon/web-component-ssr
with exactly one version, dev-master — there is no tagged release. Both
JavaScript packages are on npm: web-component-hydration at 1.0.5 and
jsx-for-web-components at 1.2.1. The three repositories are separate;
none of them depends on another at install time.
where to go
five entries-
SSR in PHP
The two functions, the template directory, the demo's commands, and the markup it actually produced.
-
Hydration in the browser
CustomHTMLElement,hydrate(),onReady(), and the placeholder attributes the client half expects from the server. -
JSX authoring (WIP)
The
h()factory,JSXCustomElement, and the TypeScript plus Rollup setup its README walks through. -
Source: php-web-component-ssr
The PHP renderer, its
examples/simpledemo, and a Psalm config. -
Source: javascript-web-component-hydration
Two ES modules and no build step. Also on npm, and the sibling jsx-for-web-components is on npm too.