question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: ...TypeError: destroy is not a function...from commitHookEffectListUnmount()

See original GitHub issue

This error pops up whenever I save to refresh (fast refresh)…it goes away when I make a different change only to re-appear in the next other change. appear-disappear-appear…

Unhandled Runtime Error
TypeError: destroy is not a function

Call Stack
commitHookEffectListUnmount
node_modules/react-dom/cjs/react-dom.development.js (19710:0)
commitPassiveHookEffects
/_next/static/chunks/main.js (40064:11)
HTMLUnknownElement.callCallback
node_modules/react-dom/cjs/react-dom.development.js (188:0)
Object.invokeGuardedCallbackDev
/_next/static/chunks/main.js (20533:16)
invokeGuardedCallback
node_modules/react-dom/cjs/react-dom.development.js (292:0)
flushPassiveEffectsImpl
/_next/static/chunks/main.js (43149:9)
unstable_runWithPriority
node_modules/scheduler/cjs/scheduler.development.js (653:0)
runWithPriority$1
/_next/static/chunks/main.js (31335:10)
flushPassiveEffects
node_modules/react-dom/cjs/react-dom.development.js (22820:0)
<unknown>
/_next/static/chunks/main.js (42995:11)
workLoop
node_modules/scheduler/cjs/scheduler.development.js (597:0)
flushWork
/_next/static/chunks/main.js (49188:16)
MessagePort.performWorkUntilDeadline
node_modules/scheduler/cjs/scheduler.development.js (164:0)

I’m running on…

 "react": "^16.13.1",
 "react-dom": "^16.13.1",

I believe it comes from here

function commitHookEffectListUnmount(tag, finishedWork) {
  var updateQueue = finishedWork.updateQueue;
  var lastEffect = updateQueue !== null ? updateQueue.lastEffect : null;

  if (lastEffect !== null) {
    var firstEffect = lastEffect.next;
    var effect = firstEffect;

    do {
      if ((effect.tag & tag) === tag) {
        // Unmount
        var destroy = effect.destroy;
        effect.destroy = undefined;

        // THIS IS WHERE IT HAPPENS...WHY NOT
        // CHECK IF IT'S AN ACTUAL FUNCTION ???
        if (destroy !== undefined) {
          destroy();
        }
      }

      effect = effect.next;
    } while (effect !== firstEffect);
  }
}

Scoped

        if (destroy !== undefined) {
          destroy();
        }

Even though it’s not undefined, it might also not be a function…I assume that’s the case so why not check to see if its an actual function before calling it?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16

github_iconTop GitHub Comments

2reactions
aberbacommented, Oct 1, 2020

Oops if (status === "collected" || status === "cancelled") return true; might be the devil

1reaction
eps1loncommented, Oct 1, 2020

if (status === “collected” || status === “cancelled”) return true;

There you are returning something other than undefined or a function.

To return early you can return nothing:

-if (status === "collected" || status === "cancelled") return true;
+if (status === "collected" || status === "cancelled") return;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix the "Uncaught TypeError: destroy is not a function" Error in ...
This React error seems particularly cryptic, but ends up making a lot of sense when you get the hang of the useEffect hook....
Read more >
React — Uncaught TypeError: destroy is not a function - Medium
While experimenting with useEffect hooks in React and React Native, I came across the following error: and my app was unable to run....
Read more >
Getting error after I put Async function in useEffect
If you return anything from useEffect , it has to be a function. ... A Promise is not a function. so React stumbles...
Read more >
typeerror: destroy is not a function at safelycalldestroy - You.com
This causes the error when the component is unmounting due to navigation. Solution. There's no reason for the callback to be async ,...
Read more >
Getting error "destroy is not a function" in Plasmic Studio
Uncaught TypeError: destroy is not a function at safelyCallDestroy (react-dom.development.js?ac89:22932:1) at commitHookEffectListUnmount ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found