kleinerpirat / anki-tooltips

Add tooltips to your Anki cards with Tippy.js
GNU Affero General Public License v3.0
10 stars 0 forks source link

Crash in browser due to missing callbacks in lifecycle.onMount #4

Closed kleinerpirat closed 1 year ago

kleinerpirat commented 1 year ago

As reported on the forum (https://forums.ankiweb.net/t/tippy-tooltips-official-support/11844/133), the reloading of Svelte components such as the toolbar or fields causes a crash:

Uncaught (in promise) TypeError: cleanup is not a function
    at browser_editor.js:64505:13
    at run (browser_editor.js:61762:12)
    at Array.forEach (<anonymous>)
    at run_all (browser_editor.js:61768:9)
    at destroy_component (browser_editor.js:63416:7)
    at Object.d (browser_editor.js:109016:9)
    at Object.d (browser_editor.js:65379:24)
    at destroy_component (browser_editor.js:63417:34)
    at Object.d (browser_editor.js:109065:9)
    at Object.d (browser_editor.js:89279:32)

Relevant code:

            return () => {
                for (const cleanup of cleanups) {
                    cleanup();
                }
            };

https://github.com/ankitects/anki/blob/5e0a761b875fff4c9e4b202c08bd740c7bb37763/ts/sveltelib/lifecycle-hooks.ts#L43-L47

The way the API is written currently, one must provide a cleanup function, otherwise the App will crash. Also, it has to be synchronous (although most Svelte interactions require awaiting an element). I will try to improve this upstream, but for now need to fix this issue with somewhat verbose callbacks.