Potential DataviewJS Render Trigger Anomaly?

TLDR

Is there any documentation that deep dives on Dataview trigger events? I am aware of the periodic refresh, but the below issue seems to bypass this functionality entirely.

Longer version…

Basically: when I open a note with a very long code block, the block does not render and the code continues to be displayed until I scroll beyond it (no clicking; just scrolling). This issue only occurs when the block exists directly in a note - I can bypass the problem by rendering the block using dv.view().

When the note with the code block is opened, I need to scroll beyond the block for it to render - it just displays the code until I scroll past it. No clicking is needed, just scrolling.

There is no async or await activity in the script, and the code is not overly complex - just a bunch of sorting of tasks based on tags.

Below is some pseudocode of the block - I’ve tried to include any functions that are not simply assignments or boilerplate JS:

function embedIncompleteTasks(current_date_str) {
  // dv.pages(fp).filter()       Get files with incomplete tasks
  // files.file.tasks.filter()   Get array of parent tags
  // tasks.forEach()             Loop through all tasks
  // --> tags.forEach()          Loop through parent tags
  // --> task_map.set()          Map tasks to parent tag
  // task_map.forEach()          Loop through all task mapping
  // --> dv.el()                 Header info
  // --> dv.taskList()           Final task list for respective tag
  // [~250 lines]
}

embedIncompleteTasks(current_date_str);

Recreating the scenario

I have attempted to recreate the issue with a simple code example, but I can’t seem to do so. For example:

function myFunc(foo) {
    dv.el(foo);
}

// ... Insert a few lines of empty space ...

myFunc("myFunc");

This recreation attempt renders just fine before I even scroll to it, so I’m guessing there is something in my code that is preventing Dataview from triggering.

Just in case, I tried deactivating all community plug-ins (aside from Dataview) and the issue persists.

If you’re in live preview it’ll show the code block when opening a note where the code block starts at the first line. In this case I’ve sometimes added a single line before the first code block fence, and sometimes also after the last code block fence. This allows me to open the file, and navigate a little easier when there are large code blocks.

Thank you for the reply @holroy!

Apologies, I should have mentioned: this is indeed in edit/preview mode, and not in read mode.

Per your suggestion, I just tried surrounding the code with whitespace both inside and outside of the code block. So:

// [whitespace]
'``dataviewjs
// [whitespace]
function myFunc() {
  // ...
}

myFunc("myFunc");
// [whitespace]
'``
// [whitespace]

Unfortunately the behavior is still the same - I need to scroll to the bottom of the code block before it renders.

Good to know about first-line entries - I’ll keep that in mind. This block is a ways down the page, but thank you for the heads up!

What size is your code block? How many lines (or bytes)?

I’ve not experienced this, and might try to recreate it. Could you post your query in full?