firepad icon indicating copy to clipboard operation
firepad copied to clipboard

TypeError: Cannot read property 'replace' of undefined on ACEAdapter.setOtherCursor in ACE with multiple sessions

Open hpneo opened this issue 8 years ago • 0 comments

Version info

Firebase: 3.3.0 Firepad: 1.4.0 Ace: 1.2.5

Test case

http://embed.plnkr.co/4VZKhN6imeV1orZDljzm/

Steps to reproduce

  1. Open the test case
  2. Write in the current editor ("# New ruby session: ruby-0123456789-24")
  3. Click the second item in the list (ruby-abcdefghij-24) and write in the editor.
  4. Click the first item in the list (ruby-0123456789-24) and focus the editor.

Expected behavior

It shouldn't raise any error, or handle the undefined somehow (maybe from a list of other clients?).

Actual behavior

It raises an error on the second window/tab:

FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'replace' of undefined

at ACEAdapter.firepad.ACEAdapter.ACEAdapter.setOtherCursor (https://cdn.firebase.com/libs/firepad/1.4.0/firepad.js:2636:47)
    at OtherClient.firepad.EditorClient.OtherClient.updateCursor (https://cdn.firebase.com/libs/firepad/1.4.0/firepad.js:2274:36)
    at cursor (https://cdn.firebase.com/libs/firepad/1.4.0/firepad.js:2325:18)
    at FirebaseAdapter.clazz.trigger (https://cdn.firebase.com/libs/firepad/1.4.0/firepad.js:48:29)
    at childChanged (https://cdn.firebase.com/libs/firepad/1.4.0/firepad.js:1520:12)
    at https://www.gstatic.com/firebasejs/3.3.0/firebase.js:389:375
    at Ub (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:283:165)
    at vc (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:271:215)
    at wc (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:270:1165)
    at sf.h.Hb (https://www.gstatic.com/firebasejs/3.3.0/firebase.js:455:287)

The colors and cursors seem to work normally but the error message worries me. Also, I'm not sure if this way is the best way to work with multiple sessions in an ACE editor (which is my use case).

The same error keeps appearing every time I'm going from the second item on the list (ruby-abcdefghij-24) to the first one (ruby-0123456789-24).

It seems to happen either if I set an userId or not. Also, it may be related to the output Firebase is sending. The last message from Firebase before the error is:

{"t":"d","d":{"r":140,"b":{"s":"ok","d":{}}}}

When I open the test case I see the same error just after loading the page, and the last message from Firebase has the same structure as the above.

From what I found, the error in setOtherCursor relates to the second argument being undefined:

ACEAdapter.prototype.setOtherCursor = function(cursor, color, clientId) {...

Following the stack trace it seems to be a missing color property in the members of editor.session.firepad.client_.clients.

You can test on fresh documents by changing the 24 at the end of the lines 42 and 43.

hpneo avatar Mar 05 '17 04:03 hpneo