codeant-ai-for-open-source[bot] commented on code in PR #37881:
URL: https://github.com/apache/superset/pull/37881#discussion_r2791865714
##########
superset-frontend/src/features/home/ActivityTable.tsx:
##########
@@ -126,19 +126,23 @@ export default function ActivityTable({
const [editedCards, setEditedCards] = useState<ActivityData[]>();
const [isFetchingEditedCards, setIsFetchingEditedCards] = useState(false);
- const getEditedCards = () => {
- setIsFetchingEditedCards(true);
- getEditedObjects(user.userId).then(r => {
- setEditedCards([...r.editedChart, ...r.editedDash]);
- setIsFetchingEditedCards(false);
- });
- };
-
useEffect(() => {
+ let isMounted = true;
+
if (activeChild === TableTab.Edited) {
- getEditedCards();
+ setIsFetchingEditedCards(true);
+ getEditedObjects(user.userId).then(r => {
+ if (isMounted) {
+ setEditedCards([...r.editedChart, ...r.editedDash]);
+ setIsFetchingEditedCards(false);
+ }
+ });
}
- }, [activeChild]);
+
+ return () => {
+ isMounted = false;
+ };
Review Comment:
**Suggestion:** When the user switches away from the "Edited" tab while the
edited-objects request is in flight, the effect cleanup sets `isMounted` to
false but never resets `isFetchingEditedCards`, so if the promise later
resolves the loading flag stays `true` indefinitely and the table renders a
permanent loading state; reset the fetching flag in the effect cleanup. [logic
error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Recents section stuck loading after leaving Edited tab mid-fetch.
- ⚠️ Users cannot view created or viewed activity lists.
```
</details>
```suggestion
setIsFetchingEditedCards(false);
```
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Open the Welcome page that mounts `ActivityTable` via the Recents
Collapse item in
`superset-frontend/src/pages/Home/index.tsx:362-381`, passing `activeChild`,
`setActiveChild`, `activityData`, and `isFetchingActivityData` props.
2. Ensure activity data is loaded so that `isFetchingActivityData` is
`false` (set in the
`Welcome` effect at `Home/index.tsx:211-293`), then click the "Edited" tab
in the Recents
SubMenu, which sets `activeChild` to `TableTab.Edited` via the `tabs`
handlers defined in
`ActivityTable.tsx:147-164`.
3. The `useEffect` in `ActivityTable` at `ActivityTable.tsx:129-145` runs
with
`activeChild === TableTab.Edited`, sets `isFetchingEditedCards` to `true` at
`ActivityTable.tsx:133`, and starts `getEditedObjects(user.userId)` at
`ActivityTable.tsx:134`, which issues `/api/v1/dashboard` and
`/api/v1/chart` requests as
defined in `superset-frontend/src/views/CRUD/utils.tsx:144-161`.
4. Before those requests resolve (e.g., under normal network latency),
quickly click the
"Created" tab so `activeChild` becomes `TableTab.Created`; React runs the
cleanup of the
previous effect (`ActivityTable.tsx:142-144`, only setting `isMounted =
false`) and then
re-runs the effect without entering the Edited branch, leaving
`isFetchingEditedCards`
stuck at `true`, so the render guard at `ActivityTable.tsx:201-203` (`if
((isFetchingEditedCards && !editedCards) || isFetchingActivityData) return
<LoadingCards
/>;`) keeps the Recents section permanently in a loading state even when
Created/Viewed
data is available.
```
</details>
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/features/home/ActivityTable.tsx
**Line:** 144:144
**Comment:**
*Logic Error: When the user switches away from the "Edited" tab while
the edited-objects request is in flight, the effect cleanup sets `isMounted` to
false but never resets `isFetchingEditedCards`, so if the promise later
resolves the loading flag stays `true` indefinitely and the table renders a
permanent loading state; reset the fetching flag in the effect cleanup.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37881&comment_hash=6953c44570ae0390ed08313c03177938fd619823f762c755bdec11feff3201a7&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37881&comment_hash=6953c44570ae0390ed08313c03177938fd619823f762c755bdec11feff3201a7&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]