Skip to content
Merged
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
27 changes: 26 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
APP_INIT_ERROR, APP_READY, subscribe, initialize, mergeConfig, getConfig, getPath,
APP_INIT_ERROR, APP_READY, subscribe, initialize, mergeConfig, getConfig, getPath, APP_AUTH_INITIALIZED,
} from '@edx/frontend-platform';
import { AppProvider, ErrorPage } from '@edx/frontend-platform/react';
import React, { StrictMode, useEffect } from 'react';
Expand All @@ -14,6 +14,7 @@ import {

import { initializeHotjar } from '@edx/frontend-enterprise-hotjar';
import { logError } from '@edx/frontend-platform/logging';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import messages from './i18n';

import {
Expand Down Expand Up @@ -151,6 +152,30 @@ subscribe(APP_INIT_ERROR, (error) => {
);
});

subscribe(APP_AUTH_INITIALIZED, () => {
Comment on lines 154 to +155
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

Registering the interceptor inside the event callback without a guard can lead to multiple identical interceptors if APP_AUTH_INITIALIZED fires more than once, causing duplicated priming requests. Add a flag to ensure the interceptor is added only once or store/eject the interceptor ID if re-registration is attempted.

Suggested change
subscribe(APP_AUTH_INITIALIZED, () => {
// Guard to ensure the interceptor is only registered once
let interceptorRegistered = false;
subscribe(APP_AUTH_INITIALIZED, () => {
if (interceptorRegistered) {
return;
}
interceptorRegistered = true;

Copilot uses AI. Check for mistakes.

getAuthenticatedHttpClient().interceptors.request.use(async (requestConfig) => {
const methodsToIntercept = ['post', 'put', 'delete', 'patch'];

if (methodsToIntercept.includes(requestConfig.method?.toLowerCase())) {
try {
await getAuthenticatedHttpClient().get(getConfig().STUDIO_BASE_URL, {
Comment on lines +156 to +161
Copy link

Copilot AI Oct 17, 2025

Choose a reason for hiding this comment

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

[nitpick] Repeated calls to getAuthenticatedHttpClient() inside the interceptor can be replaced by a captured constant (e.g., const client = getAuthenticatedHttpClient();) to make intent clearer and avoid any risk if the factory were to return a new instance in future changes.

Suggested change
getAuthenticatedHttpClient().interceptors.request.use(async (requestConfig) => {
const methodsToIntercept = ['post', 'put', 'delete', 'patch'];
if (methodsToIntercept.includes(requestConfig.method?.toLowerCase())) {
try {
await getAuthenticatedHttpClient().get(getConfig().STUDIO_BASE_URL, {
const client = getAuthenticatedHttpClient();
client.interceptors.request.use(async (requestConfig) => {
const methodsToIntercept = ['post', 'put', 'delete', 'patch'];
if (methodsToIntercept.includes(requestConfig.method?.toLowerCase())) {
try {
await client.get(getConfig().STUDIO_BASE_URL, {

Copilot uses AI. Check for mistakes.

withCredentials: true,
});
} catch (e) {
const iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = getConfig().STUDIO_BASE_URL;
document.body.appendChild(iframe);

iframe.onload = () => {
setTimeout(() => document.body.removeChild(iframe), 2000);
};
}
}
return requestConfig;
});
});

initialize({
handlers: {
config: () => {
Expand Down