From bcc892c8ec2ff4d88e0fbf89b3db6c76cd135c38 Mon Sep 17 00:00:00 2001 From: congzhou09 Date: Thu, 27 Nov 2025 23:29:19 +0800 Subject: [PATCH] fix(editor): one-time size mismatch during surface-block resize after zoom change in edgeless mode (#14019) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Problem There's a one-time content-size mismatch during surface-block resize after a zoom change in edgeless mode, as shown in the image and video below. 图片 https://github.com/user-attachments/assets/1c0e854c-b12e-4edc-9266-6358e0cf9d5a ### Reason and resolve `Viewport` maintains a `_cachedBoundingClientRect` that stores the synced-doc-block’s bounding box size. This cache is cleared by a ResizeObserver on resizing. In `EmbedSyncedDocBlockComponent`, `fitToContent()` depends on this cache, and is triggered by another ResizeObserver registered in `_initEdgelessFitEffect()`. Since `_initEdgelessFitEffect()` is invoked before the `Viewport`’s ResizeObserver is registered — dut to `_renderSyncedView()` not being called for the first-time in `renderBlock()` — `fitToContent()` reads a stale cached value at the beginning of the resize, resulting in the one-time content-size mismatch. This PR ensures that `_initEdgelessFitEffect()` is called after the registration of the ResizeObserver in `Viewport`. ### After https://github.com/user-attachments/assets/e95815e2-0575-4108-a366-ea5c00efe482 ## Summary by CodeRabbit * **Bug Fixes** * Improved initialization sequence for embedded synced documents to ensure proper rendering and resize handling, preventing potential issues with stale data during component setup. ✏️ Tip: You can customize this high-level summary in your review settings. --- .../embed-synced-doc-block.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts b/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts index 7560dc564f..7b759429b8 100644 --- a/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts +++ b/blocksuite/affine/blocks/embed-doc/src/embed-synced-doc-block/embed-synced-doc-block.ts @@ -56,6 +56,9 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent { const fitToContent = () => { if (this.isPageMode) return; @@ -558,8 +561,6 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent