# \[Enhancement\] Block review.js until the card's front is rendered

**URL:** <https://forums.ankiweb.net/t/enhancement-block-review-js-until-the-cards-front-is-rendered/27984>\
**Category:** Suggestions\
**Created:** [February 28, 2023, 1:12pm UTC](https://forums.ankiweb.net/t/enhancement-block-review-js-until-the-cards-front-is-rendered/27984 "2023-02-28T13:12:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![L.M.Sherlock](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/l.m.sherlock/32/16770_2.png) [@L.M.Sherlock](https://forums.ankiweb.net/u/L.M.Sherlock)\
**Post date:** [February 28, 2023, 1:12pm UTC](https://forums.ankiweb.net/t/enhancement-block-review-js-until-the-cards-front-is-rendered/27984/1 "2023-02-28T13:12:43Z")

</div>

> [@\[Feature Request\] Set Anki custom scheduling per deck/option](https://forums.ankiweb.net/t/feature-request-set-anki-custom-scheduling-per-deck-option/23315/2):
>
> It’s only possible to provide a single block of code, but you can make it behave differently depending on the deck using a bit of a hack: if you add \<div id=deck\>{{Deck}}\</div\> to the card template, your custom scheduling code can extract the deck name from the DOM, and vary its behaviour as necessary.

Sometime, the card’s render is slower than review.js. so the custom scheduling couldn’t get the deck name correctly. Someone reports it to me:

> <https://github.com/open-spaced-repetition/fsrs4anki/issues/172>
>
> \*\*Describe the bug\*\*
> At random, cards appear as "Deck name not found" when disp…lay\_memory\_state is set to true. Usually it happens on the first card of the deck, or if I study on a parent deck and anki jumps between the children decks, but it's not a rule. The deck is set up properly in the config, the proper div object is also present in the card. 
> 
> It looks like a race condition, when FSRS4Anki loads before the card finishes loading. It might be a bug in Anki itself. I see there was an \[attempt\](https://github.com/open-spaced-repetition/fsrs4anki/commit/4c480405d7bb9416b9dfa49d418bb75a045f3ce2) to make it wait for the card to render, but it has been reverted.
> 
> \*\*Environment\*\*
> - Anki version: 2.1.60 QT6
> - OS: Linux (Arch)
> - Scheduler version: v3.14.3
>  
> \*\*Screenshoots\*\*
> !\[image\](https://user-images.githubusercontent.com/5121875/221770937-159a799b-cef5-42a8-a5e3-4c77195f6867.png)
> After going back to main screen and back to study
> !\[image\](https://user-images.githubusercontent.com/5121875/221771393-3e0020f3-fa9a-4952-9475-fadc89615d8d.png)
> 
> The position of the div doesn't seem to matter. I've had it on top of the card and the issue was also present.

Is it possible to block the review.js until the card’s front is rendered?

---

<div class="post-metadata">

**Author:** ![L.M.Sherlock](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/l.m.sherlock/32/16770_2.png) [@L.M.Sherlock](https://forums.ankiweb.net/u/L.M.Sherlock)\
**Post date:** [February 28, 2023, 1:24pm UTC](https://forums.ankiweb.net/t/enhancement-block-review-js-until-the-cards-front-is-rendered/27984/2 "2023-02-28T13:24:55Z")

</div>

I have attempt to use some async method to solve it:

```auto
function wait_card_front() {
  return new Promise(resolve => {
    if (document.getElementById("qa").textContent != "") {
      return resolve(document.getElementById("qa").textContent);
    }
    const observer = new MutationObserver(mutations => {
      if (document.getElementById("qa").textContent != "") {
        resolve(document.getElementById("qa").textContent);
        observer.disconnect();
      }
    });
    observer.observe(document.body, {
      childList: true,
      subtree: true
    });
  });
}

```

But the mutator is not async:

```rust
export async function mutateNextCardStates(
    key: string,
    mutator: (states: Scheduler.SchedulingStates, customData: CustomDataStates) => void,
): Promise<void> {
    const states = await getSchedulingStates();
    const customData = unpackCustomData(states);
    mutator(states, customData);
    packCustomData(states, customData);
    await setSchedulingStates(key, states);
}

```

So the states and customData aren’t modified when I use async method in the custom scheduling.

---

<div class="post-metadata">

**Author:** ![L.M.Sherlock](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/l.m.sherlock/32/16770_2.png) [@L.M.Sherlock](https://forums.ankiweb.net/u/L.M.Sherlock)\
**Post date:** [February 28, 2023, 1:34pm UTC](https://forums.ankiweb.net/t/enhancement-block-review-js-until-the-cards-front-is-rendered/27984/3 "2023-02-28T13:34:25Z")

</div>

A related issue:

> <https://github.com/open-spaced-repetition/fsrs4anki/issues/161>
>
> \*\*Describe the bug\*\*
> If I click "Show Answer" while reviewing a card, then go b…ack to "Decks", then review the card again, I get different intervals. I don't think this was a problem before 2.1.58, or maybe I just didn't notice.
> EDIT: I reverted back to 2.1.54 and yes, it works properly.
> EDIT 2: nevermind, it doesn't work on 2.1.54, now I'm just really confused
> !\[image\](https://user-images.githubusercontent.com/83031600/220406252-fe8464b0-22b7-439a-86e9-5012e00d1e5b.png)
> EDIT 3: ok, I deleted all Anki files and did a fresh installation of 2.1.55 (not 2.1.54) and I \_think\_ it works fine.
> EDIT 4: I give up, I don't know what the hell is going on. Maybe after many re-installations I messed something up so bad that now every re-installation is broken.
> !\[image\](https://user-images.githubusercontent.com/83031600/220408594-d5c50d82-5930-4f66-a5ce-662f0bdd93e1.png)
> 
> 
> 
> \*\*To Reproduce\*\*
> Steps to reproduce the behavior:
> 1. Review a card and click "Show Answer"
> 2. Don't click on answer buttons and click on "Decks" instead to cancel the review
> 3. Review that card again
> 4. See that intervals are different
> 
> \*\*Expected behavior\*\*
> Intervals shouldn't change if I cancel a review and review again.
> 
> \*\*Screenshots\*\*
> !\[image\](https://user-images.githubusercontent.com/83031600/220402653-be530ca9-2064-434e-876f-774e6f3ad9be.png)
> 
> \*\*Environment\*\*
> - Anki version: 2.1.58, Qt 6.4.2, PyQt 6.4.0
> - OS: Windows 10
> - Scheduler version: v3.13.4

Sometime the intervals above rating buttons are inconsistent with the intervals given by custom scheduling. After pressing the button and checking the previous card’s info, the recorded interval is the one given by custom scheduling instead of the one above the button. Maybe it is caused by the async problem, too.

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [March 1, 2023, 7:09am UTC](https://forums.ankiweb.net/t/enhancement-block-review-js-until-the-cards-front-is-rendered/27984/4 "2023-03-01T07:09:32Z")

</div>

I’ve logged this on [Don't run custom scheduling code until cards have finished rendering · Issue #2409 · ankitects/anki · GitHub](https://github.com/ankitects/anki/issues/2409)
