@@ -162,37 +162,72 @@ function useCMSIntegrations() {
162162
163163 useEffect ( ( ) => {
164164 const fetchIntegrations = async ( ) => {
165+ // Step 1: Load fallback data first for immediate display
165166 try {
166- setLoading ( true ) ;
167- const response = await fetch ( 'https://cms.clickhouse-dev.com:1337/api/integrations?populate[]=logo&populate[]=logo_dark' ) ;
167+ const fallbackResponse = await fetch ( '/integrations-fallback.json' , {
168+ cache : 'force-cache' // Use cached version if available
169+ } ) ;
170+
171+ if ( fallbackResponse . ok ) {
172+ const fallbackData = await fallbackResponse . json ( ) ;
173+ const transformedData = transformCMSData ( fallbackData . data || [ ] ) ;
174+ setIntegrations ( transformedData ) ;
175+ setError ( null ) ;
176+ setLoading ( false ) ; // Show content immediately with fallback data
177+ console . log ( 'Loaded fallback integrations data' ) ;
178+ } else {
179+ console . warn ( 'Fallback file not available, will try CMS only' ) ;
180+ }
181+ } catch ( fallbackErr ) {
182+ console . error ( 'Failed to load fallback integrations data:' , fallbackErr ) ;
183+ // Continue to try CMS even if fallback fails
184+ }
185+
186+ // Step 2: Try to fetch fresh data from CMS with timeout
187+ try {
188+ const controller = new AbortController ( ) ;
189+ const timeoutId = setTimeout ( ( ) => {
190+ controller . abort ( ) ;
191+ console . log ( 'CMS request timed out after 8 seconds' ) ;
192+ } , 8000 ) ; // 8 second timeout
193+
194+ const response = await fetch (
195+ 'https://cms.clickhouse-dev.com:1337/api/integrations?populate[]=logo&populate[]=logo_dark' ,
196+ {
197+ signal : controller . signal ,
198+ // Add headers to help with CORS and caching
199+ headers : {
200+ 'Accept' : 'application/json' ,
201+ }
202+ }
203+ ) ;
204+
205+ clearTimeout ( timeoutId ) ;
168206
169207 if ( ! response . ok ) {
170208 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
171209 }
172210
173211 const data = await response . json ( ) ;
174212 const transformedData = transformCMSData ( data . data || [ ] ) ;
213+
214+ // Update with fresh CMS data
175215 setIntegrations ( transformedData ) ;
176216 setError ( null ) ;
177- } catch ( err ) {
178- console . error ( 'Error loading integrations data from endpoint. Falling back to static JSON file.' ) ;
179-
180- // Fallback to static JSON file
181- try {
182- const fallbackResponse = await fetch ( '/integrations-fallback.json' ) ;
183-
184- if ( ! fallbackResponse . ok ) {
185- throw new Error ( `Failed to load fallback data: ${ fallbackResponse . status } ` ) ;
217+ console . log ( 'Successfully updated with fresh CMS data' ) ;
218+ } catch ( cmsErr ) {
219+ // CMS fetch failed, but that's okay - we already have fallback data
220+ if ( cmsErr instanceof Error ) {
221+ if ( cmsErr . name === 'AbortError' ) {
222+ console . log ( 'CMS request was aborted due to timeout, using fallback data' ) ;
223+ } else {
224+ console . error ( 'Error loading integrations from CMS:' , cmsErr . message ) ;
186225 }
226+ }
187227
188- const fallbackData = await fallbackResponse . json ( ) ;
189- const transformedData = transformCMSData ( fallbackData . data || [ ] ) ;
190- setIntegrations ( transformedData ) ;
191- setError ( null ) ;
192- } catch ( fallbackErr ) {
193- console . error ( 'Failed to load fallback integrations data:' , fallbackErr ) ;
194- setError ( fallbackErr instanceof Error ? fallbackErr . message : 'Failed to fetch integrations' ) ;
195- setIntegrations ( [ ] ) ;
228+ // Only set error if we don't have any integrations data at all
229+ if ( integrations . length === 0 ) {
230+ setError ( 'Unable to load integrations. Please try refreshing the page.' ) ;
196231 }
197232 } finally {
198233 setLoading ( false ) ;
0 commit comments