Skip to content

Conversation

@slusarz
Copy link
Contributor

@slusarz slusarz commented Nov 6, 2024

We always want loadData() to be a blocking call, as we use that code to read the data JS files so that we can do further processing.

However, since data JS paths are dynamic, we must use import() which is required to be an async call.

For bootstrapping purposes, this means there is no way to block markdown processing to begin before the Dovecot markdown plugin is ready. This is because markdown-it code MUST NOT use async code, so we need to load all the data (via loadData()) before it can be initialized. Dovecot markdown code also requires VitePress paths to be available in global config object, so the only place we can realistically add the Dovecot markdown processing is via the "config" markdown option. Unfortunately, the internal VitePress code does not call this function with await, so there is simply no way to block processing via this mechanism.

Solution- the import-sync nodejs package allows import behavior to be done synchronously.

This allows us to no longer need to pre-configure the dovecot markdown plugin, as the loadData() calls can now be called on-demand inside of the plugin. Thus, we can guarantee that the Dovecot markdown plugin is initialized at the time the first page is processed by VitePress now.

We always want loadData() to be a blocking call, as we use that code to
read the data JS files so that we can do further processing.

However, since data JS paths are dynamic, we must use import() which is
required to be an async call.

For bootstrapping purposes, this means there is no way to block markdown
processing to begin before the Dovecot markdown plugin is ready. This is
because markdown-it code MUST NOT use async code, so we need to load all the
data (via loadData()) before it can be initialized. Dovecot markdown code
also requires VitePress paths to be available in global config object, so the
only place we can realistically add the Dovecot markdown processing is via the
"config" markdown option. Unfortunately, the internal VitePress code does not
call this function with await, so there is simply no way to block processing
via this mechanism.

Solution- the import-sync nodejs package allows import behavior to be done
synchronously.

This allows us to no longer need to pre-configure the dovecot markdown plugin,
as the loadData() calls can now be called on-demand inside of the plugin. Thus,
we can guarantee that the Dovecot markdown plugin is initialized at the time
the first page is processed by VitePress now.
@cmouse cmouse merged commit 0c12d5e into dovecot:main Nov 6, 2024
5 checks passed
@slusarz slusarz deleted the loadData_sync branch January 15, 2025 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants