linkfy_text icon indicating copy to clipboard operation
linkfy_text copied to clipboard

Safari does not supports userTag regexp + performance optimization

Open westito opened this issue 1 year ago • 0 comments

Linkify crashes on Safari <16.4

FormatException: FormatException: Illegal RegExp pattern (SyntaxError: Invalid regular expression: invalid group specifier name)
(?<![\w@])@([\w@]+(?:[.!][\w@]+)*)
  at wrapException (main.dart.1732570002000.js:7632:52)
  at JSSyntaxRegExp_makeNative (main.dart.1732570002000.js:8289:28)
  at RegExp_RegExp (main.dart.1732570002000.js:13491:70)
  at _linkify (main.dart.1732570002000.js:60497:35)
  at build$1 (main.dart.1732570002000.js:255796:36)

Reference: https://caniuse.com/js-regexp-lookbehind

The main problem is Link.fromMatch(match); is not filtered to linkTypes, so linkify interates over ALL regular expressions even it is not added as paramter. That's why I can't simply exclude that to solve this issue, also the whole lib can be much peformant if it is filtered. Moreover, it could be even much performant if regex not checked at least 3-5x times on every build by using start/end indexes + group index from a single allMatches call, inside a StatefulWidget that stores last matches. Instead of splitting + allMatch + check all possible regex one by one on every build.

westito avatar Nov 25 '24 22:11 westito