# @popeindustries/lit-element

> Enable hydration of lit-element elements rendered on the server with @popeindustries/lit-html-server

Latest version **3.1.5** (published 2024-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @popeindustries/lit-element
pnpm add @popeindustries/lit-element
yarn add @popeindustries/lit-element
bun add @popeindustries/lit-element
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.5 |
| Published | 2024-11-01 |
| First published | 2019-09-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 216.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 41 |
| Author | Alexander Pope |
| Maintainers | popeindustries, anderscan |
| Keywords | html template, lit-html, ssr, stream, streaming, tagged template literal, template, template render |

## Links

- npm: https://www.npmjs.com/package/@popeindustries/lit-element
- Repository: https://github.com/popeindustries/lit
- Homepage: https://github.com/popeindustries/lit#readme
- Issues: https://github.com/popeindustries/lit/issues
- npm.io page: https://npm.io/package/@popeindustries/lit-element

## Dependencies (2)

- [@popeindustries/lit-html](https://npm.io/package/@popeindustries/lit-html.md) 5.2.4
- [@popeindustries/lit-html-server](https://npm.io/package/@popeindustries/lit-html-server.md) 6.1.3

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 3.1.5 (latest) — 2024-11-01
- 2.0.0-beta.2 (beta) — 2020-01-22
- 3.1.4 — 2024-09-13
- 3.1.3 — 2024-06-16
- 3.1.2 — 2023-06-21
- 3.1.1 — 2023-06-09
- 3.1.0 — 2023-01-22
- 3.0.11 — 2022-11-07
- 3.0.10 — 2022-10-16
- 3.0.9 — 2022-10-08
- 3.0.8 — 2022-09-27
- 3.0.7 — 2022-09-26
- 3.0.6 — 2022-09-22
- 3.0.5 — 2022-09-21
- 3.0.4 — 2022-09-13
- … 11 more at https://npm.io/package/@popeindustries/lit-element/versions

## README

[![NPM Version](https://img.shields.io/npm/v/@popeindustries/lit-element.svg?style=flat)](https://npmjs.org/package/@popeindustries/lit-element)

# @popeindustries/lit-element

Seamlessly and efficiently use [@popeindustries/lit-html-server](https://github.com/popeindustries/lit/tree/main/packages/lit-html-server/) rendered HTML to hydrate **lit-element** web components in the browser, including lazy hydration with `hydrate:idle` or `hydrate:visible` attributes.

## Usage

Install with `npm/yarn/pnpm`:

```bash
$ npm install --save @popeindustries/lit-element
```

Create a web component:

```js
import { css, html, LitElement } from '@popeindustries/lit-element';

class MyEl extends LitElement {
  static styles = css`
    p {
      color: green;
    }
  `;
  render() {
    return html`<p>I am green!</p>`;
  }
}

customElements.define('my-el', MyEl);
```

...render a page template on the server with [`@popeindustries/lit-html-server`](https://github.com/popeindustries/lit/tree/main/packages/lit-html-server/):

```js
import './my-el.js';
import { html, renderToNodeStream } from '@popeindustries/lit-html-server';
import { hydratable } from '@popeindustries/lit-html-server/directives/hydratable.js';
import { LitElementRenderer } from '@popeindustries/lit-element/lit-element-renderer.js';
import http from 'node:http';

http.createServer(
  (request, response) => {
    response.writeHead(200);
    renderToNodeStream(html`<!DOCTYPE html>
      <html lang="en">
        <head>
          <meta charset="UTF-8" />
          <title>LitElement example</title>
        </head>
        <body>
          <my-el></my-el>
        </body>
      </html>`).pipe(response);
  },
  {
    // Register a renderer for LitElement components
    renderers: [LitElementRenderer],
  },
);
```

...and import the same web component in the browser to trigger hydration/render on changes:

```js
import './my-el.js';

// Trigger hydration/initial update
document.querySelector('body > my-el').removeAttribute('hydrate:defer');
```

> **Note**
> Due to how the `lit*` family of packages are minified and mangled for production, the `@popeindustries/lit-element` package is forced to _vendor_ all dependencies to `lit-element` and `@lit/reactive-element` packages. This shouldn't affect normal use as long as application code does not mix imports from `@popeindustries/lit-element` and `lit-element`.

---
_Source: https://npm.io/package/@popeindustries/lit-element · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
