Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

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

doodlewinde38e59d4e5c6
diff --git a/blocksuite/affine/shared/src/viewport-renderer/viewport-renderer.ts b/blocksuite/affine/shared/src/viewport-renderer/viewport-renderer.ts
index c62a8f0a6a..91e669c829 100644
--- a/blocksuite/affine/shared/src/viewport-renderer/viewport-renderer.ts
+++ b/blocksuite/affine/shared/src/viewport-renderer/viewport-renderer.ts
@@ -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.std.store.slots.blockUpdated.on(() => {
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() {
this.layoutVersion++;
this.layoutCache = null;
@@ -190,7 +191,10 @@ export class ViewportTurboRendererExtension extends LifeCycleWatcher {
}
private drawCachedBitmap(layout: ViewportLayout) {
- if (!this.tile) return; // version mismatch
+ if (!this.tile) {
+ this.debouncedRefresh();
+ return; // version mismatch
+ }
const bitmap = this.tile.bitmap;
const ctx = this.canvas.getContext('2d');