regenerator: Detection for accidentalStrictMode results in failures on some platforms
Some Javascript runtime like Wechat MiniProgram and Alipay MiniProgram forbids dynamically defining function (related documents), where both Function
and eval
are undefined
.
Recently added detection for accidentalStrictMode
used Function
as a rescue, which results in failures.
Is there better way to detect accidentalStrictMode
or just bypass it?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 19
- Comments: 17
Commits related to this issue
- fix: reset Function for weapp runtime workaround for https://github.com/facebook/regenerator/issues/378 https://leanticket.cn/tickets/22764 — committed to leancloud/js-realtime-sdk by leeyeh 4 years ago
- Prevent Babel from running its regenerator transform, avoiding the known [regenerator unsafe-eval issue](https://github.com/facebook/regenerator/issues/378). As far as I could tell our code is not rel... — committed to daily-co/daily-js by kompfner 2 years ago
- In daily-react-hooks, prevent Babel from running its regenerator transform, avoiding the known [regenerator unsafe-eval issue](https://github.com/facebook/regenerator/issues/378). As far as I could te... — committed to daily-co/daily-react by kompfner 2 years ago
- Fix https://github.com/facebook/regenerator/issues/378 — committed to marvinruder/rating-tracker by marvinruder a year ago
- Fix https://github.com/facebook/regenerator/issues/378 — committed to marvinruder/rating-tracker by marvinruder a year ago
- Fix https://github.com/facebook/regenerator/issues/378 (#164) — committed to marvinruder/rating-tracker by marvinruder a year ago
For anyone who struggled with this problem: Run this code before
regenerator-runtime
executesI recently became aware of a very clever
globalThis
polyfill that works in all JS implementations, without ever resorting to using theFunction
constructor: https://mathiasbynens.be/notes/globalthis (by @mathiasbynens).Here’s another project where I implemented this polyfill, and it’s worked perfectly so far: https://github.com/apollographql/invariant-packages/pull/53
For historical reasons, I’ve tried to keep
regenerator-runtime/runtime.js
runnable as a single script (rather than a CommonJS or ESM module), so I think we would need to inline the https://www.npmjs.com/package/@ungap/global-this implementation, rather than importing it, but it’s very short.Any objections to moving forward with that approach?
I’m having this problem also. I’m working on a healthcare app and allowing unsafe-eval in the CSP is not an option. I can disable strict mode in the rollup options of my library but this seems like a bad workaround. I feel like strict mode should be able to work, and we shouldn’t have to give up the performance optimizations and error detection benefits.
I think this needs to be revisited. I’m also using toolchains such as
create-react-app
andtsdx
and seeing failures. Both projects are closing issues related to this because they argue it’s the problem ofregenerator-runtime
. Unfortunately our project will fail compliance without a strict CSP, and I’m not sure how to disable strict mode fromcreate-react-app
. And as Mozilla noted in regards to this issue, disabling strict mode isn’t something anyone is keen to do.I thought I could resolve the issue by using a
yarn
resolution
to force an older version that doesn’t exhibit this issue, but unfortunately that doesn’t work either because multiple other libraries we depend on come pre-bundled with a later version ofregenerator-runtime
. Seems like the only way we will be able to get CSP working is if an update resolves the issue, and libraries start taking in the update. 😕I am having this same problem; using strict CSP with no
unsafe-eval
, i end up in thecatch
block for some reason. I am not entirely clear what is causing me to be in “accidentalStrictMode”. Am using the react toolchain based on create-react-app. Am attempting to downgrade this for the time being…