Trouble with addHooke, removeHook, then addHook again

I recently noice in version 16.1.1 that when you remove an afterChange Hook callback, then is not possible to add it again using addHook(‘afterChange‘, callback).

It seems that once the callback is added to pluginHookBucket.getHooks(‘afterChange’), then the removeHook call sets skip flag to true but then addHookfails to set skip = false .

hot.addHook('afterChange', onAfterChange);
console.log(hot.pluginHookBucket.getHooks('afterChange')[1])
// Object { callback: onAfterChange(data), 
//          orderIndex: 0, 
//          runOnce: false, 
//          initialHook: false,
//          skip: false }

hot.removeHook('afterChange', onAfterChange);
console.log(hot.pluginHookBucket.getHooks('afterChange')[1])
// Object { callback: onAfterChange(data), 
//          orderIndex: 0,
//          runOnce: false,
//          initialHook: false,
//          skip: true }

hot.addHook('afterChange', onAfterChange);
console.log(hot.pluginHookBucket.getHooks('afterChange')[1])
// Object { callback: onAfterChange(data),
//          orderIndex: 0,
//          runOnce: false,
//          initialHook: false,
//          skip: true }

The issue is that can’t fire afterChange again. I came across this result while tracking down a failure with addHookOnce maybe it has the same issue.

Is it possible that addHooke doesn’t do anything if the object is already present tough it is flagged as skipped?

The issue is resolved if the skip flag is changed directly:

hot.pluginHookBucket.getHooks('afterChange')[1].skip=false

Thank you for sharing this issue report, @salvador

I was able to replicate the issue. It seems that 14.6.2 is the last working version, and the regression was introduced in v15.0.0.

I will report it internally and update you as soon as it gets fixed.

Thank you for your fast reply

I tried version 14.6.2 with addHook and addHookOnce, both succesfully able the hook to fire the callback. :slight_smile:

1 Like

Hi @salvador

Please try v16.2.0 - released today. This issue should be fixed.