Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Show a busy state on any button the moment its tap reaches the server (#12781)

[._.]/be4e01cd2924
diff --git a/client/src/components/Layout.jsx b/client/src/components/Layout.jsx
index eec172c0c6..bcfc746ca5 100644
--- a/client/src/components/Layout.jsx
+++ b/client/src/components/Layout.jsx
@@ -71,6 +71,7 @@ import KeyboardHelp from './KeyboardHelp';
import VoiceWidget from './voice/VoiceWidget';
import { openCmdKSearch } from '../hooks/useCmdKSearch.js';
import SidebarContext from './SidebarContext.jsx';
+import ActionActivityBar from './ui/ActionActivityBar';
function ThemeModeToggle({ className = '' }) {
const { theme, toggleMode } = useThemeContext();
@@ -1106,6 +1107,7 @@ export default function Layout() {
})()}
</div>
{/* Cmd+K search overlay — mounted in layout so it's available on every page */}
+ <ActionActivityBar />
<CmdKSearch />
{/* Keyboard shortcuts help — press ? to toggle */}
<KeyboardHelp />
diff --git a/client/src/components/ui/ActionActivityBar.jsx b/client/src/components/ui/ActionActivityBar.jsx
new file mode 100644
index 0000000000..239356f750
--- /dev/null
+++ b/client/src/components/ui/ActionActivityBar.jsx
@@ -0,0 +1,30 @@
+import { useEffect, useState, useSyncExternalStore } from 'react';
+import { getPendingActionCount, subscribePendingActions } from '../../services/actionFeedback';
+
+// How long a tap-started request runs before the bar appears; quicker actions
+// finish on the button's own busy state without a second indicator.
+const SHOW_AFTER_MS = 300;
+
+// Thin indeterminate bar along the top of the app while any tap-started
+// request is in flight, so an action whose button has scrolled away or
+// unmounted (a closed drawer, a submitted modal) still visibly works.
+export default function ActionActivityBar() {
+ const pending = useSyncExternalStore(subscribePendingActions, getPendingActionCount) > 0;
+ const [visible, setVisible] = useState(false);
+
+ useEffect(() => {
+ if (!pending) {
+ setVisible(false);
+ return undefined;
+ }
+ const timer = setTimeout(() => setVisible(true), SHOW_AFTER_MS);
+ return () => clearTimeout(timer);
+ }, [pending]);
+
+ if (!visible) return null;
+ return (
+ <div role="progressbar" aria-label="Working" className="action-activity-bar fixed inset-x-0 top-0 z-[60] h-0.5 overflow-hidden pointer-events-none">
+ <div className="action-activity-bar__fill h-full w-1/3 bg-port-accent" />
+ </div>
+ );
+}
diff --git a/client/src/components/ui/README.md b/client/src/components/ui/README.md
index 1130d5848f..de321e3182 100644
--- a/client/src/components/ui/README.md
+++ b/client/src/components/ui/README.md
@@ -8,6 +8,7 @@ accessibility). Feature-specific components live under their own feature directo
| Component | What it's for |
| --- | --- |
+| `ActionActivityBar` | Thin indeterminate bar at the top of the app while a tap-started request (`services/actionFeedback.js`) runs past 300ms. Mounted once in `Layout`. |
| `AutoSizeTextarea` | Controlled `<textarea>` that grows to fit its content — no internal scroll, no hand-resize. |
| `Banner` | Toned alert block (icon + content + actions) for warnings, errors, and info callouts. |
| `SettingsLoadError` | Inline "failed to load saved settings" banner with Retry; pair with a disabled Save so defaults are never written over stored values. |
diff --git a/client/src/index.css b/client/src/index.css
index 5b1e493a8e..b04d987e6e 100644
--- a/client/src/index.css
+++ b/client/src/index.css
@@ -2113,3 +2113,42 @@ input[type="color"],
0%, 100% { transform: translateY(0) scale(1); opacity: 0.3; }
50% { transform: translateY(-10px) scale(1.5); opacity: 0.8; }
}
+
+/* A button whose tap started a request still in flight (services/actionFeedback.js).
+ A sweeping highlight rather than a spinner: it needs no layout room, no
+ positioning context, and works on every button shape. */
+[data-pending="true"] {
+ cursor: progress;
+ background-image: linear-gradient(100deg, transparent 35%, rgb(255 255 255 / 0.22) 50%, transparent 65%);
+ background-size: 250% 100%;
+ background-repeat: no-repeat;
+ animation: portos-pending-sweep 1.1s linear infinite;
+}
+
+@keyframes portos-pending-sweep {
+ from { background-position: 100% 0; }
+ to { background-position: -150% 0; }
+}
+
+.action-activity-bar__fill {
+ animation: portos-activity-slide 1.2s ease-in-out infinite;
+}
+
+@keyframes portos-activity-slide {
+ from { transform: translateX(-100%); }
+ to { transform: translateX(300%); }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ [data-pending="true"] {
+ animation: none;
+ background-image: none;
+ opacity: 0.7;
+ }
+
+ .action-activity-bar__fill {
+ animation: none;
+ width: 100%;
+ opacity: 0.6;
+ }
+}
diff --git a/client/src/main.jsx b/client/src/main.jsx
index 7172c8e8ac..f3a7632d4e 100644
--- a/client/src/main.jsx
+++ b/client/src/main.jsx
@@ -10,6 +10,7 @@ import { ThemeProvider } from './components/ThemeContext';
import { isStaleChunkError, reloadOnceForStaleChunk } from './utils/staleChunkReload';
import { reportClientError } from './lib/clientErrorReporter';
import { registerServiceWorker } from './lib/registerServiceWorker';
+import { installActionFeedback } from './services/actionFeedback';
import DownloadManager from './components/DownloadManager';
import App from './App';
import './index.css';
@@ -18,6 +19,9 @@ import './index.css';
// only — no-op in dev and over plain-HTTP Tailnet). See lib/registerServiceWorker.
registerServiceWorker();
+// Tapped buttons show a busy state while the request they started is in flight.
+installActionFeedback();
+
// Start checking for a newer build as soon as a chunk preload fails. Vite also
// emits this for module evaluation errors, so the recovery helper reloads only
// after the live shell confirms this tab is stale.
diff --git a/client/src/services/README.md b/client/src/services/README.md
index 5cb4469808..1c269ebe7f 100644
--- a/client/src/services/README.md
+++ b/client/src/services/README.md
@@ -31,6 +31,7 @@ toasts on throw). **Custom catch ⇒ `silent: true`** — otherwise toasts fire
| `api.js` | Barrel — re-exports every `apiX.js`. |
| `apiCore.js` | `request()` and `uploadBody()` (stream File/Blob multipart; legacy base64 JSON) + stable PortOS-app id. Shared error / toast handling. |
| `apiBatch.js` | `fetchByIds(path, ids, options)` — batch-fetch records through a list route's `?ids=a,b,c` filter (dedupe, empty-list short-circuit, `{ items }` envelope unwrap). |
+| `actionFeedback.js` | Marks the button whose click/submit started a `request()` as `data-pending` until it settles (never `aria-busy`, which stays component-owned) (styled in `index.css`), and counts those requests for `ActionActivityBar`. Installed once from `main.jsx`; no per-component opt-in. |
| `socket.js` | Singleton Socket.IO client over relative path (Tailscale-friendly). |
| `appUrls.js` | Compute candidate launch URLs for an app from page context. |
diff --git a/client/src/services/actionFeedback.js b/client/src/services/actionFeedback.js
new file mode 100644
index 0000000000..7c72a5956d
--- /dev/null
+++ b/client/src/services/actionFeedback.js
@@ -0,0 +1,83 @@
+// Instant feedback for taps that wait on the server. A request started from a
+// button's click (or a form's submit) marks that button `data-pending` until
+// the request settles, so every action button shows it is working the moment
+// it is tapped, with no per-component state. `request()` reports each call
+// here; nothing else needs to opt in.
+
+// Element whose click/submit is being dispatched right now. Cleared on the
+// next macrotask, which runs after the handler's synchronous body and its
+// microtasks, so only requests that handler started are attributed to it.
+let currentTrigger = null;
+let clearTimer = null;
+const pendingByElement = new WeakMap();
+let pendingCount = 0;
+const listeners = new Set();
+
+const notify = () => {
+ for (const listener of listeners) listener();
+};
+
+const setTrigger = (element) => {
+ if (!element) return;
+ currentTrigger = element;
+ clearTimeout(clearTimer);
+ clearTimer = setTimeout(() => { currentTrigger = null; }, 0);
+};
+
+const triggerFromEvent = (event) => {
+ if (event.type === 'submit') {
+ // Some engines report the form itself as the submitter of requestSubmit().
+ const { submitter } = event;
+ if (submitter && submitter !== event.target) return submitter;
+ return event.target?.querySelector?.('button[type="submit"], button:not([type])') ?? null;
+ }
+ return event.target?.closest?.('button, [role="button"]') ?? null;
+};
+
+let installed = false;
+export function installActionFeedback(doc = globalThis.document) {
+ if (installed || !doc) return;
+ installed = true;
+ const capture = (event) => setTrigger(triggerFromEvent(event));
+ doc.addEventListener('click', capture, true);
+ doc.addEventListener('submit', capture, true);
+}
+
+// Only `data-pending` is set here. `aria-busy` stays with components that
+// manage it: a button that sets its busy state in the same click hasn't
+// committed it yet when the request starts, so this module could not tell its
+// attribute from one it added, and removing it on settle would strip a busy
+// state the component still holds. ActionActivityBar announces long waits.
+const markPending = (element, delta) => {
+ const count = (pendingByElement.get(element) ?? 0) + delta;
+ if (count > 0) {
+ pendingByElement.set(element, count);
+ element.setAttribute('data-pending', 'true');
+ } else {
+ pendingByElement.delete(element);
+ element.removeAttribute('data-pending');
+ }
+};
+
+// Wraps one in-flight request. Returns the same promise.
+export function trackRequest(promise) {
+ const element = currentTrigger;
+ if (!element) return promise;
+ markPending(element, 1);
+ pendingCount += 1;
+ notify();
+ const settle = () => {
+ markPending(element, -1);
+ pendingCount -= 1;
+ notify();
+ };
+ promise.then(settle, settle);
+ return promise;
+}
+
+// Count of tap-started requests still in flight, for the global activity bar.
+export const getPendingActionCount = () => pendingCount;
+export function subscribePendingActions(listener) {
+ listeners.add(listener);
+ return () => listeners.delete(listener);
+}
diff --git a/client/src/services/actionFeedback.test.js b/client/src/services/actionFeedback.test.js
new file mode 100644
index 0000000000..b12ef65274
--- /dev/null
+++ b/client/src/services/actionFeedback.test.js
@@ -0,0 +1,68 @@
+import { describe, it, expect, beforeAll } from 'vitest';
+import { installActionFeedback, trackRequest, getPendingActionCount } from './actionFeedback.js';
+
+const deferred = () => {
+ let resolve; let reject;
+ const promise = new Promise((res, rej) => { resolve = res; reject = rej; });
+ return { promise, resolve, reject };
+};
+const nextTask = () => new Promise((resolve) => setTimeout(resolve, 0));
+
+describe('actionFeedback', () => {
+ beforeAll(() => installActionFeedback(document));
+
+ it('marks the tapped button busy until the request it started settles', async () => {
+ document.body.innerHTML = '<button id="b"><span id="icon">x</span></button>';
+ const button = document.getElementById('b');
+ const req = deferred();
+ button.addEventListener('click', () => trackRequest(req.promise));
+
+ document.getElementById('icon').click();
+ expect(button.getAttribute('data-pending')).toBe('true');
+ expect(getPendingActionCount()).toBe(1);
+
+ req.reject(new Error('boom'));
+ await req.promise.catch(() => {});
+ await nextTask();
+ expect(button.hasAttribute('data-pending')).toBe(false);
+ expect(getPendingActionCount()).toBe(0);
+ });
+
+ it('attributes a form submit to its submit button', async () => {
+ document.body.innerHTML = '<form id="f"><input name="q" /><button id="send">Send</button></form>';
+ const form = document.getElementById('f');
+ const req = deferred();
+ form.addEventListener('submit', (e) => { e.preventDefault(); trackRequest(req.promise); });
+
+ form.requestSubmit();
+ expect(document.getElementById('send').getAttribute('data-pending')).toBe('true');
+ req.resolve();
+ await req.promise;
+ await nextTask();
+ expect(document.getElementById('send').hasAttribute('data-pending')).toBe(false);
+ });
+
+ it('never touches a component-managed aria-busy', async () => {
+ document.body.innerHTML = '<button id="b" aria-busy="true">Run</button>';
+ const button = document.getElementById('b');
+ const req = deferred();
+ button.addEventListener('click', () => trackRequest(req.promise));
+ button.click();
+ req.resolve();
+ await req.promise;
+ await nextTask();
+ expect(button.hasAttribute('data-pending')).toBe(false);
+ expect(button.getAttribute('aria-busy')).toBe('true');
+ });
+
+ it('leaves background requests (no tap in this task) unattributed', async () => {
+ document.body.innerHTML = '<button id="b">Go</button>';
+ document.getElementById('b').click();
+ await nextTask();
+ const req = deferred();
+ trackRequest(req.promise);
+ expect(document.getElementById('b').hasAttribute('data-pending')).toBe(false);
+ expect(getPendingActionCount()).toBe(0);
+ req.resolve();
+ });
+});
diff --git a/client/src/services/apiCore.js b/client/src/services/apiCore.js
index f6f2981bf0..9178b16205 100644
--- a/client/src/services/apiCore.js
+++ b/client/src/services/apiCore.js
@@ -1,4 +1,5 @@
import toast from '../components/ui/Toast';
+import { trackRequest } from './actionFeedback.js';
export const API_BASE = '/api'; // exported for sub-modules that use fetch() directly
@@ -48,7 +49,13 @@ export async function throwApiError(response) {
throw err;
}
-export async function request(endpoint, options = {}) {
+// A request started from a tap marks the tapped button busy until it settles
+// (services/actionFeedback.js), so every action responds at once.
+export function request(endpoint, options = {}) {
+ return trackRequest(performRequest(endpoint, options));
+}
+
+async function performRequest(endpoint, options = {}) {
const { silent, responseType, ...fetchOptions } = options;
const url = `${API_BASE}${endpoint}`;
// Skip the JSON content-type header for FormData bodies — the browser must