diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index b611f9f66c..4efb5e9a03 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -106,6 +106,7 @@ script = $bindable(), fullyLoaded = true, initialPath = $bindable(''), + userDraftPath = '', template = $bindable('script'), initialArgs = {}, lockedLanguage = false, @@ -348,10 +349,12 @@ // editor with the template's `initialCode` is a programmatic // write that shouldn't count as the user's "first edit" and // shouldn't POST to the server. The route's UserDraft handle is - // keyed by `initialPath` (the URL path). Resumed in the async - // `.finally` so language switches AFTER bootstrap (which also - // call `initContent`) sync normally. - UserDraft.stopSync('script', initialPath) + // keyed by `userDraftPath` (the URL path), distinct from + // `initialPath` which is the editor-displayed path (empty for + // new drafts). Resumed in the async `.finally` so language + // switches AFTER bootstrap (which also call `initContent`) sync + // normally. + UserDraft.stopSync('script', userDraftPath) if (template === 'wac_python') { script.modules = { 'helper.py': { @@ -368,7 +371,7 @@ } } initContent(script.language, script.kind, template).finally(() => { - UserDraft.restartSync('script', initialPath) + UserDraft.restartSync('script', userDraftPath) }) } diff --git a/frontend/src/lib/components/script_builder.ts b/frontend/src/lib/components/script_builder.ts index fc6e31ffa2..79dfd9db89 100644 --- a/frontend/src/lib/components/script_builder.ts +++ b/frontend/src/lib/components/script_builder.ts @@ -15,6 +15,18 @@ export interface ScriptBuilderProps { disableAi?: boolean fullyLoaded?: boolean initialPath?: string + /** + * Path the route's `UserDraft.use('script', ...)` + * handle is keyed by. Distinct from `initialPath` for new drafts — + * `initialPath` is the displayed/editor path (empty for new), while + * this is the URL path the draft is persisted under (`u/{user}/ + * draft_{uuid}`). Used to bracket the bootstrap `initContent` write + * with `UserDraft.stopSync` / `restartSync` so the template seed + * doesn't POST before the user's first real edit. Default to `''` + * for backwards compat with callers that don't manage drafts; the + * stop/restart pair is a no-op on a non-live entry. + */ + userDraftPath?: string template?: | 'docker' | 'bunnative' diff --git a/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte index c7851a7537..f247e2c8b5 100644 --- a/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/scripts/edit/[...path]/+page.svelte @@ -344,6 +344,7 @@