fix(ui/events): keep the open step alive across tab switches

Each switch remounted the panel under `<component :is>`'s key, so it
started with no data and showed its skeleton before the read landed.
KeepAlive keeps every visited step mounted, so returning shows what it
already read. A step that is only polled (Events) pauses while hidden.
This commit is contained in:
sam committed 2026-11-26 01:59:29 +11:00
1 parent eb7d852567
commit bc031880bf
2 files changed
+13 -4

No files matched your search

+6 -1
View File
@@ -117,7 +117,12 @@ const panel = computed(() => PANELS[active.value]);
</TabsList>
</Tabs>
<component :is="panel" v-if="panel" :key="active" />
<!-- Kept alive so returning to a step shows what it already read rather
than its skeleton again. Each panel reads on mount and only on a live
event after that. -->
<KeepAlive v-if="panel">
<component :is="panel" :key="active" />
</KeepAlive>
<Empty v-else>
<EmptyHeader>
<EmptyTitle>Event automation is not enabled</EmptyTitle>
+7 -3
View File
@@ -1,4 +1,4 @@
import { onScopeDispose, ref, shallowRef, type Ref, type ShallowRef } from "vue";
import { onActivated, onDeactivated, onScopeDispose, ref, shallowRef, type Ref, type ShallowRef } from "vue";
import { errors } from "@/copy/errors";
import { describeError } from "./api";
@@ -37,10 +37,14 @@ export function useRead<T>(read: () => Promise<T>): Read<T> {
}
/** usePoll re-reads every intervalMs while the tab is visible, for views
* whose data the live stream does not carry. */
* whose data the live stream does not carry. A view kept alive by KeepAlive
* pauses while it is hidden, so every visited tab is not polling at once. */
export function usePoll(reload: () => unknown, intervalMs = 5000): void {
let shown = true;
onActivated(() => (shown = true));
onDeactivated(() => (shown = false));
const timer = setInterval(() => {
if (!document.hidden) void reload();
if (shown && !document.hidden) void reload();
}, intervalMs);
onScopeDispose(() => clearInterval(timer));
}