npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@elenajs/ssr

v1.0.0-alpha.10

Published

Render Elena components to HTML strings for server-side rendering.

Readme

Render Elena components to HTML strings for server-side rendering

[!WARNING] Please note that @elenajs/ssr is an experimental package and not yet ready for production use. APIs may change without notice.

Table of contents

Install

npm install @elenajs/ssr

Usage

Basic example

import { ssr, register } from "@elenajs/ssr";
const { Button } = await import("@elenajs/components");

register(Button);

const html = ssr(`<elena-button variant="primary">Save</elena-button>`);
// Outputs: '<elena-button variant="primary"><button>Save</button></elena-button>'

With nesting

Nested Elena components are expanded automatically:

import { ssr, register } from "@elenajs/ssr";
const { Button, Stack, Input } = await import("@elenajs/components");

register(Button, Stack, Input);

const html = ssr(`
  <elena-stack direction="row">
    <elena-input label="Email" type="email" placeholder="[email protected]"></elena-input>
    <elena-button>Send</elena-button>
  </elena-stack>
`);

Output:

<elena-stack direction="row">
  <elena-input type="email" placeholder="[email protected]">
    <label for="email">Email</label>
    <input id="email" type="email" placeholder="[email protected]" />
  </elena-input>
  <elena-button><button>Send</button></elena-button>
</elena-stack>

With a full page

import { ssr, register } from "@elenajs/ssr";
const { Button } = await import("@elenajs/components");

register(Button);

const page = ssr(`
<!doctype html>
<html>
<head>
  <link rel="stylesheet" href="/components/button.css">
</head>
<body>
  <elena-button variant="primary">Click me</elena-button>
  <script type="module" src="/components/button.js"></script>
</body>
</html>
`);

With Eleventy

You can use @elenajs/ssr with Eleventy as either a transform or a shortcode.

As a transform

A transform processes every rendered page automatically, expanding any registered components found in the output HTML. No shortcodes or special syntax needed, just write Elena components directly in your templates:

// eleventy.config.js
import { ssr, register } from "@elenajs/ssr";
const { Button, Stack } = await import("@elenajs/components");

register(Button, Stack);

export default function (eleventyConfig) {
  eleventyConfig.addTransform("elena-ssr", (content, outputPath) => {
    if (outputPath?.endsWith(".html")) {
      return ssr(content);
    } else {
      return content;
    }
  });
}

Note: Use await import() for component modules rather than a static import statement. Elena components extend HTMLElement, which requires a Node.js shim that @elenajs/ssr installs when it loads. Dynamic imports guarantee the shim is in place first, regardless of how an import sorter may reorder your static imports.

Then use Elena components directly in any Nunjucks, Liquid, or Markdown template:

<elena-stack direction="row">
  <elena-input type="email" placeholder="[email protected]"></elena-input>
  <elena-button variant="primary">Subscribe</elena-button>
</elena-stack>

As a shortcode

If you prefer more control over which parts of a page are processed, use a shortcode instead:

// eleventy.config.js
import { ssr, register } from "@elenajs/ssr";
const { Button } = await import("@elenajs/components");

register(Button);

export default function (eleventyConfig) {
  eleventyConfig.addShortcode("render", (html) => ssr(html));
}

Then in a template:

{% render '<elena-button variant="primary">Save</elena-button>' %}

API

register(...components)

Register Elena component classes for SSR expansion. Each class must have static tagName defined. Call this once before using ssr().

import { register } from "@elenajs/ssr";
const { Button, Stack } = await import("@elenajs/components");

register(Button, Stack);

Throws an error if a component does not have a tagName.

unregister(...components)

Remove previously registered component classes from the SSR registry.

import { register, unregister } from "@elenajs/ssr";
const { Button } = await import("@elenajs/components");

register(Button);
// ... later
unregister(Button);

clear()

Remove all registered component classes from the SSR registry at once.

import { clear } from "@elenajs/ssr";

clear();

ssr(html)

Parse an HTML string, expand registered components with render(), and return the rendered HTML. Full HTML documents are supported: <!DOCTYPE>, <html>, <head>, and <body> tags are preserved as-is alongside component expansion.

| Parameter | Type | Description | | --------- | -------- | ---------------------------------------- | | html | string | HTML string containing Elena components. |

Returns: string, the rendered HTML with components expanded.

How it works

  1. Parse the input HTML string into a tree.
  2. Walk the tree and look up each custom element tag in the registry.
  3. Expand matching custom elements by calling their render().
  4. Recurse into composite component children and non-component tags.
  5. Serialize the tree back to an HTML string.

The rendered output matches what Elena produces on the client, using the same html tagged template escaping and whitespace normalization.

If a component's render() throws an error, the SSR renderer logs a warning and falls back to passing the component through without expansion, preserving its original children.

Client-side hydration

The HTML produced by ssr() is designed for progressive enhancement. When the component JavaScript loads on the client:

  1. Elena's connectedCallback fires on the pre-rendered element.
  2. render() runs and hydrates the component with interactivity.
  3. Event listeners are attached and methods become available.

License

MIT

Copyright

Copyright © 2026 Ariel Salminen