Skip to content
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

Hangs when loading module in IE11 - with core-js 3.6.0 or newer, with and without babel sticky-regex polyfill #300

Closed
perbergland opened this issue Sep 10, 2020 · 10 comments

Comments

@perbergland
Copy link

v 4.3.0

With core-js 3.6.0 (and newer up to 3.6.5), when loading the module, the call to const parts = XRegExp.union hangs and never returns. core-js 3.6.0 introduced new compatibility stuff for sticky so maybe that’s the core problem?

const parts = XRegExp.union([/\({{([\w$]+)}}\)|{{([\w$]+)}}/, subParts], 'g', {

@perbergland
Copy link
Author

I reproduced the error in IE11 also with an empty next.js project with and without regex sticky polyfills by just adding import xregexp from "xregexp" to index.js.

To disable the default polyfill, I used this .babelrc

{
  "presets": [
    [
      "next/babel",
      {
        "preset-env": {
          "exclude": ["@babel/plugin-transform-sticky-regex"]
        }
      }
    ]
  ]
}

This is the loop that never exits because token is an empty string:

Screenshot 2020-09-10 kl  11 30 39

@perbergland perbergland changed the title Hangs when loading module in IE11 with core-js 3.6.0 or newer Hangs when loading module in IE11 - with core-js 3.6.0 or newer, with and without babel sticky-regex polyfill Sep 10, 2020
@perbergland
Copy link
Author

@perbergland
Copy link
Author

@slevithan is this something you could take a look at? I don’t quite grasp the purpose of the code that hangs

@perbergland
Copy link
Author

@josephfrazier any chance you could take a peek?

@slevithan
Copy link
Owner

slevithan commented Sep 21, 2020

@perbergland The line of code you highlighted is just concatenating two different regexes together, and separating them with an “or” (|) operator. The resulting regex is assigned the name parts. The concatenation, in this case, is merely done so that the subParts half of the regex can be reused independently elsewhere in the XRegExp.build file/addon.

Some potential fixes and workarounds:

  • If you're up for it: Identify and fix/address the issue within XRegExp.union, starting by finding a reduced error case. The regexes fed to union in the line you’ve pointed out are probably needlessly complex for triggering whatever the issue is in IE 11 with core-js 3.6.0+.
  • Use XRegExp without the XRegExp.build addon.
  • Update the XRegExp.build addon to not use XRegExp.union there:
const subParts = /(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*\]/g;
const parts = /\({{([\w$]+)}}\)|{{([\w$]+)}}|(\()(?!\?)|\\([1-9]\d*)|\\[\s\S]|\[(?:[^\\\]]|\\[\s\S])*\]/g;

@perbergland
Copy link
Author

Not sure I understand what you mean, but I ended up removing the dependency on xregexp from my app to fix the IE incompatibility. Feel free to close the issue, I don't care anymore.

@NathanAB
Copy link

@perbergland just wanna let you know this issue is totally ruining my day right now. You're not alone 😅

IE11 hangs and is completely broken just by including this library as stated.

@slevithan
Copy link
Owner

I've starting looking into this. Thanks for the repro repo @perbergland. So far I've learned the issue in IE11 is not being triggered by the identified line per se. It is any invocation of the XRegExp constructor with core-js 3.6.0+. E.g. XRegExp('testregex') will trigger the same infinite loop.

@slevithan
Copy link
Owner

I've added a fix for this in bece2eb

core-js 3.6.0 introduced new compatibility stuff for sticky so maybe that’s the core problem?

That was indeed the problem. The core-js 3.6.0 sticky polyfill appears to be partially broken or incomplete. I've added a check for incorrect handling of sticky, and made XRegExp treat the y (sticky) flag as unsupported in that case.

@slevithan
Copy link
Owner

Fix published in v4.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants