Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(github): better pr task skeleton lazy loading (#3877)
Will Hutchinson21e79eb7c7e2
diff --git a/js/app/packages/queries/storage/github-pull-requests.test.ts b/js/app/packages/queries/storage/github-pull-requests.test.tsindex 4900c2e79f..d000160ac4 100644--- a/js/app/packages/queries/storage/github-pull-requests.test.ts+++ b/js/app/packages/queries/storage/github-pull-requests.test.ts@@ -148,6 +148,46 @@ describe('fetchDocumentGithubPullRequests', () => {});});+ it('emits storage-enriched PRs before auth enrichment resolves', async () => {+ const shallowAuthPullRequest = createShallowAuthPullRequest(rawPullRequest);+ const onInitialResponse = vi.fn();+ let resolveEnrichment!: (response: unknown) => void;+ const enrichmentPromise = new Promise((resolve) => {+ resolveEnrichment = resolve;+ });++ mocks.getDocumentGithubPullRequests.mockResolvedValue(+ resultOk({ pullRequests: [storageMetadataPullRequest] })+ );+ mocks.enrichGithubPullRequests.mockReturnValue(enrichmentPromise);++ const responsePromise = fetchDocumentGithubPullRequests('document-1', {+ onInitialResponse,+ });++ await vi.waitFor(() => {+ expect(onInitialResponse).toHaveBeenCalledWith({+ pullRequests: [storageMetadataPullRequest],+ });+ });++ resolveEnrichment(resultOk({ pullRequests: [shallowAuthPullRequest] }));+ await expect(responsePromise).resolves.toEqual({+ pullRequests: [storageMetadataPullRequest],+ });+ });++ it('does not emit shallow storage PRs as an initial enriched response', async () => {+ const onInitialResponse = vi.fn();+ mocks.enrichGithubPullRequests.mockResolvedValue(+ resultOk({ pullRequests: [createShallowAuthPullRequest(rawPullRequest)] })+ );++ await fetchDocumentGithubPullRequests('document-1', { onInitialResponse });++ expect(onInitialResponse).not.toHaveBeenCalled();+ });+it('uses auth enrichment metadata when present while preserving the foreign entity id', async () => {const enrichedPullRequest: EnrichedGithubPullRequest = {...rawPullRequest,diff --git a/js/app/packages/queries/storage/github-pull-requests.ts b/js/app/packages/queries/storage/github-pull-requests.tsindex 3f1a00418d..babc89247d 100644--- a/js/app/packages/queries/storage/github-pull-requests.ts+++ b/js/app/packages/queries/storage/github-pull-requests.ts@@ -9,7 +9,7 @@ import type {GithubPullRequest,GithubPullRequestsResponse,} from '@service-storage/generated/schemas';-import { useQuery } from '@tanstack/solid-query';+import { useQuery, useQueryClient } from '@tanstack/solid-query';import type { Accessor } from 'solid-js';import { documentGithubPullRequestsKeys } from './keys';@@ -21,6 +21,10 @@ type DocumentIdInput =| Accessor<string | null | undefined>;type EnabledInput = boolean | Accessor<boolean>;+type FetchDocumentGithubPullRequestsOptions = {+ onInitialResponse?: (response: GithubPullRequestsResponse) => void;+};+function readDocumentId(documentId: DocumentIdInput): string | null | undefined {@@ -74,8 +78,28 @@ function createPullRequestFallbacksByKey();}+function hasStoredEnrichedGithubPullRequestData(+ pullRequest: GithubPullRequest+): boolean {+ return (+ pullRequest.additions != null ||+ pullRequest.checks != null ||+ pullRequest.comments != null ||+ pullRequest.deletions != null ||+ pullRequest.name != null ||+ pullRequest.status != null+ );+}++function hasStoredEnrichedGithubPullRequests(+ response: GithubPullRequestsResponse+): boolean {+ return response.pullRequests.some(hasStoredEnrichedGithubPullRequestData);+}+export async function fetchDocumentGithubPullRequests(- documentId: string+ documentId: string,+ options?: FetchDocumentGithubPullRequestsOptions): Promise<GithubPullRequestsResponse> {const rawResponse = await throwOnErr(() =>storageServiceClient.getDocumentGithubPullRequests({ documentId })@@ -85,6 +109,10 @@ export async function fetchDocumentGithubPullRequests(return rawResponse;}+ if (hasStoredEnrichedGithubPullRequests(rawResponse)) {+ options?.onInitialResponse?.(rawResponse);+ }+const enrichedResponse = await authServiceClient.enrichGithubPullRequests({pullRequests: rawResponse.pullRequests.map(toGithubPullRequestRef),});@@ -113,20 +141,27 @@ export function useDocumentGithubPullRequestsQuery(documentId: DocumentIdInput,enabled?: EnabledInput) {+ const queryClient = useQueryClient();+return useQuery(() => {const currentDocumentId = readDocumentId(documentId);+ const queryKey = currentDocumentId+ ? documentGithubPullRequestsKeys.list(currentDocumentId).queryKey+ : documentGithubPullRequestsKeys.list._def;return {- queryKey: currentDocumentId- ? documentGithubPullRequestsKeys.list(currentDocumentId).queryKey- : documentGithubPullRequestsKeys.list._def,+ queryKey,queryFn: () => {if (!currentDocumentId) {throw new Error('Document ID is required to fetch GitHub pull requests');}- return fetchDocumentGithubPullRequests(currentDocumentId);+ return fetchDocumentGithubPullRequests(currentDocumentId, {+ onInitialResponse: (initialResponse) => {+ queryClient.setQueryData(queryKey, initialResponse);+ },+ });},staleTime: DOCUMENT_GITHUB_PULL_REQUESTS_STALE_TIME,enabled: !!currentDocumentId && readEnabled(enabled),