-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add showDetailedAnalytics flag #3053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ import { memo } from "react"; | |
| import useSWR from "swr"; | ||
|
|
||
| export function ProgramCustomerPageClient() { | ||
| const { programEnrollment } = useProgramEnrollment(); | ||
| const { programEnrollment, showDetailedAnalytics } = useProgramEnrollment(); | ||
| const { programSlug, customerId } = useParams<{ | ||
| programSlug: string; | ||
| customerId: string; | ||
|
|
@@ -27,8 +27,9 @@ export function ProgramCustomerPageClient() { | |
| customerId, | ||
| }); | ||
|
|
||
| if ((!customer && !isLoading) || programSlug === "perplexity") | ||
| if ((!customer && !isLoading) || !showDetailedAnalytics) { | ||
| redirect(`/programs/${programSlug}`); | ||
| } | ||
|
Comment on lines
+30
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential race condition in redirect logic. The redirect condition checks Consider checking the - const { programEnrollment, showDetailedAnalytics } = useProgramEnrollment();
+ const { programEnrollment, showDetailedAnalytics, loading: isProgramLoading } = useProgramEnrollment();
const { programSlug, customerId } = useParams<{
programSlug: string;
customerId: string;
}>();
const { data: customer, isLoading } = usePartnerCustomer({
customerId,
});
- if ((!customer && !isLoading) || !showDetailedAnalytics) {
+ if ((!customer && !isLoading) || (!showDetailedAnalytics && !isProgramLoading)) {
redirect(`/programs/${programSlug}`);
}
🤖 Prompt for AI Agents |
||
|
|
||
| return ( | ||
| <div className="mb-10 mt-2"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { fetcher } from "@dub/utils"; | |||||||||||||||||||
| import { useSession } from "next-auth/react"; | ||||||||||||||||||||
| import { useParams } from "next/navigation"; | ||||||||||||||||||||
| import useSWR, { SWRConfiguration } from "swr"; | ||||||||||||||||||||
| import { LARGE_PROGRAM_MIN_TOTAL_COMMISSIONS_CENTS } from "../partners/constants"; | ||||||||||||||||||||
| import { ProgramEnrollmentProps } from "../types"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export default function useProgramEnrollment({ | ||||||||||||||||||||
|
|
@@ -31,6 +32,10 @@ export default function useProgramEnrollment({ | |||||||||||||||||||
|
|
||||||||||||||||||||
| return { | ||||||||||||||||||||
| programEnrollment, | ||||||||||||||||||||
| showDetailedAnalytics: | ||||||||||||||||||||
| programSlug !== "perplexity" || | ||||||||||||||||||||
| (programEnrollment?.totalCommissions ?? 0) >= | ||||||||||||||||||||
| LARGE_PROGRAM_MIN_TOTAL_COMMISSIONS_CENTS, | ||||||||||||||||||||
|
Comment on lines
+35
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Race condition: When Components that use this flag for redirects (e.g., Consider one of these solutions: Solution 1: Return return {
programEnrollment,
showDetailedAnalytics:
+ status === "loading" ||
programSlug !== "perplexity" ||
(programEnrollment?.totalCommissions ?? 0) >=
LARGE_PROGRAM_MIN_TOTAL_COMMISSIONS_CENTS,
error,
loading: status === "loading" || isLoading,
};Solution 2: Make consumers check the 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| error, | ||||||||||||||||||||
| loading: status === "loading" || isLoading, | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify the loading state before using
showDetailedAnalytics.The
showDetailedAnalyticsflag depends onprogramEnrollment.totalCommissions, which loads asynchronously. TheuseProgramEnrollmenthook returns aloadingstate, but it's not being destructured or checked here. Consider destructuring theloadingstate to avoid potential race conditions.Check if the redirect logic at line 30 should also wait for the program enrollment data to finish loading:
🏁 Script executed:
Length of output: 27
🏁 Script executed:
Length of output: 40447
🏁 Script executed:
Length of output: 225
🏁 Script executed:
Length of output: 879
🏁 Script executed:
Length of output: 1117
Check the loading state from
useProgramEnrollmentbefore redirecting based onshowDetailedAnalytics.The
useProgramEnrollmenthook returns aloadingstate, but the redirect condition at line 30 only checksisLoadingfromusePartnerCustomer. During initial load,programEnrollmentis undefined, sototalCommissionsdefaults to 0, which can makeshowDetailedAnalyticsfalse prematurely for the "perplexity" program. This causes a redirect before the enrollment data finishes loading.Destructure
loadingfromuseProgramEnrollmentand update the redirect condition to avoid redirecting while enrollment data is still loading:Then update line 30 to:
🤖 Prompt for AI Agents