ankitects / ankitects/anki

Async callback on EditorField lifecycle hook causes error when switching to notetype with fewer fields

Open
#1,959 3 comments 0 reactions 0 assignees View on GitHub
editor
Dominant language
Rust
Stars
30.5k
Forks
3.2k
Avg merge
2d 8h
Merged PRs (30d)
60

Description

While debugging https://github.com/hgiesel/closet/issues/96 I noticed the following error message when switching notetypes in the browser:

```
Uncaught (in promise) TypeError: cleanup is not a function
at browser_editor.js:33322
at run (browser_editor.js:30587)
at Array.forEach ()
at run_all (browser_editor.js:30593)
at destroy_component (browser_editor.js:32224)
at Object.d (browser_editor.js:78807)
at browser_editor.js:31587
at run (browser_editor.js:30587)
at Array.forEach ()
at run_all (browser_editor.js:30593)
```

This is the relevant function:
https://github.com/ankitects/anki/blob/50e36bc312b64c59fcd53c283596daeeaba9521e/ts/sveltelib/lifecycle-hooks.ts#L29-L49

## Reproduction steps
1. Add async callback to EditorField (e.g. with `webview_will_set_content` hook):
`require("anki/EditorField").lifecycle.onMount(async () => console.log("mounted")); `
2. switch to a notetype with fewer fields to cause a `cleanup()` call

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.