mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-15 22:32:13 +00:00
setBaseImageInfo updates baseImageInfo synchronously and only swaps in baseImageBitmap once the <img> finishes loading. During that gap the canvas still renders the previous bitmap while baseImageInfo.mediaToken already points at the new image — clicking Generate would send the new image's token alongside a mask drawn over the old pixels (inpaint path) or fail silently (composite path). Worse, with no cancellation, a stale onload from a previous selection could fire after the user moved on, overwriting baseImageBitmap (and via applyImageNodes, drawNodes) with the wrong content. Add a module-level generation counter in SceneState; bump on every setBaseImageInfo and guard onload/onerror so superseded loads no-op. Wire PageDraw's <PromptEditor isDisabled> to (!baseImageBitmap && !baseImageInfo?.isBlankCanvas) so the button visibly reflects this. Connect PromptBox2D's existing isDisabled prop to the button's disabled attribute (it was already checked in handleGenerate but never visualized). Drop the latest-ref pattern around baseImageBitmap/baseImageInfo in PageDraw; getCompositeCanvasFile now reads the live snapshot via useSceneStore.getState() which is the simpler answer for state that already lives in Zustand.