ajaxorg / ace

Ace (Ajax.org Cloud9 Editor)
https://ace.c9.io
Other
26.73k stars 5.28k forks source link

Uncaught TypeError: Cannot read properties of null (reading 'splice') #5277

Open hariharan605 opened 1 year ago

hariharan605 commented 1 year ago

Describe the bug

Using ace-build NPM package - Version 1.16.0

Use case 1 :

Uncaught TypeError: Cannot read properties of null (reading 'splice')
    at d.updateFoldWidgets (ace.js:1:147561)
    at r._signal (ace.js:1:12681)
    at d.onChange (ace.js:1:157237)
    at r._signal (ace.js:1:12681)
    at a.applyDelta (ace.js:1:123862)
    at a.insertMergedLines (ace.js:1:122174)
    at a.insert (ace.js:1:121014)
    at d.insert (ace.js:1:165721)
    at S.insert (ace.js:1:232021)
    at Object.exec (ace.js:1:205853)   

and

ace.js:1 Uncaught TypeError: Cannot set properties of null (setting '0')
    at d.updateFoldWidgets (ace.js:1:147438)
    at r._signal (ace.js:1:12681)
    at d.onChange (ace.js:1:157237)
    at r._signal (ace.js:1:12681)
    at a.applyDelta (ace.js:1:123862)
    at a.insertMergedLines (ace.js:1:122174)
    at a.insert (ace.js:1:121014)
    at d.insert (ace.js:1:165721)
    at S.insert (ace.js:1:232021)
    at Object.exec (ace.js:1:205853)

Whenever I try to delete a whole document and enter a new character, it gets printed twice and the above error displayed in console.

Use case 2 :

Uncaught TypeError: Cannot read properties of null (reading 'splice')
    at e.updateFoldWidgets (ace.js:1:159940)
    at r._signal (ace.js:1:12681)
    at e.onChange (ace.js:1:169827)
    at r._signal (ace.js:1:12681)
    at e.applyDelta (ace.js:1:135373)
    at e.remove (ace.js:1:133834)
    at e.remove (ace.js:1:178455)
    at Object.exec (ace.js:1:215613)
    at ace.js:1:203425
    at r._emit.r._dispatchEvent (ace.js:1:12555)

Whenever I try to cut the code, the last two lines of the code gets copied to clipboard whereas other lines were gone and the above error displayed in console.

A help would be seriously appreciable as I struck in this for weeks and couldn't figure out what went wrong here.

Expected Behavior

Use case 1 : No double character printing should happen.

Use case 2 : Cut operation should happen flawlessly.

Current Behavior

Use case 1 : Whenever I try to delete a whole document and enter a new character, it gets printed twice and the above error displayed in console.

Use case 2 : Whenever I try to cut the code, the last two lines of the code gets copied to clipboard whereas other lines were gone and the above error displayed in console.

Reproduction Steps

Use case 1 : Whenever I try to delete a whole document and enter a new character, it gets printed twice and the above error displayed in console.

Use case 2 : Whenever I try to cut the code, the last two lines of the code gets copied to clipboard whereas other lines were gone and the above error displayed in console.

Possible Solution

No response

Additional Information/Context

No response

Ace Version / Browser / OS / Keyboard layout

ace : 1.16.0, macos 12.6.5, Chrome 115.0.5790.114

nightwing commented 1 year ago

This is similar to the error that happens after calling session.destroy() and leaving the destroyed session in the editor. Could you show your code, or a minimal example reproducing the issue?

hariharan605 commented 1 year ago

@nightwing , I haven't used session model, I've directly configured the basePath, modePath and etc.

var CDN = "https://cdn.jsdelivr.net/npm/ace-builds@1.16.0/src-min-noconflict/";
window.ace.config.set('basePath', CDN);
window.ace.config.set('modePath', CDN);
window.ace.config.set('themePath', CDN);
window.ace.config.set('workerPath', CDN);

var editor = window.ace.edit("editor-divId");

this.editor.setOptions({
    mode: 'ace/mode/text',
    theme: 'ace/theme/crimson_editor',
    fontSize: "15px",
    showGutter: true,
    showPrintMargin: false,
    highlightActiveLine: false,
    useWorker: false
});

Here, while changing mode using this.editor.setOption('mode', 'ace/mode/' + mode); , it's causing the issue. But I couldn't narrow down the root cause.

I've never used session concept. If you suggest me to use it, please provide a working example, I'll adapt accordingly.

akoreman commented 1 year ago

Do you get the same issue if you use this.editor.getSession().setMode('ace/mode/' + mode);?

hariharan605 commented 1 year ago

Do you get the same issue if you use this.editor.getSession().setMode('ace/mode/' + mode);?

Yes @akoreman , I tired using the suggested solution. It resulted same. I've a doubt. I haven't set session while initialising but how getSession().setMode() method will work ?

nightwing commented 1 year ago

@hariharan605 are you using the same version for both ace and the cdn? the cdn version of 1.16.0 you are using is a bit old. I have tried to recreate the issue with the code you have provided above, but when versions of cdn url and ace.js match it does not throw an error. See here

github-actions[bot] commented 1 year ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.