7973ee9ba8
The template-load sequence (clear canvas -> add components -> add pages -> apply header/footer) ran as a chain of setTimeout callbacks, but onClose() fired synchronously right after kicking it off. The modal disappeared immediately, so "Loading..." never had a chance to show, and the staged mutations kept running against a dialog the caller had already dismissed. Convert the staged steps to async/await (a promise-based `wait()` replaces the setTimeout chaining) and only call onClose() in a finally block once the whole sequence has settled. Add a mountedRef guard so the trailing setLoading(false) is skipped if the component happens to unmount mid-sequence. End result (pages/header/footer/ design applied) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>