Skip to content

Commit 5a406f9

Browse files
Marfuenclaude
andauthored
fix: revert page-level hooks to useRealtimeRun to fix missing auth context (#2780)
useRun requires a TriggerProvider with an access token. When there's no active onboarding (no triggerJobId), the TriggerTokenProvider renders children without a TriggerProvider, causing useRun to throw "Missing accessToken in TriggerAuthContext." Reverted policies-table, use-policy-onboarding-status, and use-onboarding-status back to useRealtimeRun which gracefully handles missing auth context via the enabled flag. For ToDoOverview, removed the trigger hook entirely — it only needs a boolean "is onboarding running" which can be derived from the triggerJobId prop. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b14db0b commit 5a406f9

4 files changed

Lines changed: 10 additions & 29 deletions

File tree

apps/app/src/app/(app)/[orgId]/overview/components/ToDoOverview.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Card, CardContent, CardHeader, CardTitle } from '@trycompai/ui/card';
55
import { ScrollArea } from '@trycompai/ui/scroll-area';
66
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@trycompai/ui/tabs';
77
import { Policy, Task } from '@db';
8-
import { useRun } from '@trigger.dev/react-hooks';
98
import {
109
ArrowRight,
1110
CheckCircle2,
@@ -49,25 +48,7 @@ export function ToDoOverview({
4948
const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(false);
5049
const [isLoading, setIsLoading] = useState(false);
5150

52-
const { run: onboardingRun } = useRun(onboardingTriggerJobId || '', {
53-
refreshInterval: 1000,
54-
});
55-
56-
const IN_PROGRESS_STATUSES = [
57-
'QUEUED',
58-
'EXECUTING',
59-
'WAITING_FOR_DEPLOY',
60-
'REATTEMPTING',
61-
'FROZEN',
62-
'DELAYED',
63-
'WAITING',
64-
'PENDING_VERSION',
65-
'DEQUEUED',
66-
];
67-
68-
const isOnboardingInProgress = onboardingRun
69-
? IN_PROGRESS_STATUSES.includes(onboardingRun.status)
70-
: false;
51+
const isOnboardingInProgress = !!onboardingTriggerJobId;
7152

7253
const formatStatus = (status: string) => {
7354
return status.replace('_', ' ').replace(/\b\w/g, (l) => l.toUpperCase());

apps/app/src/app/(app)/[orgId]/policies/(overview)/hooks/use-policy-onboarding-status.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useRun } from '@trigger.dev/react-hooks';
3+
import { useRealtimeRun } from '@trigger.dev/react-hooks';
44
import { useMemo } from 'react';
55
import type { PolicyTailoringStatus } from '../../all/components/policy-tailoring-context';
66

@@ -20,8 +20,8 @@ export function usePolicyOnboardingStatus(
2020
onboardingRunId: string | null | undefined,
2121
) {
2222
const shouldSubscribe = Boolean(onboardingRunId);
23-
const { run } = useRun(shouldSubscribe ? onboardingRunId! : '', {
24-
refreshInterval: 1000,
23+
const { run } = useRealtimeRun(shouldSubscribe ? onboardingRunId! : '', {
24+
enabled: shouldSubscribe,
2525
});
2626

2727
const itemStatuses = useMemo<Record<string, PolicyTailoringStatus>>(() => {

apps/app/src/app/(app)/[orgId]/policies/all/components/policies-table.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useRun } from '@trigger.dev/react-hooks';
3+
import { useRealtimeRun } from '@trigger.dev/react-hooks';
44
import { Download, Loader2 } from 'lucide-react';
55
import * as React from 'react';
66
import { toast } from 'sonner';
@@ -31,8 +31,8 @@ export function PoliciesTable({ promises, onboardingRunId }: PoliciesTableProps)
3131
const orgId = params.orgId as string;
3232

3333
const shouldSubscribeToRun = Boolean(onboardingRunId);
34-
const { run } = useRun(shouldSubscribeToRun ? onboardingRunId! : '', {
35-
refreshInterval: 1000,
34+
const { run } = useRealtimeRun(shouldSubscribeToRun ? onboardingRunId! : '', {
35+
enabled: shouldSubscribeToRun,
3636
});
3737

3838
const policyStatuses = React.useMemo<PolicyStatusMap>(() => {

apps/app/src/app/(app)/[orgId]/risk/(overview)/hooks/use-onboarding-status.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { useRun } from '@trigger.dev/react-hooks';
3+
import { useRealtimeRun } from '@trigger.dev/react-hooks';
44
import { useMemo } from 'react';
55

66
export type OnboardingItemStatus = 'pending' | 'processing' | 'created' | 'assessing' | 'completed';
@@ -15,8 +15,8 @@ export function useOnboardingStatus(
1515
itemType: 'risks' | 'vendors',
1616
) {
1717
const shouldSubscribe = Boolean(onboardingRunId);
18-
const { run } = useRun(shouldSubscribe ? onboardingRunId! : '', {
19-
refreshInterval: 1000,
18+
const { run } = useRealtimeRun(shouldSubscribe ? onboardingRunId! : '', {
19+
enabled: shouldSubscribe,
2020
});
2121

2222
const itemStatuses = useMemo<Record<string, OnboardingItemStatus>>(() => {

0 commit comments

Comments
 (0)