Update guard and interceptors to prevent conflicts#1716
Update guard and interceptors to prevent conflicts#1716alexandrudanpop merged 2 commits intomainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the authentication interceptor setup to prevent conflicts by ensuring interceptors are only initialized once with the correct configuration. The key change is removing the automatic initialization of the request interceptor and instead deferring both request and response interceptor setup until flags are available.
- Moved request interceptor initialization to be controlled by the guard component
- Added state management to ensure interceptors are ready before rendering children
- Updated type signatures to align federated and standard response interceptor interfaces
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/react-ui/src/app/interceptors/response-interceptor.ts | Updated federated response interceptor return type to match standard interceptor |
| packages/react-ui/src/app/interceptors/index.ts | Exported setupRequestInterceptor and consolidated type definitions |
| packages/react-ui/src/app/common/guards/intial-data-guard.tsx | Added controlled interceptor initialization with loading state |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (!interceptorsReady) { | ||
| return ( | ||
| <div className="bg-background flex h-screen w-screen items-center justify-center "> | ||
| <LoadingSpinner size={50}></LoadingSpinner> | ||
| </div> | ||
| ); | ||
| } |
There was a problem hiding this comment.
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.
| if (!interceptorsReady) { | ||
| return ( | ||
| <div className="bg-background flex h-screen w-screen items-center justify-center "> | ||
| <LoadingSpinner size={50}></LoadingSpinner> |
There was a problem hiding this comment.
Self-closing tag should be used for components without children. Replace </LoadingSpinner> with /> to follow React conventions.
Greptile OverviewGreptile SummaryPrevented race condition where API calls could execute before Axios interceptors were configured by moving interceptor setup from module-level initialization to controlled setup within Key changes:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant App
participant InitialDataGuard
participant FlagsAPI
participant Interceptors
participant AxiosInstance
participant Children
App->>InitialDataGuard: Render with children
InitialDataGuard->>FlagsAPI: useFlags() (useSuspenseQuery)
Note over InitialDataGuard,FlagsAPI: Suspends until flags loaded
FlagsAPI-->>InitialDataGuard: Returns flags data
alt flags is null/undefined
InitialDataGuard->>InitialDataGuard: console.error + return early
InitialDataGuard->>InitialDataGuard: Show LoadingSpinner (interceptorsReady=false)
else flags exists
InitialDataGuard->>Interceptors: setupRequestInterceptor({isFederatedAuth})
Interceptors->>AxiosInstance: Register request interceptor
AxiosInstance-->>Interceptors: interceptorId
InitialDataGuard->>Interceptors: setupResponseInterceptor({isFederatedAuth})
Interceptors->>AxiosInstance: Register response interceptor
AxiosInstance-->>Interceptors: interceptorId
InitialDataGuard->>InitialDataGuard: setInterceptorsReady(true)
InitialDataGuard->>Children: Render children (with Suspense)
Children->>AxiosInstance: Make API calls
Note over AxiosInstance,Children: Interceptors now active
end
|
|



Fixes OPS-3144