Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Fixed text inside angle brackets (e.g., `<id>`) being hidden in chat prompt display due to HTML parsing. [#929](https://github.com/sourcebot-dev/sourcebot/pull/929) [#932](https://github.com/sourcebot-dev/sourcebot/pull/932)
- Fixed permission sync banner flashing on initial page load. [#942](https://github.com/sourcebot-dev/sourcebot/pull/942)
- Fixed issue where the permission sync banner would sometimes not appear until the page was refreshed. [#942](https://github.com/sourcebot-dev/sourcebot/pull/942)

## [4.11.7] - 2026-02-23

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { usePrevious } from "@uidotdev/usehooks";

const POLL_INTERVAL_MS = 5000;

export function PermissionSyncBanner() {
interface PermissionSyncBannerProps {
initialHasPendingFirstSync: boolean;
}

export function PermissionSyncBanner({ initialHasPendingFirstSync }: PermissionSyncBannerProps) {
const router = useRouter();

const { data: hasPendingFirstSync, isError, isPending } = useQuery({
Expand All @@ -25,6 +29,9 @@ export function PermissionSyncBanner() {
// Keep polling while sync is in progress, stop when done
return hasPendingFirstSync ? POLL_INTERVAL_MS : false;
},
initialData: {
hasPendingFirstSync: initialHasPendingFirstSync,
}
});

const previousHasPendingFirstSync = usePrevious(hasPendingFirstSync);
Expand Down
9 changes: 8 additions & 1 deletion packages/web/src/app/[domain]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { UpgradeToast } from "./components/upgradeToast";
import { getLinkedAccountProviderStates } from "@/ee/features/permissionSyncing/actions";
import { LinkAccounts } from "@/ee/features/permissionSyncing/components/linkAccounts";
import { PermissionSyncBanner } from "./components/permissionSyncBanner";
import { getPermissionSyncStatus } from "../api/(server)/ee/permissionSyncStatus/route";

interface LayoutProps {
children: React.ReactNode,
Expand Down Expand Up @@ -190,12 +191,18 @@ export default async function Layout(props: LayoutProps) {
)
}
const isPermissionSyncBannerVisible = session && hasEntitlement("permission-syncing");
const hasPendingFirstSync = isPermissionSyncBannerVisible ? (await getPermissionSyncStatus()) : null;

return (
<SyntaxGuideProvider>
{
isPermissionSyncBannerVisible ? (
<PermissionSyncBanner />
<PermissionSyncBanner
initialHasPendingFirstSync={(isServiceError(hasPendingFirstSync) || hasPendingFirstSync === null) ?
false :
hasPendingFirstSync.hasPendingFirstSync
}
/>
) : null
}
{children}
Expand Down
56 changes: 33 additions & 23 deletions packages/web/src/app/api/(server)/ee/permissionSyncStatus/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use server';

import { apiHandler } from "@/lib/apiHandler";
import { serviceErrorResponse } from "@/lib/serviceError";
import { ServiceError, serviceErrorResponse } from "@/lib/serviceError";
import { isServiceError } from "@/lib/utils";
import { withAuthV2 } from "@/withAuthV2";
import { getEntitlements } from "@sourcebot/shared";
import { env, getEntitlements } from "@sourcebot/shared";
import { AccountPermissionSyncJobStatus } from "@sourcebot/db";
import { StatusCodes } from "http-status-codes";
import { ErrorCode } from "@/lib/errorCodes";
import { sew } from "@/actions";

export interface PermissionSyncStatusResponse {
hasPendingFirstSync: boolean;
Expand All @@ -18,16 +19,28 @@ export interface PermissionSyncStatusResponse {
* synced for the first time.
*/
export const GET = apiHandler(async () => {
const entitlements = getEntitlements();
if (!entitlements.includes('permission-syncing')) {
return serviceErrorResponse({
statusCode: StatusCodes.FORBIDDEN,
errorCode: ErrorCode.INSUFFICIENT_PERMISSIONS,
message: "Permission syncing is not enabled for your license",
});
const result = await getPermissionSyncStatus();

if (isServiceError(result)) {
return serviceErrorResponse(result);
}

const result = await withAuthV2(async ({ prisma, user }) => {
return Response.json(result, { status: StatusCodes.OK });
});


export const getPermissionSyncStatus = async (): Promise<PermissionSyncStatusResponse | ServiceError> => sew(async () =>
Comment thread
brendan-kellam marked this conversation as resolved.
Outdated
withAuthV2(async ({ prisma, user }) => {
const entitlements = getEntitlements();
if (!entitlements.includes('permission-syncing')) {
return {
statusCode: StatusCodes.FORBIDDEN,
errorCode: ErrorCode.INSUFFICIENT_PERMISSIONS,
message: "Permission syncing is not enabled for your license",
} satisfies ServiceError;
}


const accounts = await prisma.account.findMany({
where: {
userId: user.id,
Expand All @@ -46,18 +59,15 @@ export const GET = apiHandler(async () => {
AccountPermissionSyncJobStatus.IN_PROGRESS
];

const hasPendingFirstSync = accounts.some(account =>
account.permissionSyncedAt === null &&
account.permissionSyncJobs.length > 0 &&
activeStatuses.includes(account.permissionSyncJobs[0].status)
);
const hasPendingFirstSync = env.EXPERIMENT_EE_PERMISSION_SYNC_ENABLED === 'true' &&
accounts.some(account =>
account.permissionSyncedAt === null &&
// @note: to handle the case where the permission sync job
// has not yet been scheduled for a new account, we consider
// accounts with no permission sync jobs as having a pending first sync.
(account.permissionSyncJobs.length === 0 || (account.permissionSyncJobs.length > 0 && activeStatuses.includes(account.permissionSyncJobs[0].status)))
)

return { hasPendingFirstSync } satisfies PermissionSyncStatusResponse;
});

if (isServiceError(result)) {
return serviceErrorResponse(result);
}

return Response.json(result, { status: StatusCodes.OK });
});
})
)
Loading