mirror of
https://github.com/block/buzz.git
synced 2026-11-25 10:42:26 +00:00
Three review findings against the tracer's honesty contract: - The readiness -> paint frame was unguarded. `awaitDeferredCommit` checks age, frame gap, and visibility on every frame it drives, but the one rAF it queues before `record()` checked neither age nor gap, so a suspension in that seam (App Nap fires no visibilitychange) recorded the whole absence as a clean switch. - DM actions await `open_dm` before `goChannel`, so that relay round-trip sat outside the measurement; Pulse's note actions used raw `navigate` and produced no measurement at all. Callers now capture the click anchor and hand it to `goChannel`, and Pulse routes through `goChannel`. - A `navigate()` rejection left the trace it opened active, so an untraced re-entry could settle the failed attempt. Cancellation is by trace identity, so a newer same-channel attempt is never erased. Signed-off-by: Max Lampert <maxwell@squareup.com>
78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
import * as React from "react";
|
|
|
|
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
|
|
import { captureSwitchTraceAnchor } from "@/shared/lib/channelSwitchPerf";
|
|
import { useOpenDmMutation } from "@/features/channels/hooks";
|
|
import type { ProfilePanelOpenOptions } from "@/shared/context/ProfilePanelContext";
|
|
|
|
type UseChannelProfilePanelOptions = {
|
|
closeAgentSession: () => void;
|
|
openProfilePanel: (pubkey: string, options?: ProfilePanelOpenOptions) => void;
|
|
requireThreadEditResolution: () => boolean;
|
|
setChannelManagementOpen: (open: boolean) => void;
|
|
setExpandedThreadReplyIds: (value: Set<string>) => void;
|
|
setOpenThreadHeadId: (value: string | null) => void;
|
|
setProfilePanelPubkey: (value: string | null) => void;
|
|
setThreadReplyTargetId: (value: string | null) => void;
|
|
setThreadScrollTargetId: (value: string | null) => void;
|
|
};
|
|
|
|
export function useChannelProfilePanel({
|
|
closeAgentSession,
|
|
openProfilePanel,
|
|
requireThreadEditResolution,
|
|
setChannelManagementOpen,
|
|
setExpandedThreadReplyIds,
|
|
setOpenThreadHeadId,
|
|
setProfilePanelPubkey,
|
|
setThreadReplyTargetId,
|
|
setThreadScrollTargetId,
|
|
}: UseChannelProfilePanelOptions) {
|
|
const { goChannel } = useAppNavigation();
|
|
const openDmMutation = useOpenDmMutation();
|
|
|
|
const handleOpenProfilePanel = React.useCallback(
|
|
(pubkey: string, options?: ProfilePanelOpenOptions) => {
|
|
if (!requireThreadEditResolution()) return;
|
|
setOpenThreadHeadId(null);
|
|
setExpandedThreadReplyIds(new Set());
|
|
setThreadScrollTargetId(null);
|
|
setThreadReplyTargetId(null);
|
|
closeAgentSession();
|
|
setChannelManagementOpen(false);
|
|
openProfilePanel(pubkey, options);
|
|
},
|
|
[
|
|
closeAgentSession,
|
|
openProfilePanel,
|
|
requireThreadEditResolution,
|
|
setChannelManagementOpen,
|
|
setExpandedThreadReplyIds,
|
|
setOpenThreadHeadId,
|
|
setThreadReplyTargetId,
|
|
setThreadScrollTargetId,
|
|
],
|
|
);
|
|
|
|
const handleCloseProfilePanel = React.useCallback(() => {
|
|
setProfilePanelPubkey(null);
|
|
}, [setProfilePanelPubkey]);
|
|
|
|
const openDmMutateAsync = openDmMutation.mutateAsync;
|
|
const handleOpenDm = React.useCallback(
|
|
async (pubkeys: string[]) => {
|
|
// Anchor before awaiting open_dm; see captureSwitchTraceAnchor.
|
|
const traceStartedAt = captureSwitchTraceAnchor();
|
|
const dm = await openDmMutateAsync({ pubkeys });
|
|
await goChannel(dm.id, { traceStartedAt });
|
|
},
|
|
[goChannel, openDmMutateAsync],
|
|
);
|
|
|
|
return {
|
|
handleOpenProfilePanel,
|
|
handleCloseProfilePanel,
|
|
handleOpenDm,
|
|
};
|
|
}
|