Introducing a new way to review your PRs.

Read the announcement

chakra-ui / panda

🐼 Universal, Type-Safe, CSS-in-JS Framework for Design Systems ⚡️

View on GitHub

19 documents · Updated Sep 23, 2026

docs / playground-application

Playground application

The Playground application is an interactive way to try Panda in a browser. It lets a user edit a small component, Panda CSS configuration, and custom CSS, then see the result and generated output at once. It also lets the user load examples, test responsive views, save a session, and compare two saved sessions. It is part of the product experiences area.

Application role

The application brings together a code editor, Panda processing, a live preview, and inspection views. Its main purpose is to shorten the path from a Panda idea to a visible result without requiring a separate local project.

Playground session

A playground session is the shared unit of work. It contains the component source, custom CSS, and Panda configuration. The application can start with a built-in example, restore a saved session, or show two saved sessions for comparison.

References: playground/…/usePlayground.ts• L9-19 playground/…/page.tsx• L5-13 playground/…/page.tsx• L6-23 playground/…/page.tsx• L6-31

Application boundary

The application runs Panda in the browser while using the repository's Panda packages as its processing layer. The browser view supplies the edited state, Panda turns that state into CSS and parse results, and the preview displays the result in an isolated document. The application also uses a database-backed share endpoint to make a session available through a link.

References: playground/…/PlaygroundContent.tsx• L22-49 playground/…/usePanda.ts• L8-12 playground/…/usePandaContext.ts• L18-29 playground/…/share.ts• L7-26 playground/…/schema.prisma• L5-16

Playground workflows

The application supports a small set of connected workflows. Each workflow uses the same session state, so an edit changes the preview, generated output, and any later shared link.

Session flow

The session flow moves from an initial example or saved record to editable state, Panda output, and an optional shared URL. This diagram shows the main relationship between the application layers.

flowchart LR
    A[Built-in example or saved session] --> B[Playground state]
    B --> C[Config and Panda processing]
    C --> D[Live preview]
    C --> E[AST and generated CSS]
    B --> F[Share endpoint]
    F --> G[Saved session URL]
    G --> A

References: playground/…/Playground.tsx• L6-13 playground/…/PlaygroundContent.tsx• L44-49 playground/…/usePanda.ts• L42-79 playground/…/usePlayground.ts• L79-131

Example workflow

The Examples menu provides ready-made starting points for common Panda usage. A user can switch between direct style functions, recipes, slot recipes, patterns, and JSX style props. Selecting an example replaces the current editable code and configuration with that example's state.

References: playground/…/data.ts• L10-38 playground/…/data.ts• L41-79 playground/…/data.ts• L82-122 playground/…/data.ts• L125-173 playground/…/data.ts• L175-294 playground/…/index.tsx• L9-31 playground/…/usePlayground.ts• L133-143

Editing workflow

The editor presents three views of the session: component code, custom CSS, and Panda configuration. The user can change any of them and use the result as the next input to the preview and artifact views. The application keeps editing separate from the slower Panda work so the editor remains usable while output updates.

References: playground/…/Editor.tsx• L10-20 playground/…/Editor.tsx• L22-33 playground/…/PlaygroundContent.tsx• L125-143 playground/…/usePlayground.ts• L69-72 playground/…/usePlayground.ts• L145-149

Configuration workflow

The configuration view accepts Panda configuration written for the playground. Simple configuration is checked in the browser. Configuration that uses imports or presets is resolved through a background worker and can load packages from the public package CDN. Errors remain visible to the user instead of stopping the whole playground.

References: playground/…/useConfig.ts• L7-18 playground/…/useConfig.ts• L21-58 playground/…/compile.ts• L4-43 playground/…/compile.worker.ts• L3-10

Preview workflow

The preview turns the edited component and Panda output into a live browser view. It runs in an isolated frame, reports code or configuration errors in that view, and follows the application's light or dark mode. The responsive mode adds a resizable viewport and uses the active Panda breakpoints to show the selected size.

References: playground/…/index.tsx• L21-83 playground/…/index.tsx• L183-218 playground/…/usePreview.ts• L41-81 playground/…/LayoutControl.tsx• L8-16 playground/…/useResponsiveView.ts• L18-35

Artifact workflow

The artifact panel helps the user understand what Panda produced from the edited component. It exposes the parsed result as an AST view and the generated CSS as separate readable files. These views connect source constructs to the CSS that appears in the preview.

References: playground/…/ArtifactsPanel.tsx• L16-25 playground/…/ArtifactsPanel.tsx• L27-114 playground/…/ASTViewer.tsx• L12-24 playground/…/GeneratedCss.tsx• L12-26

Sharing workflow

Sharing stores the current session and changes the browser URL to its short identifier. Opening that identifier restores the saved code, CSS, and configuration. After a session is saved, the user can save a second state and open a comparison route that shows the original and updated states side by side in the editor.

References: playground/…/usePlayground.ts• L74-131 playground/…/share.ts• L13-26 playground/…/page.tsx• L10-23 playground/…/page.tsx• L10-31 playground/…/Editor.tsx• L95-106

Application integration points

The application depends on a few boundaries that shape its user experience. These boundaries allow the browser playground to use Panda services, persist links, and keep browser-only work out of the server render.

Panda processing boundary

The Panda boundary accepts a resolved user configuration and the current source state. It returns the live CSS, generated CSS artifacts, preview support code, and parse results that drive the preview and artifact panel. A configuration error can fall back to a usable context so the user can continue editing.

References: playground/…/usePanda.ts• L14-79 playground/…/usePandaContext.ts• L31-92 playground/…/Playground.tsx• L6-13

Share persistence boundary

The share boundary accepts only the three session values needed to restore a playground. It validates the request, assigns a short ID, and stores the session in the database. Read routes use that ID to rebuild the initial state before the client playground starts.

References: playground/…/share.ts• L7-26 playground/…/schema.prisma• L10-16 playground/…/page.tsx• L13-22

Browser runtime boundary

The browser runtime boundary provides the services that cannot be used during the first server render. It waits for the CSS runtime support to load, sets the application theme, and hosts the live result in an iframe. This keeps browser execution and preview styling separate from the application shell.

References: playground/…/providers.tsx• L7-27 playground/…/layout.tsx• L17-26 playground/…/usePreview.ts• L19-39 playground/…/index.tsx• L45-83

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to the session shape must stay aligned across usePlayground, parse-state, the share request schema, the Session record, and both saved-session routes.
  • Changes to the editor's three state keys must stay aligned with the preview input, Panda processing input, share payload, and diff editor paths.
  • Changes to configuration imports or presets must preserve both the direct configuration path and the worker-based package loading path.
  • Changes to Panda output names or layers must stay aligned with the artifact tabs and the CSS injected into the preview frame.
  • Changes to responsive breakpoint data must preserve the link between the selected layout control and the preview viewport.

Important failure modes

TriggerConsequenceGuard
A shared session cannot be readThe saved playground route returns not found instead of showing a partial sessionThe route treats the read failure as a missing page and restores only validated session fields
The configuration has an invalid import or presetPanda output cannot use the requested configuration and the preview shows an errorConfiguration loading reports the worker error and the playground keeps an available context
The edited component contains a runtime or compile errorThe preview cannot render the componentThe live preview displays the error inside the preview area
The share request does not contain valid session textNo usable saved link is createdThe share endpoint validates code, css, and config before writing
Browser CSS runtime support is not readyThe application shell must not show an incomplete playgroundThe provider waits for the CSS runtime to load before rendering the client experience

Key files

FileWhy to read it
playground/…/PlaygroundContent.tsxShows how the toolbar, editor, artifact panel, preview, and layout controls form the main experience.
playground/…/usePlayground.tsDefines the session state and the example, layout, edit, share, and compare workflows.
playground/…/usePanda.tsShows the boundary between session state and Panda results used by the UI.
playground/…/index.tsxExplains how the edited component becomes a live preview and how errors reach the user.
playground/…/Editor.tsxDefines the user-facing code, CSS, configuration, and comparison views.
playground/…/ArtifactsPanel.tsxShows the two inspection paths for parse results and generated CSS.
playground/…/data.tsDefines the built-in learning examples and the Panda workflows they demonstrate.
playground/…/share.tsDefines the persistence contract for shareable sessions.
playground/…/page.tsxShows how a saved session becomes the initial state for a normal shared link.
playground/…/page.tsxShows how two saved sessions become a comparison playground.
playground/…/schema.prismaDefines the stored session data needed to restore a playground.