fix: open an older script version without flashing the Archived alert (#12497)

* fix: open an older script version without flashing the Archived alert

Opening an older version of a script showed "Archived: This path was archived" until the
latest version at its path was fetched, then "Not HEAD". Resolve that latest version before
setting the script, so the page renders both together.

* fix: drop a superseded script load so it cannot overwrite a newer one
This commit is contained in:
Raunak Burrows
2026-11-18 18:07:09 +01:00
committed by GitHub
parent 8984bccf83
commit 3cc2f16dd1
@@ -52,6 +52,7 @@
import { PLAN_MODE_MESSAGES } from '$lib/components/copilot/chat/planModeMessages'
import { sendUserToast } from '$lib/toast'
import { latestRequest } from '$lib/utils/latestRequest'
import NoDirectDeployAlert from '$lib/components/NoDirectDeployAlert.svelte'
import DeployWorkspaceDrawer from '$lib/components/DeployWorkspaceDrawer.svelte'
@@ -277,12 +278,16 @@
await triggersState.fetchTriggers(triggersCount, workspace, path, false)
}
// A slower load for an earlier version must not overwrite the one the page has moved on to.
const scriptLoads = latestRequest()
async function loadScript(hash: string): Promise<void> {
const isLatest = scriptLoads.start()
// Check if this is a hub script path
if (hash.startsWith('hub/')) {
isHubScript = true
try {
const hubScript = await ScriptService.getHubScriptByPath({ path: hash })
if (!isLatest()) return
// Create a partial Script object from hub script data
script = {
hash: '',
@@ -312,8 +317,9 @@
}
isHubScript = false
let loaded: Script
try {
script = await ScriptService.getScriptByHash({
loaded = await ScriptService.getScriptByHash({
workspace: workspace!,
hash,
withStarredInfo: true,
@@ -321,13 +327,14 @@
})
} catch {
try {
script = await ScriptService.getScriptByPath({
loaded = await ScriptService.getScriptByPath({
workspace: workspace!,
path: hash,
withStarredInfo: true
})
hash = script.hash
hash = loaded.hash
} catch (e) {
if (!isLatest()) return
// A path with no deployed script 404s here, which is the normal state of a
// draft the user has not deployed — the host says so rather than the page
// staying blank, so no toast for it. Anything else is a real failure.
@@ -336,6 +343,21 @@
return
}
}
// Set together with `script`: an archived script whose `topHash` is not known yet renders
// as an archived path, so an older version would show the "Archived" alert until it is.
let nextTopHash: string | undefined = undefined
if (loaded.path && loaded.archived) {
const script_by_path = await ScriptService.getScriptByPath({
workspace: workspace!,
path: loaded.path
}).catch((_) => console.error('this script has no non-archived version'))
if (script_by_path?.hash != loaded.hash) {
nextTopHash = script_by_path?.hash
}
}
if (!isLatest()) return
script = loaded
topHash = nextTopHash
// A carried non-template value equal to the resolution of the script's own dynamic
// tag for these args is not an override but the previous run's pinned resolution:
// drop it so the backend re-resolves from the (possibly edited) args. A differing
@@ -354,17 +376,6 @@
}
loadTriggers(script.path)
if (script.path && script.archived) {
const script_by_path = await ScriptService.getScriptByPath({
workspace: workspace!,
path: script.path
}).catch((_) => console.error('this script has no non-archived version'))
if (script_by_path?.hash != script.hash) {
topHash = script_by_path?.hash
}
} else {
topHash = undefined
}
intervalId && clearInterval(intervalId)
deploymentInProgress = script.lock == undefined && script.lock_error_logs == undefined
if (deploymentInProgress) {