Skip to content

Commit a0185cf

Browse files
committed
fix(app-shell): the lock read stays where an adapter is mounted, as before
Claude-Session: https://claude.ai/code/session_01J8VVAojjEQUUoMeSBSdgW4 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3c07cb8 commit a0185cf

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

‎ui/packages/app-shell/src/hooks/useRecordApprovals.ts‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343

4444
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
4545
import { createQuietHttpLogger } from '@object-ui/data-objectstack';
46+
import { useAdapter } from '../providers/AdapterProvider.js';
4647
import { bearerAuthHeaders } from '../utils/authToken.js';
4748
import type { DecisionOutputDef } from '../utils/decisionOutputParams.js';
4849

@@ -305,10 +306,10 @@ interface UseRecordApprovalsResult {
305306
* `{ locked: true }` means a pending approval whose node locks the record is
306307
* running, though this viewer cannot see its request. `null` when there is
307308
* no answer to give: a pending request was found (it decides, with its own
308-
* `lock_record`), or the read has never answered — a composition without
309-
* the approvals service answers it 501, so there the record is not locked
310-
* by this signal, and the read is not sent again. A later failed read keeps
311-
* the last answer, as the list read does.
309+
* `lock_record`), no adapter is mounted, or the read has never answered — a
310+
* composition without the approvals service answers it 501, so there the
311+
* record is not locked by this signal, and the read is not sent again. A
312+
* later failed read keeps the last answer, as the list read does.
312313
*/
313314
recordLock: { locked: boolean } | null;
314315
refresh: () => Promise<void>;
@@ -547,7 +548,7 @@ async function readRecordLock(objectName: string, recordId: string): Promise<{ l
547548
}
548549

549550
/** Send the record's read and publish its answer to every consumer of the key. */
550-
function startRead(key: string, objectName: string, recordId: string): Promise<void> {
551+
function startRead(key: string, objectName: string, recordId: string, readsLock: boolean): Promise<void> {
551552
const seq = ++readSeq;
552553
latestSeq.set(key, seq);
553554
const entry = entries.get(key);
@@ -567,7 +568,7 @@ function startRead(key: string, objectName: string, recordId: string): Promise<v
567568
// `lock_record`. Without one, ask the record itself (objectstack#25934):
568569
// the list hides a request from a non-participant, the lock does not.
569570
let recordLock: { locked: boolean } | null = null;
570-
if (!pending && !recordLockAbsent) {
571+
if (!pending && readsLock && !recordLockAbsent) {
571572
recordLock = entries.get(key)?.snapshot.recordLock ?? null;
572573
try {
573574
const lock = await readRecordLock(objectName, recordId);
@@ -637,6 +638,10 @@ export function useRecordApprovals(
637638
// for the render, mirrored into a ref the mount effect and `refresh` read.
638639
const [unavailable, setUnavailable] = useState(false);
639640
const unavailableRef = useRef(false);
641+
// The record lock is read only where an adapter is mounted — the console's
642+
// connection to an ObjectStack server; a host with none never asked it.
643+
const readsLock = !!useAdapter();
644+
640645
const subscribe = useCallback((l: () => void) => subscribeKey(readKey, l), [readKey]);
641646
const getSnapshot = useCallback(
642647
() => (readKey === null ? INITIAL_SNAPSHOT : entries.get(readKey)?.snapshot ?? INITIAL_SNAPSHOT),
@@ -658,19 +663,19 @@ export function useRecordApprovals(
658663
// read only when neither exists. The entry may be new while a read is in
659664
// flight (StrictMode's replayed mount): that read publishes into it.
660665
if (entry && !entry.read && !inFlight.has(readKey) && !unavailableRef.current) {
661-
void startRead(readKey, objectName, recordId);
666+
void startRead(readKey, objectName, recordId, readsLock);
662667
} else if (entry && inFlight.has(readKey)) {
663668
entry.read = true;
664669
if (!entry.snapshot.loading) publish(readKey, { loading: true });
665670
}
666671
return release;
667-
}, [readKey, objectName, recordId]);
672+
}, [readKey, objectName, recordId, readsLock]);
668673

669674
const refresh = useCallback(async () => {
670675
if (!objectName || !recordId || !readKey) return;
671676
if (unavailableRef.current) return;
672-
await startRead(readKey, objectName, recordId);
673-
}, [objectName, recordId, readKey]);
677+
await startRead(readKey, objectName, recordId, readsLock);
678+
}, [objectName, recordId, readKey, readsLock]);
674679

675680
const requests = readKey === null ? EMPTY_ROWS : snapshot.rows;
676681
const loading = snapshot.loading;

0 commit comments

Comments
 (0)