Skip to content

Bug Report: visualFeedback elements get added multiple times #24

@h16nning

Description

@h16nning

Hi!

First of all, thank you for this wonderful add-on!

I recently discovered that the opacity of the colored overlay in the "flashcard" theme is very high – sometimes to the point where you'll even see color banding.

However, this only occurred for one note type I was using. I did some investigating and I think I found the problematic code:

The problem occurs when the onLoad function and will thus add multiple visualFeedback items for every position. I confirmed this with inspector and a few debug logs.

I suggest checking if an element exists before adding it.

  function onLoad() {
    for (const pos of ["top", "bottom", "left", "right"]) {

      // check if the element exists before adding it
      if (
        document.getElementsByClassName(`visualFeedback ${pos}`).length > 0
      ) {
        continue;
      }

      const div = visualFeedbackDiv();
      div.classList.add(pos);
    }
  }

Implementing this check fixed the issue for me.

The note type in question (which is actually a modified AnKing note type) is manually dispating a window load, which in turn causes the onLoad function to be called multiple times. Of course it would be best to avoid multiple window load events alltogether… but some note types / extensions may rely on that, so a tiny check on load like this is be the most robust solution.

While this bug is most noticeable for the "flashcard" theme as it featured semi-transparent elements, the general problem should apply to all themes (not tested though).

If you would like to, I can open a pr with changes to all themes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions