Skip to content

Fix memory leak from uncancelled timeouts in Share component#23

Merged
AccessiT3ch merged 3 commits intofeature/phase1.4-web-api-error-handlingfrom
copilot/sub-pr-20-again
Feb 1, 2026
Merged

Fix memory leak from uncancelled timeouts in Share component#23
AccessiT3ch merged 3 commits intofeature/phase1.4-web-api-error-handlingfrom
copilot/sub-pr-20-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 1, 2026

The Share component's setTimeout calls were not cleaned up on unmount, causing React to attempt state updates on unmounted components.

Changes:

  • Store timeout ID in ref for lifecycle management
  • Add useEffect cleanup to cancel pending timeout on unmount
  • Clear existing timeout before setting new one to prevent concurrent timeouts
const timeoutRef = useRef(null);

useEffect(() => {
  return () => {
    if (timeoutRef.current) {
      clearTimeout(timeoutRef.current);
    }
  };
}, []);

const handleShare = async (e) => {
  // Clear any existing timeout before setting a new one
  if (timeoutRef.current) {
    clearTimeout(timeoutRef.current);
  }

  await shareHandler({
    onSuccess: (message) => {
      timeoutRef.current = setTimeout(() => {
        setShareStatus({ type: null, message: "" });
      }, 3000);
    },
    // ...
  });
};

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 1, 2026 08:21
Co-authored-by: AccessiT3ch <95449364+AccessiT3ch@users.noreply.github.com>
Co-authored-by: AccessiT3ch <95449364+AccessiT3ch@users.noreply.github.com>
@AccessiT3ch AccessiT3ch marked this pull request as ready for review February 1, 2026 08:22
Copilot AI changed the title [WIP] Address feedback on comprehensive error handling for web APIs Fix memory leak from uncancelled timeouts in Share component Feb 1, 2026
Copilot AI requested a review from AccessiT3ch February 1, 2026 08:23
@AccessiT3ch AccessiT3ch merged commit 9c441bf into feature/phase1.4-web-api-error-handling Feb 1, 2026
1 check passed
@AccessiT3ch AccessiT3ch deleted the copilot/sub-pr-20-again branch February 1, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants