utility.js: Make loadData() a sync function #1068
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.