A full-featured browser-based code playground for React applications, built with React, TypeScript, and modern web technologies. Write, bundle, and preview React code entirely in your browser!
- Multiple Project Templates:
- Plain React - Lightweight React starter with modern gradient UI
- Material UI - Full MUI setup with comprehensive component examples
- One-Click Switching: Switch between templates with confirmation dialog
- Template Persistence: Active template and files saved in state
- Hierarchical File Tree: Nested folders and files with expand/collapse
- Inline Operations: Hover over any folder to show action buttons:
- Create new files and folders at any level
- Rename files and folders inline
- Delete files and folders with confirmation
- Smart Icons: File type detection with colored icons (.js, .jsx, .ts, .tsx, .html, .css, .json)
- Visual Feedback: Active file highlighting and hover states
- CodeMirror 6 Integration: Lightning-fast, extensible code editor
- Language Support: JavaScript, JSX, TypeScript, TSX, HTML, CSS, JSON
- Auto-save: Changes automatically saved to state
- Dark Theme: OneDark color scheme optimized for long coding sessions
- Real-time Bundling: ESBuild-powered bundling in the browser
- React Rendering: Full React 18 support with JSX transformation
- Iframe Isolation: Sandboxed preview with clean error handling
- Auto-refresh: Smooth transitions when code changes
- Console Integration: Captured console.log, error, warn, and info messages
- Restricted Public Demo Mode: Public deployments only expose a curated dependency list
- Local Open NPM Mode: Clone the repo and enable
VITE_ENABLE_OPEN_NPM=trueto search and install arbitrary npm packages locally - Smart Dependency Resolution: Automatic peer dependency detection
- Version Selection: Choose specific package versions
- Visual Dependencies Panel: See installed packages with versions
- One-Click Install/Uninstall: Easy package management
- Dual Resolver System:
- Base Resolver: Standard React packages
- MUI Resolver: Material UI with external React handling
- Import Map Generation: Dynamic ESM import maps via esm.sh
- Peer Dependency Handling: Automatic resolution of peer dependencies
- Virtual File System: In-memory file resolution for imports
- Resizable Panels: Four-panel layout with drag-to-resize:
- File tree (vertical split with dependencies)
- Dependencies panel (resizable height)
- Code editor
- Live preview with console
- Responsive Design: Clean, VS Code-inspired dark UI
- Collapsible Sections: Toggle dependencies and console visibility
- React 18 - UI library with hooks
- TypeScript - Type safety and better DX
- Vite - Lightning-fast build tool and dev server
- Tailwind CSS - Utility-first styling
- Zustand - Lightweight state management for file system and packages
- CodeMirror 6 - Extensible code editor
- @codemirror/lang-javascript - JavaScript/JSX syntax
- @codemirror/theme-one-dark - Dark theme
- esbuild-wasm - WebAssembly-based bundler
- esm.sh - CDN for ES modules with import maps
- Virtual FS Plugin - In-memory file resolution
- react-resizable-panels - Draggable panel layout
- react-icons - VS Code and file type icons
- Material UI (optional) - Template with full MUI setup
- NPM Registry API - Package search and metadata
- Custom Dependency Resolver - Smart peer dependency detection
# Install dependencies
npm install
# Start development server
npm run dev
# Enable full npm search/install for local experiments
echo "VITE_ENABLE_OPEN_NPM=true" > .env.local
npm run dev
# Build for production
npm run buildThe application will be available at http://localhost:5173
The hosted demo is intentionally restricted. It is meant to show the artifact runtime, editor, templates, browser bundling, and sandboxed preview without letting the public subdomain become a general-purpose npm execution surface.
By default, the public app:
- Searches only a curated package list used by the built-in demos.
- Blocks non-curated package names even if someone edits
package.jsonmanually. - Caps dependency count and install batch size.
- Runs previews in a sandboxed iframe without same-origin, form submission, or popup escape permissions.
- Ships Netlify/Vercel security headers, including CSP, frame blocking, MIME sniffing protection, referrer policy, and restricted browser permissions.
For unrestricted package experiments, clone the repo and set:
VITE_ENABLE_OPEN_NPM=truecode-playground/
βββ src/
β βββ components/
β β βββ FileTree.tsx # File tree with hover actions
β β βββ FileToolbar.tsx # Top toolbar with file operations
β β βββ CodeEditor.tsx # CodeMirror 6 editor wrapper
β β βββ Preview.tsx # Live preview with iframe
β β βββ Console.tsx # Console output panel
β β βββ PackageManager.tsx # NPM package search & install
β β βββ TemplateModal.tsx # Template selection dialog
β βββ store/
β β βββ fileSystemStore.ts # Zustand store (files, packages, templates)
β βββ types/
β β βββ fileSystem.ts # TypeScript type definitions
β βββ utils/
β β βββ bundler.ts # ESBuild bundler with plugins
β β βββ npmApi.ts # NPM registry API wrapper
β β βββ dependencyResolver.ts # Peer dependency resolver
β β βββ templates/ # Project templates
β β β βββ index.ts # Template exports
β β β βββ types.ts # Template types
β β β βββ defaultTemplate.ts # Plain React template
β β β βββ muiTemplate.ts # Material UI template
β β βββ resolvers/ # Dependency resolvers
β β βββ index.ts # Resolver factory
β β βββ baseResolver.ts # Standard React resolver
β β βββ muiResolver.ts # MUI with external handling
β βββ App.tsx # Main app with layout
β βββ main.tsx # Entry point
β βββ index.css # Global styles
βββ public/
β βββ esbuild.wasm # ESBuild WebAssembly binary
βββ index.html
βββ package.json
βββ tailwind.config.js
βββ tsconfig.json
βββ vite.config.ts
- Click the Templates button (layers icon) in the top toolbar
- Select from available templates:
- Plain React: Lightweight starter with gradient UI
- Material UI: Full MUI setup with component examples
- Confirm to replace all files (warning: this clears current work)
From Toolbar:
- Click "New File" or "New Folder" in the top toolbar
- Enter name and press Enter (or click Create)
From File Tree (Hover Actions):
- Hover over any folder in the tree
- Click the folder/file icon that appears
- Type name inline and press Enter
- Press Escape to cancel
- Click any file in the tree to open it
- Start typing in the editor
- Changes auto-save to state
- Preview updates automatically
Hover over any folder:
- π New File button
- π New Folder button
- βοΈ Rename button (folders only)
- ποΈ Delete button
Hover over any file:
- ποΈ Delete button
- Click the Dependencies button to expand the panel
- Search for packages in the search box
- Click Add on any package
- Select version and click Install
- Package and dependencies auto-install
- View installed packages in the list
- Hover and click trash icon to uninstall
// Just import them in your code
import { Button } from "@mui/material";
import axios from "axios";
// They'll be automatically resolved via esm.sh- Console logs appear automatically in the bottom panel
- Color-coded: errors (red), warnings (yellow), info (blue), logs (white)
- Click "Clear" to clear console output
- Toggle with chevron icon to expand/collapse
- File Changes β Zustand store updates
- Bundler Triggered β ESBuild compiles JSX/TSX to JS
- Dependency Resolution β Appropriate resolver detects package type
- Import Map Generation β Creates ESM import map for esm.sh
- Code Injection β Bundles with React runtime and user code
- Iframe Render β Sandboxed execution with console capture
The app automatically selects the right resolver based on installed packages:
Base Resolver (default):
- Standard React packages
- Uses
https://esm.sh/package@versionformat
MUI Resolver (when MUI detected):
- Adds
?external=react,react-domto prevent multiple React instances - Handles
@emotion/*packages properly - Adds JSX runtime for Emotion
- In-memory file structure stored in Zustand
- ESBuild plugin resolves imports from virtual FS
- Supports relative imports:
import './Component' - Package imports resolved via import maps
- β Hierarchical file system with CRUD operations
- β Nested folders with hover actions
- β CodeMirror 6 code editor with syntax highlighting
- β Resizable panels (horizontal & vertical)
- β File type icons
- β Auto-save functionality
- β TypeScript/JSX/TSX support
- β Dark theme UI
- β Live preview with iframe isolation
- β Console output capture
- β React 18 execution with JSX
- β ESM package imports via esm.sh
- β NPM package search and install
- β Automatic peer dependency resolution
- β Multiple project templates
- β Material UI support with proper external handling
- β Template switching with state reset
- TypeScript type checking in editor
- Multiple file upload/import
- Export project as ZIP
- Share playground via URL
- Dark/Light theme toggle
- More templates (Vue, Svelte, Solid)
- Code formatting (Prettier)
- Cloud save/load projects
- Check browser console for errors
- Ensure all imports are installed in Dependencies panel
- Try clearing console and refreshing
- Verify package name is correct on npm
- Check if package has peer dependencies that conflict
- Some packages may not work in browser environment
- Ensure you're using the Material UI template
- Check that
@emotion/reactand@emotion/styledare installed - The app uses the MUI resolver automatically when MUI is detected
- The editor shows syntax highlighting but doesn't do type checking yet
- TypeScript/TSX files are transpiled to JavaScript for execution
- Type errors won't prevent code from running
- Use Cmd/Ctrl + S - Auto-saves, but manual save triggers re-bundle
- Hover over folders to reveal quick actions
- Drag panel borders to resize sections
- Check console output for runtime errors
- Install packages before importing them
- Templates come with working examples to start from
Contributions are welcome! Feel free to open issues or submit PRs.