refactor(editor): request refresh after finding stale bitmap (#10438)

This ensures a bitmap will be eventually generated after tile got invalidated.
This commit is contained in:
doodlewind
2025-02-26 06:49:09 +00:00
parent 7dbc1e300d
commit e38e59d4e5

View File

@@ -67,17 +67,10 @@ export class ViewportTurboRendererExtension extends LifeCycleWatcher {
); );
}); });
const debouncedRefresh = debounce(
() => {
this.refresh().catch(console.error);
},
1000, // During this period, fallback to DOM
{ leading: false, trailing: true }
);
this.disposables.add( this.disposables.add(
this.std.store.slots.blockUpdated.on(() => { this.std.store.slots.blockUpdated.on(() => {
this.invalidate(); this.invalidate();
debouncedRefresh(); this.debouncedRefresh();
}) })
); );
} }
@@ -115,6 +108,14 @@ export class ViewportTurboRendererExtension extends LifeCycleWatcher {
} }
} }
debouncedRefresh = debounce(
() => {
this.refresh().catch(console.error);
},
1000, // During this period, fallback to DOM
{ leading: false, trailing: true }
);
invalidate() { invalidate() {
this.layoutVersion++; this.layoutVersion++;
this.layoutCache = null; this.layoutCache = null;
@@ -190,7 +191,10 @@ export class ViewportTurboRendererExtension extends LifeCycleWatcher {
} }
private drawCachedBitmap(layout: ViewportLayout) { private drawCachedBitmap(layout: ViewportLayout) {
if (!this.tile) return; // version mismatch if (!this.tile) {
this.debouncedRefresh();
return; // version mismatch
}
const bitmap = this.tile.bitmap; const bitmap = this.tile.bitmap;
const ctx = this.canvas.getContext('2d'); const ctx = this.canvas.getContext('2d');