handsontable / hyperformula

HyperFormula is an open-source headless spreadsheet for business web apps. It comes with over 400 formulas, CRUD operations, undo-redo, clipboard support, and sorting.
https://hyperformula.handsontable.com/
Other
1.95k stars 108 forks source link

destroy(), unregisterFunctionPlugin, unregisterAllFunctions not removing custom plugins #775

Closed MartinDawson closed 3 years ago

MartinDawson commented 3 years ago

Description

The above functions should all remove hyperformula instance registered custom plugins.

Steps to reproduce

// Register the custom function plugin
HyperFormula.registerFunctionPlugin(CountHF, countHFTranslations);

// Create an empty HyperFormula instance.
const hf = HyperFormula.buildEmpty({
  licenseKey: "gpl-v3"
});

console.log(hf.getAllFunctionPlugins());

HyperFormula.unregisterFunctionPlugin(CountHF);
HyperFormula.unregisterAllFunctions();
hf.destroy();

console.log(hf.getAllFunctionPlugins());

image

Demo

https://codesandbox.io/s/github/handsontable/hyperformula-demos/tree/0.6.x/vanillajs-demo?from-embed=&file=/src/hyperformulaConfig.js

Your environment

I ran into this issue when testing this PR: https://github.com/handsontable/hyperformula/pull/766

Thanks.

wojciechczerniak commented 3 years ago

Calling method on an instance that is destroyed should not be possible:

hf.destroy();

console.log(hf.getAllFunctionPlugins());

So this is a bug IMO.

The second part with

HyperFormula.registerFunctionPlugin(CountHF, countHFTranslations);

HyperFormula.unregisterFunctionPlugin(CountHF);

we will have to investigate. AFAIK plugin should be removed globally 🤔 Thanks for reporting.

izulin commented 3 years ago

The second part with

HyperFormula.registerFunctionPlugin(CountHF, countHFTranslations);

HyperFormula.unregisterFunctionPlugin(CountHF);

we will have to investigate. AFAIK plugin should be removed globally 🤔 Thanks for reporting.

AFAIR it's not a bug. Look at this code:

    HyperFormula.unregisterAllFunctions()
    HyperFormula.registerFunctionPlugin(FooPlugin)
    const engine = HyperFormula.buildEmpty()
    HyperFormula.unregisterFunctionPlugin(FooPlugin)
    console.log(engine.getAllFunctionPlugins())

engine was created when registered statically plugins contained FooPlugin. Removing it statically did not affect after engine was created. So the output is [FooPlugin].

Do you see a way around it? For me it's working as designed.

wojciechczerniak commented 3 years ago

Done in #788