toeverything/AFFiNE · error

failed to fitViewPort

Error message

failed to fitViewPort

What it means

Warning logged in `fitViewport` when positioning the peek-preview editor viewport throws — for example Bound.deserialize failing on a malformed xywh string or the gfx viewport APIs throwing. The preview still shows; it is just not scrolled/zoomed to the target region.

Source

Thrown at packages/frontend/core/src/modules/peek-view/view/doc-preview/doc-peek-view.tsx:69

    viewport.onResize();

    if (xywh) {
      const newViewport = {
        xywh: xywh,
        padding: [60, 20, 20, 20] as [number, number, number, number],
      };
      viewport.setViewportByBound(
        Bound.deserialize(newViewport.xywh),
        newViewport.padding,
        false
      );
    } else {
      gfx.fitToScreen({
        smooth: false,
      });
    }
  } catch (e) {
    logger.warn('failed to fitViewPort', e);
  }
}

function DocPeekPreviewEditor({
  xywh,
}: {
  xywh?: `[${number},${number},${number},${number}]`;
}) {
  const { editorService } = useServices({
    EditorService,
  });
  const editor = editorService.editor;
  const doc = editor.doc;
  const workspace = editor.doc.workspace;
  const mode = useLiveData(editor.mode$);
  const defaultOpenProperty = useLiveData(editor.defaultOpenProperty$);
  const workbench = useService(WorkbenchService).workbench;
  const peekView = useService(PeekViewService).peekView;

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Retry fitViewPort after the editor finishes rendering.
  2. Check the editor has a valid viewport before calling.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Triggered when setViewportByBound or fitToScreen throws while initializing the peek-view doc preview viewport, e.g. invalid xywh bounds or an unready surface.

Common situations: Occurs when opening a doc peek preview with a malformed saved viewport or before the editor surface is ready. The preview still renders; reopen it if positioning is off.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/693f08a679c19df3. Report an issue: GitHub.