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

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:

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

1 Like

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

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 != "") {
    observer.observe(document.body, {
      childList: true,
      subtree: true

But the mutator is not async:

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.

A related issue:

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.

I’ve logged this on Don't run custom scheduling code until cards have finished rendering · Issue #2409 · ankitects/anki · GitHub

1 Like