Skip to content

Fix missing setTimeout cleanup in onboarding tour retry logic #950

@MODSetter

Description

@MODSetter

Description

The onboarding tour component uses recursive setTimeout calls to retry finding target elements, but only the initial setTimeout is cleaned up on unmount. The inner retry setTimeout calls (line ~575, ~480) are never cancelled, which can cause state updates on unmounted components.

Files to Update

  • surfsense_web/components/onboarding-tour.tsx (lines ~558–581 and ~478–488)

What to Do

Use a ref to track whether the effect is still active, and skip state updates after cleanup:

// For the checkAndStartTour retry pattern (lines ~558-581):
useEffect(() => {
  let cancelled = false;

  const checkAndStartTour = () => {
    if (cancelled) return;
    
    const connectorEl = document.querySelector(...);
    // ...
    if (connectorEl && documentsEl && inboxEl) {
      // start tour
    } else {
      setTimeout(checkAndStartTour, 200);  // recursive retry
    }
  };

  const timer = setTimeout(checkAndStartTour, 500);
  return () => {
    cancelled = true;
    clearTimeout(timer);
  };
}, [/* deps */]);

Apply the same cancelled flag pattern to the updateTarget retry logic (lines ~478–488). The flag ensures that after cleanup, no further setTimeout callbacks will attempt DOM queries or state updates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions