-
Notifications
You must be signed in to change notification settings - Fork 56
Description
Bug Description
After calling project.generate() with a comprehensive app prompt, project.screens() consistently returns an empty array — even though screens were successfully created on the Stitch backend. The screens only become visible via the SDK after the project is manually opened in the Stitch web UI (stitch.google.com).
Steps to Reproduce
import { StitchToolClient, Stitch } from "@google/stitch-sdk";
const client = new StitchToolClient({
apiKey: process.env.STITCH_API_KEY,
timeout: 300_000,
});
const sdk = new Stitch(client);
// 1. Create project
const project = await sdk.createProject("My App");
console.log("Project ID:", project.projectId);
// 2. Generate screens (blocks until complete)
try {
await project.generate(fullPrompt, "MOBILE");
} catch (err) {
// Known: SDK throws "Cannot read properties of undefined (reading 'screens')"
// but the screens ARE created on Stitch's side
console.log("generate() threw (expected):", err.message);
}
// 3. List screens — returns empty
const screens = await project.screens();
console.log("Screens found:", screens.length); // Always 0
// 4. Retry after delays — still empty
await new Promise(r => setTimeout(r, 15000));
const retry = await project.screens();
console.log("Retry screens:", retry.length); // Still 0
// 5. WORKAROUND: Open the project in stitch.google.com, then:
const afterWebUI = await project.screens();
console.log("After opening web UI:", afterWebUI.length); // Now returns screens!Expected Behavior
project.screens() should return the generated screens after generate() completes, without requiring the project to be opened in the web UI first.
Actual Behavior
generate()throwsCannot read properties of undefined (reading 'screens')(separate known bug — the screen IS created despite the error)project.screens()returns[]regardless of how long you wait (tested up to 60 seconds with multiple retries)- Opening the project in the Stitch web UI "activates" it — after that,
project.screens()returns the expected screens - Re-downloading via
project.screens()after the web UI visit works perfectly
Workaround
Open the Stitch project in the web UI (stitch.google.com) before calling project.screens(). After that, the SDK returns screens correctly. In our app we show a "Re-download from Stitch" button that the user can click after visiting the web UI.
Environment
@google/stitch-sdk:0.0.3- Node.js: v22
- Using
new StitchToolClient()+new Stitch(client)(not the singleton)
Related
This may be related to the generate() parsing error (Cannot read properties of undefined (reading 'screens')) — if generate() returned the screen object correctly, we wouldn't need to call project.screens() at all.