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

@contentful/optimization-web-preview-panel

v1.0.1

Published

Preview panel UI for Contentful Optimization Web integrations

Readme

Guides · Reference · Contributing

This package implements the first-party browser preview panel for the Optimization Web SDK. It loads into the DOM as a Lit-based Web Component micro-frontend and talks to the Web SDK through the preview bridge exposed by the Optimization Web SDK runtime.

Getting started

Install using an NPM-compatible package manager, pnpm for example:

pnpm add @contentful/optimization-web-preview-panel

Import the attach function; both CJS and ESM module systems are supported, ESM preferred:

import attachOptimizationPreviewPanel from '@contentful/optimization-web-preview-panel'

Attach the preview panel with an existing, unmodified Contentful Delivery API client. By default, the attach function uses the browser singleton created by the Optimization Web SDK:

attachOptimizationPreviewPanel({
  contentful: contentfulClient,
})

When your application already fetches preview content, pass entries instead:

attachOptimizationPreviewPanel({
  entries: {
    audiences: audienceEntries,
    experiences: experienceEntries,
  },
})

The attach function appends the panel to the DOM and adds the toggle button that opens it. It is safe to call more than once; repeated calls reuse the in-flight or completed panel attachment. The panel search uses fuzzy matching for audience and optimization names and highlights matched text in the result list.

[!IMPORTANT]

Importing this package has no side effects. It does not attach the panel, define custom elements, inject styles, touch storage, or mutate globals until attachOptimizationPreviewPanel(...) is called.

When to use this package

Use @contentful/optimization-web-preview-panel when a Web SDK or React Web SDK integration needs the browser preview panel attached to an existing Contentful SDK client. Application code can pass an explicit Optimization Web SDK instance, but the common browser flow uses window.contentfulOptimization.

Pre-fetched entries

Use entries when the app cannot give the browser preview panel a direct Contentful client or when it already owns the query layer. This covers GraphQL query adapters, Hydrogen loaders, SSR data handoff, tag-filtered Contentful queries, and proxy APIs.

The entries option has this shape:

attachOptimizationPreviewPanel({
  entries: {
    audiences,
    experiences,
  },
})

Each value can be either a Contentful-style entry collection or a readonly array of Contentful entries. The preview panel normalizes arrays into entry collections, keeps only nt_audience items from audiences, keeps only nt_experience items from experiences, and preserves experiences.includes.Entry so linked variant names can be displayed.

If both entries and contentful are provided, entries wins and the preview panel does not fetch through the Contentful client.

Common paths:

  • Contentful client - Pass contentful first when the browser can use an existing Contentful Delivery API client.
  • GraphQL - Map GraphQL nodes to Contentful entry objects, then pass the arrays as entries.audiences and entries.experiences.
  • Hydrogen loaders and SSR - Load audiences and experiences in the loader or server route, serialize them to the browser, then attach with entries.
  • Tag-filtered queries - Pass the filtered Contentful collections directly. The panel still filters by content type before building definitions.
  • Proxy APIs - Return { audiences, experiences } from the proxy and pass that object as entries.

Common configuration

| Option | Required? | Default | Description | | -------------- | ----------- | ------------------------------- | ---------------------------------------------------------- | | contentful | Conditional | N/A | Existing Contentful client used to read preview content | | entries | Conditional | N/A | Pre-fetched audience and experience entries | | optimization | No | window.contentfulOptimization | Existing Optimization Web SDK instance | | nonce | No | undefined | CSP nonce applied to Lit styles when strict CSP is enabled |

Provide either contentful or entries.

For the complete attach function signature, use the generated Preview Panel reference.

Production bundle control

The preview panel is intended for development and staging builds. Consumers own that build policy and can wrap the attachment call in an environment-backed conditional:

import attachOptimizationPreviewPanel from '@contentful/optimization-web-preview-panel'

if (import.meta.env.PUBLIC_OPTIMIZATION_ENABLE_PREVIEW_PANEL === 'true') {
  void attachOptimizationPreviewPanel({ contentful: contentfulClient })
}

When the consumer bundler replaces that condition with a build-time false value and performs dead-code elimination, the side-effect-free preview panel import graph can be removed from the production output.

Content security policy support

In strict CSP environments, pass a nonce directly:

attachOptimizationPreviewPanel({ contentful: contentfulClient, nonce })

Alternatively, set window.litNonce before attaching the panel:

window.litNonce = nonce
attachOptimizationPreviewPanel({ contentful: contentfulClient })

Related