Skip to content

Commit 63342c5

Browse files
authored
Reset app state on simulation switch, fix dev without dist (#20)
* Reset app state when switching simulations, fix dev without dist/ - Add selectedSimulationName to IframeResource key so iframe remounts when switching between simulations that share the same resource URL. Fixes review Approve/Cancel status persisting across simulation switches. - Add resolveAlias option to inspectServer and pass sunpeak/simulator source alias in workspace dev mode so pnpm dev works without a pre-built dist/ directory. * chore: bump sunpeak version in examples to 0.17.6 * Fix dev without dist/ for CSS: pass Tailwind plugin to inspector Also alias sunpeak/style.css and sunpeak/chatgpt/globals.css to source, and pass the Tailwind Vite plugin + lightningcss config so source CSS with @import "tailwindcss" is processed correctly.
1 parent 03b23d6 commit 63342c5

7 files changed

Lines changed: 28 additions & 8 deletions

File tree

examples/albums-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"clsx": "^2.1.1",
1616
"embla-carousel-react": "^8.6.0",
1717
"embla-carousel-wheel-gestures": "^8.1.0",
18-
"sunpeak": "^0.17.3",
18+
"sunpeak": "^0.17.6",
1919
"tailwind-merge": "^3.5.0",
2020
"zod": "^4.3.6"
2121
},

examples/carousel-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"clsx": "^2.1.1",
1616
"embla-carousel-react": "^8.6.0",
1717
"embla-carousel-wheel-gestures": "^8.1.0",
18-
"sunpeak": "^0.17.3",
18+
"sunpeak": "^0.17.6",
1919
"tailwind-merge": "^3.5.0",
2020
"zod": "^4.3.6"
2121
},

examples/map-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"clsx": "^2.1.1",
1616
"embla-carousel-react": "^8.6.0",
1717
"mapbox-gl": "^3.20.0",
18-
"sunpeak": "^0.17.3",
18+
"sunpeak": "^0.17.6",
1919
"tailwind-merge": "^3.5.0",
2020
"zod": "^4.3.6"
2121
},

examples/review-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"dependencies": {
1515
"clsx": "^2.1.1",
16-
"sunpeak": "^0.17.3",
16+
"sunpeak": "^0.17.6",
1717
"tailwind-merge": "^3.5.0",
1818
"zod": "^4.3.6"
1919
},

packages/sunpeak/bin/commands/dev.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,18 @@ if (import.meta.hot) {
526526
projectRoot,
527527
noBegging,
528528
open: !process.env.CI && !process.env.SUNPEAK_LIVE_TEST,
529+
// In workspace dev mode, resolve sunpeak imports to source files so the
530+
// inspector's Vite server works without a pre-built dist/ directory.
531+
// The Tailwind plugin is also passed so source CSS (@import "tailwindcss") is processed.
532+
...(isTemplate && {
533+
resolveAlias: {
534+
'sunpeak/simulator': resolve(parentSrc, 'simulator/index.ts'),
535+
'sunpeak/style.css': resolve(parentSrc, 'style.css'),
536+
'sunpeak/chatgpt/globals.css': resolve(parentSrc, 'chatgpt/globals.css'),
537+
},
538+
vitePlugins: [tailwindcss()],
539+
viteCssConfig: lightningcssConfig,
540+
}),
529541
// Direct tool handler call for Prod Tools Run button.
530542
// Re-imports via Vite SSR on each call so handlers pick up HMR changes.
531543
callToolDirect: async (name, args) => {

packages/sunpeak/bin/commands/inspect.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@ function readRequestBody(req) {
509509
* @param {boolean} [opts.open] - Whether to open browser (default: !CI && !SUNPEAK_LIVE_TEST)
510510
* @param {(name: string, args: Record<string, unknown>) => Promise<object>} [opts.callToolDirect] - Direct handler call (bypasses MCP, for prod-tools)
511511
* @param {() => Promise<void>} [opts.onCleanup] - Additional cleanup callback on exit
512+
* @param {Record<string, string>} [opts.resolveAlias] - Vite resolve aliases (e.g., to map sunpeak imports to source)
513+
* @param {object[]} [opts.vitePlugins] - Additional Vite plugins (e.g., Tailwind for source CSS)
514+
* @param {object} [opts.viteCssConfig] - Vite css config override (e.g., lightningcss customAtRules)
512515
*/
513516
export async function inspectServer(opts) {
514517
const {
@@ -523,6 +526,9 @@ export async function inspectServer(opts) {
523526
noBegging = false,
524527
open,
525528
onCleanup,
529+
resolveAlias,
530+
vitePlugins: extraVitePlugins = [],
531+
viteCssConfig,
526532
} = opts;
527533

528534
// Load favicon from sunpeak package for the inspector UI.
@@ -623,8 +629,11 @@ export async function inspectServer(opts) {
623629
const server = await createServer({
624630
root: SUNPEAK_PKG_DIR,
625631
configFile: false,
632+
...(resolveAlias ? { resolve: { alias: resolveAlias } } : {}),
633+
...(viteCssConfig ? { css: { lightningcss: viteCssConfig } } : {}),
626634
plugins: [
627635
react(),
636+
...extraVitePlugins,
628637
sunpeakInspectVirtualPlugin(
629638
simulations,
630639
simulatorServerUrl,

packages/sunpeak/src/simulator/simulator.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export function Simulator({
533533
content = (
534534
<div className="h-full w-full" style={{ background: iframeBg }}>
535535
<IframeResource
536-
key={`${state.activeHost}-${effectiveResourceUrl}-${prodResources}-${prodResourcesGeneration}`}
536+
key={`${state.activeHost}-${state.selectedSimulationName}-${effectiveResourceUrl}-${prodResources}-${prodResourcesGeneration}`}
537537
src={effectiveResourceUrl}
538538
hostContext={hostContext}
539539
toolInput={state.toolInput}
@@ -559,7 +559,7 @@ export function Simulator({
559559
content = (
560560
<div className="h-full w-full" style={{ background: iframeBg }}>
561561
<IframeResource
562-
key={`${state.activeHost}-${state.resourceScript}`}
562+
key={`${state.activeHost}-${state.selectedSimulationName}-${state.resourceScript}`}
563563
scriptSrc={state.resourceScript}
564564
hostContext={hostContext}
565565
toolInput={state.toolInput}
@@ -741,8 +741,7 @@ export function Simulator({
741741
{
742742
value: '__none__',
743743
label:
744-
selectedToolInfo &&
745-
selectedToolInfo.fixtureSimNames.length > 0
744+
selectedToolInfo && selectedToolInfo.fixtureSimNames.length > 0
746745
? 'None (call server)'
747746
: 'None',
748747
},

0 commit comments

Comments
 (0)