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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: compose back-to-back lock toggles that land in the same tick (#3290)
[._.]/ Adam Eivy867bcde2b261
diff --git a/client/src/hooks/useUniverseDraft.js b/client/src/hooks/useUniverseDraft.jsindex d84f2027ed..e4eec0d4ff 100644--- a/client/src/hooks/useUniverseDraft.js+++ b/client/src/hooks/useUniverseDraft.js@@ -482,6 +482,12 @@ export default function useUniverseDraft({ selectedId, goToWorld }) {const nextLocked = { ...(current.locked || {}) };if (nextLocked[field]) delete nextLocked[field];else nextLocked[field] = true;+ // Advance the mirror synchronously. The effect that syncs `draftRef` runs a+ // commit later, so two toggles inside one tick would otherwise both read the+ // pre-toggle map — the second re-sending the first's write instead of+ // composing on top of it. The functional updater still owns the draft+ // itself, so a concurrent edit to another field is not clobbered.+ draftRef.current = { ...current, locked: nextLocked };setDraft((value) => ({ ...value, locked: nextLocked }));if (selectedId && current.name?.trim()) {updateUniverse(selectedId, { locked: nextLocked }, { silent: true })diff --git a/client/src/hooks/useUniverseDraft.test.jsx b/client/src/hooks/useUniverseDraft.test.jsxindex aef424a4bf..f09aee0318 100644--- a/client/src/hooks/useUniverseDraft.test.jsx+++ b/client/src/hooks/useUniverseDraft.test.jsx@@ -686,6 +686,25 @@ describe('useUniverseDraft', () => {expect(result.current.draft.locked).toEqual({});});+ // Two clicks inside one tick: the lock map has to compose across them.+ // `draftRef` is normally refreshed by a passive effect that runs a commit+ // later, so a naive read of it would let the second toggle re-send the+ // first's write and leave the field locked forever.+ it('composes back-to-back toggles that land before a re-render', async () => {+ const { result } = renderDraft();+ await waitFor(() => expect(result.current.draft.id).toBe('u1'));++ act(() => {+ result.current.toggleLock('logline');+ result.current.toggleLock('logline');+ });++ expect(apiMocks.updateUniverse).toHaveBeenCalledTimes(2);+ expect(apiMocks.updateUniverse.mock.calls.map((call) => call[1]))+ .toEqual([{ locked: { logline: true } }, { locked: {} }]);+ expect(result.current.draft.locked).toEqual({});+ });+it('accepts the per-influence-list lock keys, not just the bible scalars', async () => {const { result } = renderDraft();await waitFor(() => expect(result.current.draft.id).toBe('u1'));