lexical
lexical copied to clipboard
Bug: AutoLinkPlugin's negative lookbehind breaks in older browsers
Lexical version: 0.17.1 (latest)
Steps To Reproduce
- Use Safari v15
- Visit a site that uses Lexical with AutoLinkPlugin, e.g., https://playground.lexical.dev/
- Observe that the site fails to load due to an exception
SyntaxError: Invalid regular expression: invalid group specifier name
Removing the negative lookbehind here appears to fix the issue, but causes a regression for #6146: https://github.com/facebook/lexical/blob/0683d58243a226b066d5231d9a0040185bd08398/packages/lexical-playground/src/plugins/AutoLinkPlugin/index.tsx#L15-L16
A more graceful fix might be something like:
let URL_REGEX: RegExp;
try {
URL_REGEX =
/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)(?<![-.+():%])/;
} catch (e) {
console.info('Failed to define URL_REGEX - falling back to basic version without negative lookbehind', e);
URL_REGEX =
/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
}
Link to code example: https://playground.lexical.dev/
The current behavior
Lexical crashes
The expected behavior
Lexical works :)
Impact of fix
This breaks Lexical on affected browsers. caniuse indicates that Safari <16.4 (March 2023) is affected in particular.