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

IE11 + core-js@3.6.4 String.prototype.split doesn't work with regexp #751

Closed
kmsheng opened this issue Jan 15, 2020 · 21 comments
Closed

IE11 + core-js@3.6.4 String.prototype.split doesn't work with regexp #751

kmsheng opened this issue Jan 15, 2020 · 21 comments

Comments

@kmsheng
Copy link

kmsheng commented Jan 15, 2020

Screen Shot 2020-01-15 at 9 40 26 PM

repo to reproduce
https://github.com/kmsheng/core-js-bug

Note that core-js was imported twice,
one in src/js/index.js and the other one in assets/js/default.js

simlar issue
#741

@jaynetics
Copy link

i encountered the same bug, and can confirm that importing core-js into two js files is the root cause. importing it in only one file fixes the problem.

@11101101
Copy link

I'm also running into the same issue. My code path results in a second import which causes the bug to manifest.

@pierremanceaux
Copy link

In case this helps someone: JakeChampion/fetch#748
It would be great to identify which version of IE11 is/are affected, but it seems pretty recent to me, probably the last build.

@aliaksandr-yermalayeu
Copy link

Hi everyone. I am facing the same issue. It is still reproduced in IE11 with the latest version of core-js. However the scenario is pretty tricky to reproduce. So I created a minimal repo with needed steps. Hope it helps.

@sargismarkosyan
Copy link

Hi, the issue is reproducible with other regexp too for example '/test/'.split(/\W/) is returning ["/", "t", "e", "s", "t", "/"] but should return ["", "test", ""].

@slowcheetah
Copy link
Contributor

Please show your npm list | grep core-js

@aliaksandr-yermalayeu
Copy link

@slowcheetah, will result of yarn list --pattern core-js work for you?

├─ core-js-compat@3.6.4
└─ core-js@3.6.4

@aliaksandr-yermalayeu
Copy link

I took a deeper dive into this issue. The problem is caused by this line. It turns out regexp.exec and regexpExec are different references when polyfill is loaded twice.

@steveworkman
Copy link

Is there an older version of core-js that does not show this issue? It looks like there were changes related to adding more regexp.exec requires in 3.6.2
Would a downgrade to 3.6.1 work?

@jdreesen
Copy link
Contributor

I downgraded to 3.5.0 yesterday and it works for me.

@aliaksandr-yermalayeu
Copy link

The bug was introduced by version 3.6.0 due to support of y flag. In version 3.5.0 exec was never patched in IE.

@toxik
Copy link

toxik commented May 4, 2020

is reverting the sticky flag support considered?

@slowcheetah
Copy link
Contributor

@toxik Not yet. But I think about it, because I can’t make it work correctly and break nothing

@toxik
Copy link

toxik commented May 21, 2020

@slowcheetah have you got any news regarding a revert/fix ? thanks

nutgaard added a commit to navikt/modiapersonoversikt that referenced this issue Jun 9, 2020
Gjøres pga følgende issues;
JakeChampion/fetch#750
JakeChampion/fetch#748
zloirock/core-js#751
zloirock/core-js#741

I bunn og grunn, core-js@^3.6.0 introduserte støtte for
String.prototype.split med regex som har sticky-flag. Pga bug her så
fungerer ikke funksjonen som forventet noe mer i eldre IE11 versjoner.

E.g `"test".split(/e/) === ['t', 'e', 's', 't']`, denne burde gitt
`['t', 'st']`
jebrosen added a commit to Dfam-consortium/Dfam-Portal that referenced this issue Nov 6, 2020
Suspected cause is <zloirock/core-js#751>, via
<d3/d3-zoom#200>, which is used in SODA.
@toxik
Copy link

toxik commented Nov 19, 2020

you can upgrade XRegExp to v4.4.0 instead – slevithan/xregexp#300

@scrollbar-ww
Copy link

same problem with 3.8.0.
I put a .replace() before call String.split() as a short term fix :
str.replace(someRegexp/g, ' \n').split('\n')

@Jokero
Copy link

Jokero commented Mar 9, 2021

@zloirock @slowcheetah Are there any plans to revert sticky flag?

@zloirock
Copy link
Owner

@Jokero sticky flag will not be reverted. Feel free to work on exploring and fixing this issue without it.

@Khartir
Copy link

Khartir commented Mar 19, 2021

I looked into this a bit. As far as I can tell the issue lies in the way regexp-exec (which is required by string.split) provides the patched exec-function. It creates a new patched function, if regexp-sticky-helpers.UNSUPPORTED_Y is true.

In order for UNSUPPORTED_Y not to be true the regexp.constructor and regexp.sticky polyfills are required.

However, these are not included with regexp-exec, so unless they are explicitly included regexp-exec provides a new patch-function if called in separate files.

So I think the solution would be for regexp-exec not to use UNSUPPORTED_Y to check for support but instead to ensure sticky-support exists requiring regexp.constructor and regexp.sticky.

@zloirock Do you agree? I can try to provide a PR for this, but I am unsure how to do this correctly. Should I use a simple require or is there another way for one polyfill to ensure the presence of another polyfill?

I assume a similar issue could exist with regexp.flags but I have not tested this.

@zloirock
Copy link
Owner

@Khartir sounds reasonable, you could try to add a PR. I don't think that it could affect .flags - it's an unrelated case.

@zloirock zloirock added the bug label Apr 7, 2021
nutgaard added a commit to navikt/modiapersonoversikt that referenced this issue Apr 8, 2021
Var tidligere nødvendig for å låse core-js til 3.5.0 versjonen, siden alle nyere versjoner hadde en regex-bug.
Dette skal nå være fikset i siste versjon, og dette var kun ett problem i eldre versjoner av IE11 som ikke er mye brukt noe mer.
Tenker det derfor er innafor å teste ut om vi kan rydde opp litt i avhengighetene våre.

For bedre dokumentasjon om vi skal reverte denne, så inkluderer jeg den originale commit-meldingen som introduserte overskrivingen;

```
Gjøres pga følgende issues;
JakeChampion/fetch#750
JakeChampion/fetch#748
zloirock/core-js#751
zloirock/core-js#741

I bunn og grunn, core-js@^3.6.0 introduserte støtte for
String.prototype.split med regex som har sticky-flag. Pga bug her så
fungerer ikke funksjonen som forventet noe mer i eldre IE11 versjoner.

E.g `"test".split(/e/) === ['t', 'e', 's', 't']`, denne burde gitt
`['t', 'st']`
```
@marcospont
Copy link

My team just experienced this issue because we were running core-js 3.9.1 in our code.
Because of the above mentioned issue, one other library we are using to polyfill CSS variables (css-vars-ponyfill) was producing severe performance issues. The execution time of variables polyfilling was more than 200 seconds when it should be around 5. :)

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

Successfully merging a pull request may close this issue.