toeverything/AFFiNE · error · BlockSuiteError

InlineEditorError

InlineEditorError

Error message

yText must not contain "\r" because it will break the range synchronization

What it means

RenderService periodically validates (every 64th yText change) that the inline editor's Y.Text contains no carriage returns, because \r corrupts DOM/range synchronization; throwing turns a silent rendering bug into an explicit data error from upstream content.

Source

Thrown at blocksuite/framework/std/src/inline/services/render.ts:66

    };
    if (!this.editor.isValidInlineRange(newInlineRange)) return;

    this.editor.setInlineRange(newInlineRange);
  };

  private readonly _onYTextChange = (
    _: Y.YTextEvent,
    transaction: Y.Transaction
  ) => {
    this.editor.slots.textChange.next();

    const yText = this.editor.yText;

    if (
      (this._carriageReturnValidationCounter++ & 0x3f) === 0 &&
      yText.toString().includes('\r')
    ) {
      throw new BlockSuiteError(
        ErrorCode.InlineEditorError,
        'yText must not contain "\\r" because it will break the range synchronization'
      );
    }

    if (!transaction.local) {
      this._pendingRemoteInlineRangeSync = true;
    }

    this.render();
  };

  mount = () => {
    const editor = this.editor;
    const yText = editor.yText;

    yText.observe(this._onYTextChange);
    editor.disposables.add({

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Strip carriage returns from text before inserting into yText: text.replace(/\r\n?/g, '\n').
  2. Normalize pasted or imported content to use only \n line endings before applying it to the inline editor.
  3. If the text comes from a file or clipboard, normalize line endings at the import boundary, not inside the editor.

Example fix

function normalizeForYText(text: string): string {
  return text.replace(/\r\n?/g, '\n');
}
yText.insert(0, normalizeForYText(rawText));
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at blocksuite/framework/std/src/inline/services/render.ts:66 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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