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

@semantic-ui/astro-lit

v5.3.0

Published

Use Lit components with Astro

Downloads

6,755

Readme

@semantic-org/astro-lit

NPM Version NPM Downloads License

The official @astrojs/lit integration was deprecated in Astro v5. This community-maintained integration enables you to continue using Lit with modern versions of Astro.

This Astro integration enables server-side rendering and client-side hydration for your Lit custom elements.

Features

  • Server-side rendering (SSR) of Lit components.
  • Client-side hydration with Astro client:* directives.
  • Automatic polyfills for Declarative Shadow DOM in unsupported browsers.
  • Support for experimental decorators.

Installation

Prerequisites

  • Astro v5.0 or later.
  • Node.js v18.17.1, v20.3.0 or later.

To use the Lit integration, you first install the required package and then update your Astro configuration.

Procedure

  1. Install the integration package into your project:

    • npm
      $ npm install @semantic-ui/astro-lit
    • pnpm
      $ pnpm add @semantic-ui/astro-lit
    • yarn
      $ yarn add @semantic-ui/astro-lit
  2. Update your astro.config.mjs file to include the Lit integration.

    import { defineConfig } from 'astro/config';
    import lit from '@semantic-ui/astro-lit';
        
    export default defineConfig({
      integrations: [lit()],
    });

Usage

To learn about using framework components in Astro, refer to the Astro Framework Components guide.

Creating and Using a Lit Component

To use a Lit component, create a component file and then import it into your .astro pages.

  1. Create your Lit component. For example, create a new file named my-element.js in the src/components/ directory.

    import { LitElement, html } from 'lit';
        
    export class MyElement extends LitElement {
      render() {
        return html`<p>Hello world! This is my Lit component.</p>`;
      }
    }
        
    customElements.define('my-element', MyElement);
  2. Import and use the component in an Astro page. Note that Astro requires you to use the class name, MyElement, as the component tag, not the custom element tag name my-element.

    ---
    import { MyElement } from '../components/my-element.js';
    ---
    <MyElement />

Using Third-Party Lit Components

You can also use third-party web components that are built with Lit. To use a third-party component, import its JavaScript module, which typically registers the custom element as a side effect. Then, you can use the custom element tag directly in your template.

In the following example, you import a third-party button component and use it with its custom HTML tag, <sbb-button>:

---
// This import registers the <sbb-button> custom element.
import '@sbb-esta/lyne-elements/button.js';
---
<h1>Third-Party Component Example</h1>

<sbb-button>Click Me</sbb-button>

Client-Side Hydration

To hydrate a component on the client, add an Astro client:* directive. These directives determine when the component's JavaScript is sent to the browser.

For example, to hydrate a component only when it becomes visible in the viewport, use the client:visible directive:

---
import { MyElement } from '../components/my-element.js';
---
<MyElement client:visible />

For a full list of available directives, refer to the official Astro Client Directives documentation.

Using Experimental Decorators

To use experimental decorators in Lit, for example @customElement or @state, you must enable the experimentalDecorators option in your tsconfig.json file.

  1. If you do not have one, create a tsconfig.json file in the root of your project.

  2. Add the compilerOptions.experimentalDecorators setting:

    {
      "compilerOptions": {
        "experimentalDecorators": true
      }
    }

You can now use decorators in your Lit TypeScript components:

import { LitElement, html } from "lit";
import { customElement, property } from "lit/decorators.js";

@customElement("my-decorator-element")
export class MyDecoratorElement extends LitElement {
    @property()
    name = "World";

    override render() {
        return html`<p>Hello, ${this.name}!</p>`;
    }
}

Troubleshooting

This section describes common issues and their solutions.

Browser Global Interference

The Lit integration adds browser global properties, for example window and document, to the global scope during server-side rendering. These globals can interfere with other libraries that check for their existence to determine if they are running in a browser environment. This can cause unexpected behavior or errors with other libraries.

If you use multiple integrations, changing their order in the astro.config.mjs file can sometimes resolve the issue.

import { defineConfig } from 'astro/config';
import vue from '@astrojs/vue';
import lit from '@semantic-ui/astro-lit';

export default defineConfig({
  // If vue() causes issues, try placing lit() before it.
  integrations: [lit(), vue()]
});

Component Not Updating in Development

During development, if you make changes to a Lit component and do not see the updates in your browser, you might need to restart the Astro development server.

Strict Package Manager Errors

When you use a strict package manager like pnpm, you can encounter a ReferenceError: module is not defined error. To resolve this, create a .npmrc file in your project's root directory and add a hoist pattern for Lit dependencies:

public-hoist-pattern[]=*lit*

Contributing

This project is open source and maintained by the community. You are welcome to submit issues and pull requests.

  • To report a bug or request a feature, open an issue.
  • To contribute code, please open a pull request.

License

MIT