Page MenuHomePhabricator

Uncaught TypeError: Cannot read property 'getOffset' of null appears when typing a character in Find field while RegEx option is enabled
Closed, ResolvedPublic

Description

Steps to replicate:

  1. Open VE
  2. Go to Find and Replace
  3. Enable the option for RegEx
  4. Type 'a' in the Find field

The following Error appears in the console

Uncaught TypeError: Cannot read property 'getOffset' of null

Event Timeline

I can't reproduce this, trying locally and on beta.

Ok, it's not that straightforward as I described in my original report. Sorry about that. Try the following steps instead:

  1. Go to Find and Replace.
  2. Enable the option for RegEx.
  3. Search and Replace a character/text. For example, replace 'xy' with z
  4. Save your edit
  5. Reopen the page
  6. Open the Find and Replace panel again
  7. Now at this point you will see the previous input 'xy' being highlighted, so now Type 'a' to replace it

The following error should appear at this point making the dialog crash.

Uncaught TypeError: Cannot read property 'getOffset' of null
   at VeCeDocument.ve.ce.Document.getNodeAndOffset (load.php?debug=false&lang=en&modules=ext.CodeMirror.lib|ext.visualEditor.core&skin=vector&version=1a2ep2x:609)
   at VeCeSurface.ve.ce.Surface.getSelectionState (load.php?debug=false&lang=en&modules=ext.CodeMirror.lib|ext.visualEditor.core&skin=vector&version=1a2ep2x:726)
   at VeCeSurface.ve.ce.Surface.getNativeRange (load.php?debug=false&lang=en&modules=ext.CodeMirror.lib|ext.visualEditor.core&skin=vector&version=1a2ep2x:727)
   at VeCeLinearSelection.ve.ce.LinearSelection.getSelectionRects (load.php?debug=false&lang=en&modules=ext.CodeMirror.lib|ext.visualEditor.core&skin=vector&version=1a2ep2x:737)
   at VeUiFindAndReplaceDialog.ve.ui.FindAndReplaceDialog.renderRangeOfFragments (load.php?debug=false&lang=en&modules=ext.CodeMirror.lib|ext.visualEditor.core&skin=vector&version=1a2ep2x:957)
   at VeUiFindAndReplaceDialog.ve.ui.FindAndReplaceDialog.renderFragments (load.php?debug=false&lang=en&modules=ext.CodeMirror.lib|ext.visualEditor.core&skin=vector&version=1a2ep2x:956)
   at VeUiFindAndReplaceDialog.ve.ui.FindAndReplaceDialog.onFindChange (load.php?debug=false&lang=en&modules=ext.CodeMirror.lib|ext.visualEditor.core&skin=vector&version=1a2ep2x:954)
   at OoUiTextInputWidget.oo.EventEmitter.emit (<anonymous>:9:486)
   at OoUiTextInputWidget.OO.ui.InputWidget.setValue

Screen Shot 2018-06-07 at 2.41.58 PM.png (713×1 px, 195 KB)

Okay, thanks for that! That sequence, and particularly the "xy" still being present, makes me suspect that we're failing to properly tear down the toolbar dialogs, so it's still holding on to a reference to the previous surface, resulting in the failure when we try to perform actions on a discarded surface.

That said, I just tried to reproduce this with the new steps, and it still doesn't produce the error for me.

hmm strange, it's even happening on the first attempt to find and replace now for me. Adding the screen capture, just incase there is something I missed stating.

Vvjjkkii renamed this task from Uncaught TypeError: Cannot read property 'getOffset' of null appears when typing a character in Find field while RegEx option is enabled to ekbaaaaaaa.Jul 1 2018, 1:05 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
CommunityTechBot renamed this task from ekbaaaaaaa to Uncaught TypeError: Cannot read property 'getOffset' of null appears when typing a character in Find field while RegEx option is enabled.Jul 2 2018, 4:29 AM
CommunityTechBot raised the priority of this task from High to Needs Triage.
CommunityTechBot updated the task description. (Show Details)
CommunityTechBot added a subscriber: Aklapper.

I tried to reproduce this in other environments but couldn't. However, this is happening consistently on my sandbox here: https://en.wikipedia.beta.wmflabs.org/wiki/User:RYasmeen_(WMF)?veaction=edit

I am not sure what might be causing that for that page only :(

I can reproduce this. The cause is that we find the letter "a" inside one of the references.

Steps to reproduce:

  • Open https://en.wikipedia.beta.wmflabs.org/w/index.php?title=User:RYasmeen_(WMF)&oldid=382671&veaction=edit
  • Open the find-and-replace dialog
  • Type "a". Note that there are 14 results:
    image.png (600×1 px, 124 KB)
  • Enable regexp search, click next or prev. Note that there are 15 results:
    image.png (600×1 px, 124 KB)
  • The last result is causing the bug. If you add a breakpoint before the exception, you can see it is at offset 538, which is in the middle of the internal list. We can't render a selection at that position, and so we can't render the find-and-replace highlight.

Change 449237 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
[VisualEditor/VisualEditor@master] Do not try searching outside of valid range when using regex

https://gerrit.wikimedia.org/r/449237

This is caused by 3db54b22a01e130e3d1d5e3116744b614b5540ee, where I mistakely assumed the "document range" spans the whole document, while in fact it spans the document excluding the internal list.

Change 449237 merged by jenkins-bot:
[VisualEditor/VisualEditor@master] Do not try searching outside of valid range when using regex

https://gerrit.wikimedia.org/r/449237

@matmarex: is this ready for testing on Beta cluster?

Change 449530 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (086de2707)

https://gerrit.wikimedia.org/r/449530

@Ryasmeen Sorry, forgot to update the submodule in the extension.

Change 449530 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (086de2707)

https://gerrit.wikimedia.org/r/449530

@Ryasmeen Sorry about wasting your time. The patch in extensions/VisualEditor is merged now, and it should have been deployed to Beta. Now actually ready for testing :)

@matmarex: No worries! :) Just tested this. Seems fixed for all cases. Thanks!

Deskana triaged this task as Medium priority.