tidalcycles / strudel

Web-based environment for live coding algorithmic patterns, incorporating a faithful port of TidalCycles to JavaScript
https://strudel.cc/
GNU Affero General Public License v3.0
671 stars 115 forks source link

out of range errors break with new codemirror wrapper #178

Closed felixroos closed 1 year ago

felixroos commented 2 years ago

edit from the future: new repro: https://github.com/tidalcycles/strudel/issues/178#issuecomment-1614465496

this is a regression bug: after https://github.com/tidalcycles/strudel/pull/173 , range errors may crash codemirror component. Reproduction:

  1. open repl (main head, not deployed)
  2. press play
  3. press random repeatedly until everything breaks (should not take long)
index.js:801 Uncaught RangeError: Position 594 is out of range for changeset of length 109

it seems this is a missing try catch somewhere inside ui/react-codemirror, probably also on the strudel side. Will need to investigate more.

felixroos commented 2 years ago

It seems this error is not catchable.. I think the issue is that codemirror still tries to highlight a region in the old document after it has been changed (from a longer document to a shorter one). I already tried to handle that case here, but the problem is that the length of the new document is not accessible in that callback..

@mindofmatthew do you have any idea how this could be fixed? It seems impossible to catch this error because it is not thrown in userland:

index.js:801 Uncaught RangeError: Position 534 is out of range for changeset of length 476
    at ChangeSet.mapPos (index.js:801:19)
    at findSharedChunks (index.js:3503:55)
    at RangeSet.compare (index.js:3298:28)
    at findChangedDeco (index.js:2955:14)
    at DocView.update (index.js:2510:24)
    at EditorView.update (index.js:6210:36)
    at EditorView._dispatch (index.js:6092:59)
    at EditorView.dispatch (index.js:6160:14)
    at useCodeMirror.ts:156:12
    at invokePassiveEffectCreate (react-dom.development.js:23487:20)

Might also make sense to get help on the codemirror forums..

felixroos commented 2 years ago

minimal repro: https://codesandbox.io/s/react-codemirror-range-error-i67cs6?file=/src/App.js

felixroos commented 2 years ago

forum post: https://discuss.codemirror.net/t/uncatchable-out-of-range-errors-when-document-changes/4864

felixroos commented 1 year ago

this bug came back after a long holiday of not bugging

new repro: play a pattern, then delete everything while it's running