fix(editor): block can be null in widget (#10959)

Closes: [BS-2826](https://linear.app/affine-design/issue/BS-2826/typeerror-thisblock-is-null)
This commit is contained in:
Saul-Mirone committed 2025-03-18 10:58:19 +00:00
1 parent b7ab49a263
commit 321e3449ec
17 files changed
+118 -55

No files matched your search

@@ -161,6 +161,8 @@ export class PointerEventWatcher {
if (this.widget.isGfxDragHandleVisible) return;
const point = new Point(state.raw.x, state.raw.y);
if (!this.widget.rootComponent) return;
const closestBlock = getClosestBlockByPoint(
this.widget.host,
this.widget.rootComponent,
@@ -246,6 +248,8 @@ export class PointerEventWatcher {
// When pointer on drag handle, should do nothing
if (element.closest('.affine-drag-handle-container')) return;
if (!this.widget.rootComponent) return;
// When pointer out of note block hover area or inside database, should hide drag handle
const point = new Point(state.raw.x, state.raw.y);
@@ -284,6 +284,9 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
}
private _initLabels() {
if (!this.block) {
return;
}
const { service } = this.block;
const surfaceRefs = service.doc
.getBlocksByFlavour('affine:surface-ref')
@@ -144,6 +144,10 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
}
private _getCursorRect(selections: BaseSelection[]): SelectionRect | null {
if (!this.block) {
return null;
}
if (this.block.model.flavour !== 'affine:page') {
console.error('remote selection widget must be used in page component');
return null;
@@ -208,6 +212,10 @@ export class AffineDocRemoteSelectionWidget extends WidgetComponent {
private readonly _getSelectionRect = (
selections: BaseSelection[]
): SelectionRect[] => {
if (!this.block) {
return [];
}
if (this.block.model.flavour !== 'affine:page') {
console.error('remote selection widget must be used in page component');
return [];
@@ -105,7 +105,7 @@ export class AffineSlashMenuWidget extends WidgetComponent {
}
};
if (this.block.model.flavour !== 'affine:page') {
if (this.block?.model.flavour !== 'affine:page') {
console.error('SlashMenuWidget should be used in RootBlock');
return;
}