-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixing EuiCodeBlock regex for Safari regex support. #6603
Fixing EuiCodeBlock regex for Safari regex support. #6603
Conversation
* Updated EuiCodeBlock regex to support Safari using negative lookahead. * Changed regex comment to explain negative lookahead.
Preview documentation changes for this PR: https://eui.elastic.co/pr_6603/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this negative lookahead is not robust enough to catch the underlying issue of all import
statements within template literals. It will not catch the following snippets:
const string = `import foo from 'bar';
const foo = bar;`
this will also not be caught:
const string = `/* this is js */
import foo from 'bar';
const bar = baz;`
Apologies on my end for not remembering Safari doesn't support negative lookbehinds (thanks for nothing, Apple) - we'll likely need to take a different approach to solving this problem (not catching strings within template literals) a different way than purely regex-based.
This reverts commit 2ea2964.
… case - this prevents us from incorrectly catching usages just becase a backtick is on the same line as an import string, which it may not always be
…arse template literals
- we mostly want to trim just line breaks caused by the removed imports - spaces shouldn't really be happening
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@breehall do you mind reviewing this PR so I'm not self-approving/merging my own code?
Going to add a changelog to this PR, since I intend on doing a patch release with this fix after this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_6603/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for me. I tested by opening the PR preview link in Safari. The page loads with no trouble. Confirmed that the CodeSandbox demos containing imports loaded as expected without errors.
Summary
Yesterday I merged #6595 to update
EuiCodeBlock
regex to ignore template literal comments. This change caused a bug in Safari because it used the currently unsupported negative lookbehind. I've updated the regex to use negative lookahead and keyed off the end of the template literal string instead of the beginning.Retested with Chrome, Safari, Edge, and Firefox locally as well as opened CodeSandbox from playground links in each browser. Expanded unit test for this case.
Changeset
Screenshot from Safari
QA
Remove or strikethrough items that do not apply to your PR.
General checklist