Skip to content

Bug: TemplateDetailAnalytics does not reset state when draftId changes (stale data shown) #39

Description

@ChitkulLakshya

Bug: TemplateDetailAnalytics does not reset state when draftId changes

File: src/pages/TemplateDetailAnalytics.jsx:82-88

Problem

The useEffect that fetches detail and submissions depends on fetchDetail and fetchSubmissions, which are useCallback functions dependent on draftId. However, when navigating from one template to another (changing draftId), the component does not reset error, githubData, githubError, or submissionsPage:

useEffect(() => {
  (async () => {
    setLoading(true);
    await Promise.all([fetchDetail(), fetchSubmissions(1)]);
    setLoading(false);
  })();
}, [fetchDetail, fetchSubmissions]);

Impact

  • If template A had an error and user navigates to template B, the error banner from A persists
  • GitHub data from template A shows until user clicks "Load Analysis" for template B
  • Submissions page number doesn't reset to 1

Fix

Reset all state when draftId changes:

useEffect(() => {
  setError(null);
  setGithubData(null);
  setGithubError(null);
  setSubmissionsPage(1);
  (async () => {
    setLoading(true);
    await Promise.all([fetchDetail(), fetchSubmissions(1)]);
    setLoading(false);
  })();
}, [fetchDetail, fetchSubmissions]);

Severity

Low-Medium — UI shows stale data from previous template. Not a crash but confusing UX.

Phase

Introduced in Phase 2 (PR #27, merged). Also affects Phase 3 GitHub section.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions