-
Notifications
You must be signed in to change notification settings - Fork 94
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
Legacy browser support: Issue with subclassing "Promise" #174
Comments
My current workaround: Just replace the variable const neverSettle = new Promise(() => {}, () => {}); The codebase doesn't use |
Hey, thanks for reporting this! It's a pretty big problem so we need to find a proper solution. However, the function NeverSettle() {}
Object.setPrototypeOf(NeverSettle, Promise)
NeverSettle.prototype = Object.assign(Object.create(Promise.prototype), {
finally() {
return this
},
catch() {
return this
},
then() {
return this
},
}) |
This is not the only place where we're extending a builtin class by the way. There's also Another thing to note is that |
I've been trying to reproduce the transpilation failure using the Babel REPL, but haven't succeeded to trigger an error so far. What did you do to get these errors? |
Created a PR here: #175 |
I also cannot reproduce the issue on the Babel REPL. Maybe there's some patch after babel/babel#1120? (it's quite old issue 😅 and I just googled it to look into the situation.) But it is possible on the Typescript Playground.
Actually, subclassing "Error" doesn't make any problem in my experience so far. (and maybe that is "runtime error" rather than "transpile error"? 😅 ) But just in case, I leave a reference here: |
Can you verify that the PR I opened works? CodeSandbox automatically packs a release candidate: #175 (comment) See https://ci.codesandbox.io/status/async-library/react-async/pr/175/builds/333 |
@ghengeveld I tested your PR in my codebase and now it works (without any runtime error) well :) |
Awesome. I'll ship it early next week, as I'm out for the weekend. |
Related to #51.
react-async
is hard to use in legacy ES5 browsers due to the implementation ofNeverSettle
class. The problem is subclassing nativePromise
is not supported in well-known transpilers, and to achieve this we have to polyfillReflect
and use custom transpilers.References:
Let me show an example:
source:
react-async/packages/react-async/src/reducer.js
Lines 3 to 22 in ac09f5f
transpiled (ES5)
So I wish we can change the
NeverSettle
implementation rather than force us to set it up that complex setup. For example:The text was updated successfully, but these errors were encountered: