fix(editor): repeated instantiation of frame preview editor (#10729)

Close [BS-2774](https://linear.app/affine-design/issue/BS-2774/frame-preview-会重新创建editor)
This commit is contained in:
L-Sun
2025-03-10 04:41:20 +00:00
parent 4dd5f2ffb0
commit 6b0639facd

View File

@@ -14,6 +14,7 @@ import { DisposableGroup } from '@blocksuite/global/slot';
import { type Query, type Store } from '@blocksuite/store';
import { css, html, nothing, type PropertyValues } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import { guard } from 'lit/directives/guard.js';
import { styleMap } from 'lit/directives/style-map.js';
import debounce from 'lodash-es/debounce';
@@ -151,7 +152,6 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
}
private _renderSurfaceContent() {
if (!this._previewDoc || !this.frame) return nothing;
const { width, height } = this.frameViewportWH;
const _previewSpec = this._previewSpec.value;
@@ -169,10 +169,13 @@ export class FramePreview extends WithDisposable(ShadowlessElement) {
height: `${height}px`,
})}
>
${new BlockStdScope({
store: this._previewDoc,
extensions: _previewSpec,
}).render()}
${guard([this._previewDoc, this.frame], () => {
if (!this._previewDoc || !this.frame) return nothing;
return new BlockStdScope({
store: this._previewDoc,
extensions: _previewSpec,
}).render();
})}
</div>
</div>`;
}