flutter-code-editor
flutter-code-editor copied to clipboard
Reusing a RegExp causes a JavaScript error
Steps to reproduce:
- Start the example app.
- Click to the bottom empty line.
- Press Enter.
- Click to
readOnlyMethodmethod name. - Press Enter.
Expected: Nothing happens. Acutal: Cursor is moved to the bottom, an empty line is added there.
Reproducible in:
- Web, Flutter 3.3, with the message in the console (see below).
- Web, Flutter 3.0, no messages in console.
Not reproducible in Linux Desktop.
https://user-images.githubusercontent.com/44893228/188877648-ff9a231e-a9ce-4fbe-afb9-6743eab72316.mp4
Found in commit: 72caacd2975e80e0c3e3f477b6d82c7b0ef271ce 72caacd2975e80e0c3e3f477b6d82c7b0ef271ce
Error in the IDE debug output
======== Exception caught by services library ======================================================
The following JSNoSuchMethodError was thrown during method call TextInputClient.updateEditingState:
TypeError: Cannot read properties of null (reading 'Symbol(dartx.length)')
When the exception was thrown, this was the stack:
dart:sdk_internal 29437:17 regExpCaptureCount
dart:sdk_internal 18584:70 split]
packages/flutter_code_editor/src/autocomplete/autocompleter.dart.lib.js 138:32 [_updateText]
packages/flutter_code_editor/src/autocomplete/autocompleter.dart.lib.js 123:24 setText
packages/flutter_code_editor/src/code_field/code_controller.dart.lib.js 464:28 set value
packages/flutter/src/widgets/title.dart.lib.js 41746:36 set [_value]
packages/flutter/src/widgets/title.dart.lib.js 42015:24 [_formatAndSetValue]
packages/flutter/src/widgets/title.dart.lib.js 41557:35 updateEditingValue
packages/flutter/src/services/text_editing_delta.dart.lib.js 3243:66 _handleTextInputInvocation
dart:sdk_internal 40595:34 runBody
dart:sdk_internal 40626:7 _async
packages/flutter/src/services/text_editing_delta.dart.lib.js 3167:20 [_handleTextInputInvocation]
packages/flutter/src/services/text_editing_delta.dart.lib.js 3154:56 _loudlyHandleTextInputInvocation
dart:sdk_internal 40595:34 runBody
dart:sdk_internal 40626:7 _async
packages/flutter/src/services/text_editing_delta.dart.lib.js 3152:20 [_loudlyHandleTextInputInvocation]
packages/flutter/src/services/text_editing_delta.dart.lib.js 4436:57 _handleAsMethodCall
dart:sdk_internal 40595:34 runBody
dart:sdk_internal 40626:7 _async
packages/flutter/src/services/text_editing_delta.dart.lib.js 4433:20 [_handleAsMethodCall]
packages/flutter/src/services/text_editing_delta.dart.lib.js 4430:126 <fn>
packages/flutter/src/services/text_editing_delta.dart.lib.js 9104:31 <fn>
dart:sdk_internal 40595:34 runBody
dart:sdk_internal 40626:7 _async
packages/flutter/src/services/text_editing_delta.dart.lib.js 9101:82 <fn>
dart:sdk_internal 196990:7 invoke2
dart:sdk_internal 133154:15 invoke
dart:sdk_internal 133225:54 push
dart:sdk_internal 133316:19 push
dart:sdk_internal 172366:27 invokeOnPlatformMessage
dart:sdk_internal 187512:49 updateEditingState
dart:sdk_internal 187594:26 <fn>
dart:sdk_internal 179063:38 handleChange
dart:sdk_internal 5438:16 _checkAndCall
dart:sdk_internal 5443:17 dcall
dart:sdk_internal 62137:21 ret
call: MethodCall(TextInputClient.updateEditingState, [1, {text: class MyClass {
void readOnlyMethod() {
}
void method() {
}
}
, selectionBase: 74, selectionExtent: 74, composingBase: null, composingExtent: null}])
====================================================================================================
No errors in browser console.
autocompleter.dart, Failing _updateText
void _updateText(AutoComplete ac, String text) {
ac.clearEntries();
ac.enterList(
text
.split(RegExps.wordSplit)
.where((t) => t.isNotEmpty)
.toList(growable: false),
);
}
autocompleter.dart, Working _updateText
void _updateText(AutoComplete ac, String text) {
ac.clearEntries();
ac.enterList(
text
.split(RegExp(RegExps.wordSplit.pattern))
.where((t) => t.isNotEmpty)
.toList(growable: false),
);
}
flutter doctor -v
[✓] Flutter (Channel stable, 3.3.0, on Ubuntu 20.04.4 LTS 5.14.0-1051-oem, locale en_US.UTF-8)
• Flutter version 3.3.0 on channel stable at /home/alexey/snap/flutter/common/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ffccd96b62 (9 days ago), 2022-08-29 17:28:57 -0700
• Engine revision 5e9e0e0aa8
• Dart version 2.18.0
• DevTools version 2.15.0
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /home/alexey/Android/Sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/linux#android-setup for more details.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
• cmake version 3.10.2
• ninja version 1.8.2
• pkg-config version 0.29.1
[✓] Android Studio (version 2021.2)
• Android Studio at /home/alexey/bin/android-studio
• Flutter plugin version 68.1.2
• Dart plugin version 212.5744
• Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.70.2)
• VS Code at /usr/share/code
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (2 available)
• Linux (desktop) • linux • linux-x64 • Ubuntu 20.04.4 LTS 5.14.0-1051-oem
• Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.101
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
Must be an internal bug of Dart. If we have time, we should make a minimal reproducible example and file the bug.
For now applying the workaround from 'Working _updateText' above. Leaving this bug open.
The reasons to leave this open:
- When reusing the
RegExp, this will work faster. - Every developer will stumble on this workaround in the code and have a desire for it to not be there.
- We can help the Dart team to identify the bug.