From ee998c4c3f119c7e2c0319dd885ccdcf1e6bf905 Mon Sep 17 00:00:00 2001 From: Saurabh Kumar Bajpai Date: Mon, 27 Jul 2026 05:39:04 +0530 Subject: [PATCH] fix: import order violation in ESM modules and untyped API response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Move AVATAR_API constant after imports in RealTimeContext.tsx (invalid ESM — imports must precede all code) - Move DEVPATH_API constant after imports in InteractiveBackground.tsx (same ESM violation) - Guard setNews(data) in CodingNews.tsx: validate that API response is an array before setting; fall back to FALLBACK_NEWS on mismatch --- src/components/home/CodingNews.tsx | 8 +++++++- src/components/ui/InteractiveBackground.tsx | 5 +++-- src/context/RealTimeContext.tsx | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/home/CodingNews.tsx b/src/components/home/CodingNews.tsx index 4856e508..4f22471e 100644 --- a/src/components/home/CodingNews.tsx +++ b/src/components/home/CodingNews.tsx @@ -105,7 +105,13 @@ export default function CodingNews() { throw new Error('Failed to fetch news'); } const data = await response.json(); - setNews(data); + if (Array.isArray(data)) { + setNews(data as NewsItem[]); + } else if (data && Array.isArray(data.articles)) { + setNews(data.articles as NewsItem[]); + } else { + setNews(FALLBACK_NEWS); + } } catch (err) { console.error('Error fetching news:', err); // Fall back gracefully even if fetch fails diff --git a/src/components/ui/InteractiveBackground.tsx b/src/components/ui/InteractiveBackground.tsx index b1c16f35..ab97ee33 100644 --- a/src/components/ui/InteractiveBackground.tsx +++ b/src/components/ui/InteractiveBackground.tsx @@ -1,9 +1,10 @@ 'use client'; -const DEVPATH_API = - process.env.NEXT_PUBLIC_DEVPATH_API_URL ?? 'https://api.devpath.in'; import { useEffect, useRef } from 'react'; import { useUIStore } from '@/stores/ui-store'; +const DEVPATH_API = + process.env.NEXT_PUBLIC_DEVPATH_API_URL ?? 'https://api.devpath.in'; + // Code snippets that type across the screen — dev/community themed const CODE_LINES = [ // Git diff --git a/src/context/RealTimeContext.tsx b/src/context/RealTimeContext.tsx index 3504525e..6ece0c28 100644 --- a/src/context/RealTimeContext.tsx +++ b/src/context/RealTimeContext.tsx @@ -1,8 +1,9 @@ 'use client'; +import React, { createContext, useContext, useState, useEffect } from 'react'; + const AVATAR_API = process.env.NEXT_PUBLIC_AVATAR_API_URL ?? 'https://api.dicebear.com/7.x/avataaars/svg'; -import React, { createContext, useContext, useState, useEffect } from 'react'; interface Activity { id: number;