fix(editor): use nullable inline editor root element (#9320)

Fixes `sentry-7906c03b79a54ede819c56cc15ad9889`
This commit is contained in:
doodlewind
2024-12-26 07:55:15 +00:00
parent cb4dd127fd
commit 71b5cddea1
16 changed files with 58 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
/* eslint-disable no-useless-escape */
/* oxlint-disable no-useless-escape */
import type { BlockComponent, ExtensionType } from '@blocksuite/block-std';
import {
KEYBOARD_ALLOW_DEFAULT,
@@ -450,6 +450,7 @@ export const LatexExtension = InlineMarkdownExtension({
undoManager.stopCapturing();
if (!inlineEditor.rootElement) return KEYBOARD_ALLOW_DEFAULT;
const blockComponent =
inlineEditor.rootElement.closest<BlockComponent>('[data-block-id]');
if (!blockComponent) return KEYBOARD_ALLOW_DEFAULT;

View File

@@ -103,7 +103,8 @@ export class AffineLink extends ShadowlessElement {
// Please also note that when readonly mode active,
// this workaround is not necessary and links work normally.
get block() {
const block = this.inlineEditor?.rootElement.closest<BlockComponent>(
if (!this.inlineEditor?.rootElement) return null;
const block = this.inlineEditor.rootElement.closest<BlockComponent>(
`[${BLOCK_ID_ATTR}]`
);
return block;

View File

@@ -148,7 +148,8 @@ export class AffineReference extends WithDisposable(ShadowlessElement) {
}
get block() {
const block = this.inlineEditor?.rootElement.closest<BlockComponent>(
if (!this.inlineEditor?.rootElement) return null;
const block = this.inlineEditor.rootElement.closest<BlockComponent>(
`[${BLOCK_ID_ATTR}]`
);
return block;

View File

@@ -138,7 +138,7 @@ export class ReferencePopup extends WithDisposable(LitElement) {
}
get block() {
const block = this.inlineEditor.rootElement.closest<BlockComponent>(
const block = this.inlineEditor.rootElement?.closest<BlockComponent>(
`[${BLOCK_ID_ATTR}]`
);
assertExists(block);