Slightly optimize vertical jiggering by pre-computing all widgets on page load

This commit is contained in:
Zef Hemel
2026-05-12 09:38:17 +02:00
parent 32d0ee8f64
commit a96a86c0b5
6 changed files with 61 additions and 6 deletions
+17 -3
View File
@@ -73,6 +73,20 @@ export class LuaWidget extends WidgetType {
openRef: null,
...opts,
};
// Eagerly kick off the widget callback so the query result is ready
// (or close to it) by the time CodeMirror mounts the widget. Idempotent
// on cacheKey — the decorator state field rebuilds widgets on every
// editor update, but only the first construction per cacheKey starts
// the actual fetch.
this.opts.client.widgetCache.prewarmResult(this.opts.cacheKey, () =>
this.opts.callback(
this.opts.expressionText,
this.opts.client.currentName(),
),
).catch(() => {
// Ignore: renderContent re-awaits the same promise and handles
// errors via its own catch path.
});
}
override get estimatedHeight(): number {
@@ -136,9 +150,9 @@ export class LuaWidget extends WidgetType {
async renderContent(div: HTMLElement) {
const currentName = this.opts.client.currentName();
let widgetContent = await this.opts.callback(
this.opts.expressionText,
currentName,
let widgetContent = await this.opts.client.widgetCache.prewarmResult(
this.opts.cacheKey,
() => this.opts.callback(this.opts.expressionText, currentName),
);
activeWidgets.add(this);
if (widgetContent === null || widgetContent === undefined) {