An open source design system that's fully customizable and agent ready
TypeScript
fix(sandbox): add dual dev modes — source (hot reload) and watch (correct theming) (#862)
Cindy Zhang983807472af8
diff --git a/apps/sandbox/README.md b/apps/sandbox/README.mdindex 3dc9f25980..543970ded9 100644--- a/apps/sandbox/README.md+++ b/apps/sandbox/README.md@@ -51,15 +51,40 @@ export default function MyPage() {The page will appear in the sidebar and get its own URL in the PR deployment.-## Local development+## Development++Three ways to run the sandbox locally, depending on what you're iterating on:++### Quick start (build once, then dev)++```bash+yarn dev:sandbox+```++Builds `@xds/core` once, then starts the sandbox. Edits to `packages/core/src/` require a manual rebuild (`yarn build`). Good for working on sandbox pages themselves without touching core components.++### Source mode (fast hot reload, no theming)```bash-# From repo root+yarn dev:sandbox:source+```++Resolves `@xds/core` from TypeScript source directly via the `"source"` exports condition. Edits to component source hot-reload instantly (~200ms). **Theming and CSS layers don't work** in this mode because the CSS `@layer` wrapping only exists in the built dist output. Use for layout and behavior iteration only.++### Watch mode (correct theming, near-hot-reload)++Run in two terminals:++```bash+# Terminal 1: watch core for changes, rebuild dist incrementally+yarn workspace @xds/core dev++# Terminal 2: start sandbox (uses dist with correct CSS layers)yarn workspace @xds/sandbox dev-# or-cd apps/sandbox && yarn dev```+Best of both worlds — edits trigger incremental dist rebuilds via tsup (a few seconds), and CSS layer ordering is correct. Theming works properly.+## File manifest| File | Purpose |diff --git a/apps/sandbox/next.config.mjs b/apps/sandbox/next.config.mjsindex 476006fcdb..036ff9fdd9 100644--- a/apps/sandbox/next.config.mjs+++ b/apps/sandbox/next.config.mjs@@ -1,11 +1,28 @@+/**+ * @file next.config.mjs+ * @description Next.js configuration for the XDS sandbox app.+ *+ * Supports two dev modes controlled by the XDS_SOURCE env var:+ *+ * - **Default** (XDS_SOURCE unset): Resolves @xds/core from dist/.+ * CSS layers and theming work correctly. Pair with `yarn workspace @xds/core dev`+ * in a second terminal for near-hot-reload via incremental dist rebuilds.+ *+ * - **Source mode** (XDS_SOURCE=1): Resolves @xds/core from TypeScript source.+ * Instant hot reload (~200ms), but CSS layer separation is lost — theming+ * won't work. Best for layout and behavior iteration.+ */++const useSource = process.env.XDS_SOURCE === '1';+/** @type {import('next').NextConfig} */const nextConfig = {output: 'export',trailingSlash: true,basePath: process.env.SANDBOX_BASE_PATH || '',- // Theme packages still need transpilation for defineTheme() calls.- // @xds/core uses pre-built dist — no transpilation needed.transpilePackages: [+ // Only transpile @xds/core in source mode — in dist mode, it's pre-built.+ ...(useSource ? ['@xds/core'] : []),'@xds/theme-default','@xds/theme-neutral','@xds/theme-brutalist',@@ -16,6 +33,34 @@ const nextConfig = {typescript: {ignoreBuildErrors: false,},+ webpack: useSource+ ? (config) => {+ // Prefer "source" exports condition so @xds/core resolves to src/ TypeScript.+ // This enables hot reload when editing packages/core/src/ files.+ config.resolve.conditionNames = [+ 'source',+ 'import',+ 'require',+ 'default',+ ];++ // Remove packages/core from snapshot managedPaths so webpack+ // doesn't treat it as an immutable dependency.+ config.snapshot = {+ ...config.snapshot,+ managedPaths: [],+ };++ // Poll as fallback — FSEvents can miss changes through symlinks.+ config.watchOptions = {+ ...config.watchOptions,+ poll: 1000,+ followSymlinks: true,+ };++ return config;+ }+ : undefined,};export default nextConfig;diff --git a/package.json b/package.jsonindex ae6fd9c548..37b893c3a2 100644--- a/package.json+++ b/package.json@@ -27,7 +27,9 @@"version-packages": "changeset version","verify-exports": "node scripts/verify-exports.mjs","release": "yarn build && changeset publish",- "prepare": "husky install"+ "prepare": "husky install",+ "dev:sandbox": "yarn workspace @xds/core build && yarn workspace @xds/sandbox dev",+ "dev:sandbox:source": "XDS_SOURCE=1 yarn workspace @xds/sandbox dev"},"devDependencies": {"@axe-core/playwright": "^4.11.1",