ankitects / ankitects/anki

EditorField instances not ordered according to DOM tree once new fields are mounted

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

Description

https://github.com/ankitects/anki/blob/50e36bc312b64c59fcd53c283596daeeaba9521e/ts/sveltelib/lifecycle-hooks.ts#L41-L42

Mounting new fields (e.g. when switching from Basic to Basic + reverse card) shifts the initial fields to the end of `EditorField.instances`:

![image](https://user-images.githubusercontent.com/62722460/180394761-28c04277-746f-419c-bc46-bb3a7e158ffb.png)
![image](https://user-images.githubusercontent.com/62722460/180394900-018026dc-a91e-4cf5-af87-23a3833bd027.png)
![image](https://user-images.githubusercontent.com/62722460/180394948-8d2b588c-0ea5-4dff-b5db-1d45d587b728.png)

Developers will assume the instances are ordered according to their appearance in the DOM tree, so we should handle the case where instances is already filled with something like:

```
instances = oldInstances.concat(newInstances);
```

The `setup` function of `lifecycleHooks` seems to be oblivious to the bigger picture (in this case, the difference between mounting fields when loading the first note and appending new fields when switching to another note). Any ideas?

Contributor guide

Open the contributing guide

Research direction

Read ts/sveltelib/lifecycle-hooks.ts around lines 41-42, then reproduce the case where switching from Basic to Basic + reverse card mounts new fields. The change is done when EditorField.instances remains ordered according to the fields' appearance in the DOM after new fields are mounted.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.