Skip to content

Crash: Cannot read properties of undefined (reading 'range') #55

@pmachapman

Description

@pmachapman

On Scripture Forge, our users have been reported crashes from Lynx while using the editor.

I have narrowed down the source of the crashes to Lynx not correctly handling the addition of delta ops to the end of a scripture delta document, as demonstrated by the following test:

 it('add paragraph at end of document', () => {
    const document = new ScriptureDeltaDocument(
      'uri',
      'scr-delta',
      1,
      new Delta()
        .insert({ chapter: { number: '1', style: 'c' } })
        .insert({ verse: { number: '1', style: 'v' } })
        .insert('This is a test.', { segment: 'verse_1_1' })
        .insert('\n', { para: { style: 'p' } })
        .insert({ verse: { number: '2', style: 'v' } })
        .insert('This is a test.', { segment: 'verse_1_2' })
        .insert('\n', { para: { style: 'p' } }),
    );

    document.update(
      new Delta()
        .retain(35)
        .insert('section header.', { segment: 's_1' })
        .insert('\n', { para: { style: 's' } }),
      2,
    );

    expect(document.children.length).toEqual(4);

    const paragraph2 = document.children[2];
    expect(paragraph2.getText()).toEqual(`\ufffcThis is a test.\n`);
    expect(paragraph2.range).toEqual({ start: { line: 2, character: 0 }, end: { line: 3, character: 0 } });

    const paragraph3 = document.children[3];
    expect(paragraph3.getText()).toEqual(`section header.\n`);
    expect(paragraph3.range).toEqual({ start: { line: 3, character: 0 }, end: { line: 4, character: 0 } });
  });

See also: https://app.bugsnag.com/sil-international/scripture-forge-v2-plus/errors/6945181b5d860bbd2087fadf

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions