mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
Each behaviour here was verified by removing the code that provides it and confirming the test went red, then putting it back. Two of them did not, and both were rewritten rather than kept: The restore-side persister check asserted that the delegate's own dashboard could not be read back inside a shared record. Deleting the guard left it green, because the record-scoped hash already makes a snapshot written in one record unreadable in another. It now counts what landed in the cache, so the guard it names is the thing it measures — and the weaker line is kept beside it with a note saying why. The switcher's account rows were asserted from server-rendered markup. Radix portals do not render server-side at all, so an earlier draft was measuring the renderer. Those rows moved to the browser suite; what stays here is the gate, which fails sharply — with the `canSwitch` bail removed the two cases do not return different markup, they throw. Two more shapes worth naming. The cache dimension is exercised through a real QueryClient built from the app's own defaults, because "the hash string changed" and "one record's data cannot be read while inside another" are different claims. And the invalidation is a plain function over a client with three live entries seeded, with a test that asserts they start valid — without it, a client that failed to seed and one where everything was invalidated look the same from every other assertion.
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
"use client";
|
|
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import { useEffect } from "react";
|
|
|
|
import {
|
|
subscribeToGrantLoss,
|
|
useLeaveSharedRecordOnGrantLoss,
|
|
} from "@/hooks/use-account-switch";
|
|
|
|
/**
|
|
* v1.36.0 — leave a record the server has stopped honouring.
|
|
*
|
|
* The switcher reset the contract asks for. A grant can end at any moment: the
|
|
* owner presses revoke, or an expiry passes. Revocation clears the delegate's
|
|
* acting sessions in the same transaction, so that path lands them back in
|
|
* their own account by itself. **Expiry does not** — nothing sweeps, the grant
|
|
* simply stops being live on the next request, and the session keeps its stamp.
|
|
* A browser in that state gets a 403 on every read while the banner still says
|
|
* it is inside somebody's record. Correct refusals under a screen that lies.
|
|
*
|
|
* So one subscriber watches the query cache for the stable
|
|
* `sharing.access.denied` code and, on the first one, clears the switch and
|
|
* reloads. Watching the cache rather than asking ~200 call sites to handle a
|
|
* code is the point: a per-call-site handler is a rule the next feature
|
|
* forgets, and forgetting it here means somebody is stuck.
|
|
*
|
|
* Fires once — `subscribeToGrantLoss` owns that, because `landOnRecord` never
|
|
* resolves (the document is being replaced) and a second trigger would queue a
|
|
* second reload behind a navigation already in flight.
|
|
*/
|
|
export function SharedRecordGrantLossBridge() {
|
|
const queryClient = useQueryClient();
|
|
const leave = useLeaveSharedRecordOnGrantLoss();
|
|
|
|
useEffect(
|
|
() => subscribeToGrantLoss(queryClient, () => void leave()),
|
|
[queryClient, leave],
|
|
);
|
|
|
|
return null;
|
|
}
|