Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 21 additions & 3 deletions packages/react-ui/src/app/common/guards/intial-data-guard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { LoadingSpinner } from '@openops/components/ui';
import { Suspense, useEffect } from 'react';
import { Suspense, useEffect, useState } from 'react';

import { flagsHooks } from '@/app/common/hooks/flags-hooks';
import { setupResponseInterceptor } from '@/app/interceptors';
import {
setupRequestInterceptor,
setupResponseInterceptor,
} from '@/app/interceptors';

type InitialDataGuardProps = {
children: React.ReactNode;
Expand All @@ -11,16 +14,31 @@ export const InitialDataGuard = ({
children,
}: Readonly<InitialDataGuardProps>) => {
const { data: flags } = flagsHooks.useFlags();
const [interceptorsReady, setInterceptorsReady] = useState(false);

useEffect(() => {
if (!flags) {
console.error('Missing flags for response interceptor configuration');
return;
}
Comment thread
alexandrudanpop marked this conversation as resolved.
const isFederatedAuth = Boolean(flags?.FEDERATED_LOGIN_ENABLED);
setupRequestInterceptor({
isFederatedAuth,
});
setupResponseInterceptor({
isFederatedAuth: Boolean(flags?.FEDERATED_LOGIN_ENABLED),
isFederatedAuth,
});
setInterceptorsReady(true);
}, [flags]);

if (!interceptorsReady) {
return (
<div className="bg-background flex h-screen w-screen items-center justify-center ">
<LoadingSpinner size={50}></LoadingSpinner>
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-closing tag should be used for components without children. Replace </LoadingSpinner> with /> to follow React conventions.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1min fix, looks legit.

</div>
);
}
Comment on lines +34 to +40
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interceptorsReady check will block rendering even when flags is undefined. This creates a situation where if flags never load, the application will show a loading spinner indefinitely instead of handling the error state. Consider checking both flags and interceptorsReady, or handling the flags error case differently.

Copilot uses AI. Check for mistakes.

return (
<Suspense
fallback={
Expand Down
16 changes: 8 additions & 8 deletions packages/react-ui/src/app/interceptors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import {
let requestInterceptorId: number | null = null;
let responseInterceptorId: number | null = null;

function setupRequestInterceptor(): void {
type InterceptorOptions = {
isFederatedAuth: boolean;
};

export function setupRequestInterceptor({
isFederatedAuth,
}: InterceptorOptions): void {
if (requestInterceptorId === null) {
const requestInterceptor = createRequestInterceptor();
requestInterceptorId = axios.interceptors.request.use(requestInterceptor);
}
}

setupRequestInterceptor();

type ResponseInterceptorOptions = {
isFederatedAuth: boolean;
};

export function setupResponseInterceptor({
isFederatedAuth,
}: ResponseInterceptorOptions): void {
}: InterceptorOptions): void {
if (responseInterceptorId === null) {
const responseInterceptor = isFederatedAuth
? createFederatedResponseInterceptor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

export function createFederatedResponseInterceptor(): {
onFulfilled: (response: AxiosResponse) => AxiosResponse;
onRejected: (error: AxiosError) => Promise<never>;
onRejected: (error: AxiosError) => Promise<AxiosResponse | never>;

Check warning on line 46 in packages/react-ui/src/app/interceptors/response-interceptor.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'never' is overridden by other types in this union type.

See more on https://sonarcloud.io/project/issues?id=openops-cloud_openops&issues=AZrjhyfyTNjg9jrC-VJc&open=AZrjhyfyTNjg9jrC-VJc&pullRequest=1716
} {
throw new Error('Not implemented in OSS');
}
Loading