Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parent Parent's cache is not getting invalidated #4264

Open
vinodgubbala opened this issue Jun 21, 2024 · 0 comments
Open

Parent Parent's cache is not getting invalidated #4264

vinodgubbala opened this issue Jun 21, 2024 · 0 comments

Comments

@vinodgubbala
Copy link

vinodgubbala commented Jun 21, 2024

When a nested element is being modified, the cache of the parent's parent is not being invalidated.
This is causing the lengths and index calculations being wrong.

Steps for Reproduction

it('Cache issue', async () => {
  let quillRef = {};
  render(<QuillEditor html={`
    <p><b>1<i>2</i>3</b></p>
    <p><i>567</b=i></p>
  `} quillRef={quillRef}/>);
  const quill = quillRef.quill;
  
  // get all italics
  const italics = quill.scroll.descendants(Italic);

  // Get index of italic, so cache is generated
  const index1 = quill.getIndex(italics[0]);
  expect(index1).toBe(1);

  //replace italic with longer text
  italics[0].replaceWith('text', '21234');

  // get index of next line   
  const index2 = quill.getIndex(italics[1]);
  expect(index2).toBe(8); // But 4
});

Expected behavior: Index or length to be recalculated

Actual behavior: Index or length being returned from last calculation

Platforms: Any platform

Version: 2.0.2

I had to do this as a workaround right now.

while (parent !== blot.scroll) {
  if ('cache' in parent) {
    // @ts-ignore
    parent.cache = {};
  }
  parent = parent.parent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant