Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
perf(issues): a deep link's first frame renders only its target (MUL-9538) (#10910)
Jiayuan Zhang9bdfb69afc89
diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsxindex cedebb06c4..d696632685 100644--- a/packages/views/issues/components/issue-detail.test.tsx+++ b/packages/views/issues/components/issue-detail.test.tsx@@ -3299,6 +3299,76 @@ describe("IssueDetail (shared)", () => {});});+ it("holds the composer back until a landing on cached data puts its target on screen (MUL-9538)", async () => {+ const queryClient = createTestQueryClient();+ queryClient.setQueryData(issueKeys.detail("ws-1", "issue-1"), mockIssue);+ queryClient.setQueryData(issueKeys.timeline("issue-1"), mockTimeline);+ queryClient.setQueryData(issueKeys.tasks("issue-1"), []);+ render(+ <I18nProvider locale="en" resources={TEST_RESOURCES}>+ <QueryClientProvider client={queryClient}>+ <IssueDetail issueId="issue-1" highlightCommentId="comment-2" />+ </QueryClientProvider>+ </I18nProvider>,+ );++ // The landing frame renders the target, not the composer below it.+ expect(document.getElementById("comment-comment-2")).not.toBeNull();+ expect(screen.queryByTestId("comment-composer-shell")).toBeNull();++ await waitFor(() => expect(+ hasHighlightedCommentBackground(document.getElementById("comment-comment-2")),+ ).toBe(true));+ expect(await screen.findByTestId("comment-composer-shell")).toBeInTheDocument();+ });++ it("holds the composer for an Inbox landing whose comment arrives a render later (MUL-9538)", async () => {+ const queryClient = createTestQueryClient();+ queryClient.setQueryData(issueKeys.detail("ws-1", "issue-1"), mockIssue);+ queryClient.setQueryData(issueKeys.timeline("issue-1"), mockTimeline);+ queryClient.setQueryData(issueKeys.tasks("issue-1"), []);+ const page = (highlightCommentId?: string) => (+ <I18nProvider locale="en" resources={TEST_RESOURCES}>+ <QueryClientProvider client={queryClient}>+ <IssueDetail issueId="issue-1" highlightRequestPending highlightCommentId={highlightCommentId} />+ </QueryClientProvider>+ </I18nProvider>+ );+ // Web reads the comment from the URL fragment, which the router writes+ // after the page's first render.+ const { rerender } = render(page());+ expect(screen.queryByTestId("comment-composer-shell")).toBeNull();+ rerender(page("comment-2"));+ expect(screen.queryByTestId("comment-composer-shell")).toBeNull();++ await waitFor(() => expect(+ hasHighlightedCommentBackground(document.getElementById("comment-comment-2")),+ ).toBe(true));+ expect(await screen.findByTestId("comment-composer-shell")).toBeInTheDocument();+ });++ it("lets the composer in at once when an Inbox landing names no comment", async () => {+ const queryClient = createTestQueryClient();+ queryClient.setQueryData(issueKeys.detail("ws-1", "issue-1"), mockIssue);+ queryClient.setQueryData(issueKeys.timeline("issue-1"), mockTimeline);+ queryClient.setQueryData(issueKeys.tasks("issue-1"), []);+ render(+ <I18nProvider locale="en" resources={TEST_RESOURCES}>+ <QueryClientProvider client={queryClient}>+ <IssueDetail issueId="issue-1" highlightRequestPending />+ </QueryClientProvider>+ </I18nProvider>,+ );+ // Within a frame, well before the hold's upper bound.+ expect(await screen.findByTestId("comment-composer-shell", {}, { timeout: 200 })).toBeInTheDocument();+ });++ it("renders the composer while a deep link's timeline is still loading", async () => {+ mockApiObj.listTimeline.mockReturnValue(new Promise(() => {}));+ renderIssueDetailWithHighlight("comment-2");+ expect(await screen.findByTestId("comment-composer-shell")).toBeInTheDocument();+ });+it("auto-expands a folded resolved thread when deep-link target is a reply inside it", async () => {// Seed a timeline where comment-3 is resolved (so it renders as a// resolved-bar by default) and has a reply, reply-1, whose id is thediff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsxindex af99a8672a..50e0815b71 100644--- a/packages/views/issues/components/issue-detail.tsx+++ b/packages/views/issues/components/issue-detail.tsx@@ -730,6 +730,14 @@ function TimelineSkeleton() {// as badly as N blocks of 1 would. Older entries fold behind a "Show N more// activities" line that expands in place.const LAST_ACTIVITY_BLOCK_VISIBLE_LIMIT = 8;+/** Rows Virtuoso keeps mounted beyond the viewport, in px each way. */+const TIMELINE_OVERSCAN = { top: 800, bottom: 800 };+/** Upper bound on a deep link holding the overscan back (see landingOverscanStep). */+const LANDING_OVERSCAN_HOLD_MAX_MS = 3000;+/** Upper bound on a deep link holding the sidebar, composer and thread rail back. */+const LANDING_CHROME_HOLD_MAX_MS = 500;+/** Overscan while a deep link lands, then on each idle step after it, before TIMELINE_OVERSCAN. */+const LANDING_OVERSCAN_STEPS = [0, 200, 400];// Collapsible wrapper for an activity block. Older blocks default to a single// "N activities" summary line so the timeline isn't dominated by status /@@ -1646,6 +1654,63 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, d!!highlightCommentId && !highlightRequestPending && consumedHighlightId === highlightCommentId;const highlightConsumedRef = useRef(highlightConsumed);highlightConsumedRef.current = highlightConsumed;+ // While a deep link lands, the timeline mounts only the rows the viewport+ // shows; its overscan (800px each way, several comment bodies) waits until+ // the target is on screen, so the landing frame renders the target thread+ // and little else. Afterwards the overscan grows back one step per idle+ // period, so the neighbours mount a few at a time instead of in one long+ // task. The hold is bounded in case the landing never runs (a target that+ // is gone). `null`: the full overscan.+ //+ // An Inbox click marks its landing pending before the page mounts; the+ // comment it names arrives a render later on web, with the URL's fragment.+ const landingAtMount = highlightRequestPending || (!!highlightCommentId && !highlightConsumed);+ const [landingOverscanStep, setLandingOverscanStep] = useState<number | null>(+ () => (landingAtMount ? 0 : null),+ );+ const [landingSettled, setLandingSettled] = useState(false);+ const releaseLandingOverscan = useCallback(() => setLandingSettled(true), []);+ // The landing frame also leaves out what is off the reading path: the+ // properties sidebar, the composer and the thread rail. They mount once the+ // target has painted, a frame or two after it.+ const [landingChromeHeld, setLandingChromeHeld] = useState(() => landingAtMount);+ const releaseLandingChrome = useCallback(() => setLandingChromeHeld(false), []);+ // A landing request whose link names no comment has nothing to land on.+ // The fragment is in by the next frame, so a hold still without a target+ // then is let go.+ const holdingWithoutTarget = (landingChromeHeld || landingOverscanStep !== null) && !landingSettled && !highlightCommentId;+ useEffect(() => {+ if (!holdingWithoutTarget) return;+ const frame = requestAnimationFrame(() => {+ releaseLandingChrome();+ releaseLandingOverscan();+ });+ return () => cancelAnimationFrame(frame);+ }, [holdingWithoutTarget, releaseLandingChrome, releaseLandingOverscan]);+ useEffect(() => {+ if (!landingChromeHeld) return;+ if (landingSettled) return releaseLandingChrome();+ const timer = window.setTimeout(releaseLandingChrome, LANDING_CHROME_HOLD_MAX_MS);+ return () => window.clearTimeout(timer);+ }, [landingChromeHeld, landingSettled, releaseLandingChrome]);+ useEffect(() => {+ if (landingOverscanStep === null) return;+ if (!landingSettled) {+ const timer = window.setTimeout(releaseLandingOverscan, LANDING_OVERSCAN_HOLD_MAX_MS);+ return () => window.clearTimeout(timer);+ }+ const grow = () => setLandingOverscanStep((step) =>+ step === null || step + 1 >= LANDING_OVERSCAN_STEPS.length ? null : step + 1);+ if (typeof window.requestIdleCallback === "function") {+ const idle = window.requestIdleCallback(grow, { timeout: 250 });+ return () => window.cancelIdleCallback(idle);+ }+ const timer = window.setTimeout(grow, 16);+ return () => window.clearTimeout(timer);+ }, [landingOverscanStep, landingSettled, releaseLandingOverscan]);+ const timelineOverscan = landingOverscanStep === null+ ? TIMELINE_OVERSCAN+ : LANDING_OVERSCAN_STEPS[landingOverscanStep]!;const onHighlightLandedRef = useRef(onHighlightLanded);onHighlightLandedRef.current = onHighlightLanded;const writeViewState = useViewStateWriter();@@ -1849,6 +1914,11 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, d} = useIssueTimeline(id, user?.id, activeDeliverableJump?.commentId);const { data: commentTasks, isLoading: commentTasksLoading } = useQuery(issueTasksOptions(id));+ // Only a landing on data already in hand is worth holding the chrome for;+ // while the timeline is still on its way, the chrome renders in the wait.+ useEffect(() => {+ if (timelineLoading || commentTasksLoading) releaseLandingChrome();+ }, [timelineLoading, commentTasksLoading, releaseLandingChrome]);const enteringRunIds = useNewRunIds(id, commentTasks);const previousCommentRuns = useRef(new Map<string, CommentRun[]>());const { runs: commentRuns, timeline: displayTimeline, standaloneRuns } = useMemo(() => {@@ -2684,6 +2754,8 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, dcontainer, virtualizer: virtuosoRef.current,index: targetIdx, commentId: landingId,onMounted: () => {+ // After the frame that paints the target, not inside it.+ requestAnimationFrame(() => window.setTimeout(releaseLandingChrome, 0));didHighlightRef.current = highlightCommentId;writeViewState(issueHighlightMementoKey(id), highlightCommentId);onHighlightLandedRef.current?.();@@ -2691,7 +2763,11 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, d// highlight on.flashJumpTarget(landingId, 2500);},- onComplete: () => { completed = true; },+ onComplete: () => {+ completed = true;+ // After the aligned frame paints, not inside it.+ window.setTimeout(releaseLandingOverscan, 0);+ },});return () => {cancel();@@ -2705,7 +2781,7 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, dinterruptedLandingRef.current = highlightCommentId;}};- }, [highlightCommentId, highlightTargetId, highlightRequestToken, activeDeliverableJump, id, writeViewState, items, targetIdx, scrollContainerEl, highlightRootId, expandedResolved, timelineView, toggleResolvedExpand, timelineSized, timelineLoading, commentTasksLoading, flashJumpTarget]);+ }, [highlightCommentId, highlightTargetId, highlightRequestToken, activeDeliverableJump, id, writeViewState, items, targetIdx, scrollContainerEl, highlightRootId, expandedResolved, timelineView, toggleResolvedExpand, timelineSized, timelineLoading, commentTasksLoading, flashJumpTarget, releaseLandingOverscan, releaseLandingChrome]);// Land on the comment in-page find stepped to, the way a deep link lands.useEffect(() => {@@ -3539,7 +3615,7 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, dmetadata: <MetadataSection metadata={issue.metadata ?? {}} />,};- const sidebarContent = (+ const sidebarContent = landingChromeHeld ? null : (<IssueSidebarSectionssections={sidebarSections}available={ISSUE_SIDEBAR_SECTIONS.filter(@@ -4394,7 +4470,7 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, ddata={items}initialScrollTop={readingAnchor ? undefined : restoredScrollTop}heightEstimates={timelineHeightEstimates}- increaseViewportBy={{ top: 800, bottom: 800 }}+ increaseViewportBy={timelineOverscan}totalListHeightChanged={handleTimelineHeightChange}rangeChanged={handleTimelineRangeChanged}computeItemKey={(_i, item) => `${item.kind}:${item.kind === "run" ? item.run.task.id : item.id}`}@@ -4453,14 +4529,16 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, d{stickyComposer && jumpToLatest.visible && (<JumpToLatestButton onClick={onJumpToLatest} label={jumpToLatestLabel} hasNew={!!firstNewCommentId} />)}- <CommentInput- key={id}- issueId={id}- onSubmit={submitComment}- annotationComposer={descriptionAnnotations.composer}- onAccepted={scrollToTimelineBottom}- onEditAnnotation={(annotationId) => descriptionAnnotations.editAnnotation(annotationId, true)}- />+ {!landingChromeHeld && (+ <CommentInput+ key={id}+ issueId={id}+ onSubmit={submitComment}+ annotationComposer={descriptionAnnotations.composer}+ onAccepted={scrollToTimelineBottom}+ onEditAnnotation={(annotationId) => descriptionAnnotations.editAnnotation(annotationId, true)}+ />+ )}</div></div></div>@@ -4475,7 +4553,7 @@ export function IssueDetail({ issueId, onDelete, onDone, onUnsubscribeArchive, dthe resize handle's 4px drag strip at the panel edge. Hoveropens the outline; clicking jumps to a section or comment. Hidden on mobile: nohover, and the gutter is too tight. */}- {!isMobile && !isPeek && (+ {!isMobile && !isPeek && !landingChromeHeld && (<ThreadMinimapthreads={minimapThreads}description={{