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

Calling editor.getSession().setMode('jsx), then quickly calling editor.destroy() causes null getLength error #5681

Open
jjfrankovich opened this issue Nov 20, 2024 · 2 comments

Comments

@jjfrankovich
Copy link

Describe the bug

I just upgraded from 1.1.9 to 1.36.5 and I am running into an issue with calling editor.getSession().setMode, then destroying with :
editor.destroy()

build	19-Nov-2024 20:58:07	  Uncaught TypeError: Cannot read properties of null (reading 'getLength')
build	19-Nov-2024 20:58:07	  at http://localhost:9876/module/js/rc/ace/ace.js:1

It looks to me like their are race conditions within the event handling such that its not accounting for this scenario.

I am currently working around the issue by waiting 100ms before allowing a destroy() call to run. My tests were still sometimes even failing with a 60 ms delay.

Expected Behavior

Ideally, if it was safe to call setMode then quickly call destroy in 1.1.9, it would be safe to do so in 1.36.5

Current Behavior

I get an errorwhen calling destroy soon after calling setMode like with setMode ('jsx')

Reproduction Steps

set setMode to change the mode,
then quickly call editor.destory without any much delay (a 6ms to 100ms wait is required to avoid an event error)

Possible Solution

make setMode and destroy promise based so setMode can wait to return so it can be destroyed right after.

Additional Information/Context

No response

Ace Version / Browser / OS / Keyboard layout

1.36.5

@nlujjawal
Copy link
Contributor

I was not able to reproduce the error when executing in ace editor.
editor.getSession().setMode('jsx');
editor.destroy;

Can you provide the un-minified files stack trace for the error,
or more detailed reproduction steps.

@jjfrankovich
Copy link
Author

jjfrankovich commented Nov 20, 2024

Here is a code pen to reproduce the issue with an unminified version of ace:

https://codepen.io/blueShell/pen/ZEgdLPp

ace.js:8115 Uncaught TypeError: Cannot read properties of null (reading 'getLength')
    at BackgroundTokenizer.start (ace.js:8115:79)
    at BackgroundTokenizer.setTokenizer (ace.js:8099:14)
    at EditSession.$onChangeMode (ace.js:10871:26)
    at EditSession.<anonymous> (ace.js:10849:22)
    at ace.js:1281:31
    at Array.forEach (<anonymous>)
    at ace.js:1280:27
    at ace.js:1336:9
    at _require (ace.js:88:37)
    at req (ace.js:138:24)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants