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

Promise.allSettled and Promise.any is undefined #766

Closed
1 task done
retyui opened this issue Jun 28, 2022 · 18 comments
Closed
1 task done

Promise.allSettled and Promise.any is undefined #766

retyui opened this issue Jun 28, 2022 · 18 comments
Labels
bug Something isn't working

Comments

@retyui
Copy link
Contributor

retyui commented Jun 28, 2022

That super weird that a fresh method from ES2022 Object.hasOwn was implemented, but methods of perv. ecmascript spec not implemented yet:

  • Promise.allSettled(...) // ES2020
  • Promise.any(...) // ES2021

Bug Description

  • I have run gradle clean and confirmed this bug does not occur with JSC

Hermes version: 0.11.0
React Native version (if any): 0.69.0
OS version (if any): Android 11
Platform: arm64-v8a, armeabi-v7a, x86, x86_64

Steps To Reproduce

const object1 = {prop: 'exists'};

console.log(Object.hasOwn(object1, 'prop')); // true
console.log(Object.hasOwn(object1, 'toString')); // false

Promise.allSettled([]); // TypeError: undefined is not a function, js engine: hermes
Promise.any([]);        // TypeError: undefined is not a function, js engine: hermes

The Expected Behavior

// `Promise.allSettled, Promise.any` works without any exceptions
@retyui retyui added the bug Something isn't working label Jun 28, 2022
@SMKH-PRO
Copy link

SMKH-PRO commented Jul 9, 2022

Promise.allSettled is undefined in React-Native 0.68.2 with hermes enabled.

Any solution to this?

@retyui
Copy link
Contributor Author

retyui commented Jul 12, 2022

you need to install and apply custom polyfill for that methods

@ljharb
Copy link

ljharb commented Jul 13, 2022

@retyui
Copy link
Contributor Author

retyui commented Jul 13, 2022

@SMKH-PRO also be careful with these polyfills

As their size too big( 48.9kB is 7 React's (6.4kB)!!!

it's better to use something lighter

@ljharb
Copy link

ljharb commented Jul 13, 2022

@retyui theres nothing lighter that’s also correct, and correctness is much more important. Also, you’re using sizes from bundlephobia, which is FUD because in an actual application it won’t be anywhere near that large.

@retyui
Copy link
Contributor Author

retyui commented Jul 13, 2022

theres nothing lighter

actually no, for example 25 lines pollyfill for Promise.allSettled()


Note: React Native use then/promise

https://github.com/facebook/react-native/blob/080a5921e158dee8b2edc93d56232ba0517d831a/Libraries/Promise.js#L13-L23

@ljharb
Copy link

ljharb commented Jul 13, 2022

@retyui and those 25 lines are incorrect, per spec. They also break if delete Promise.all has been ran, which is also incorrect.

This thread isn't the place to debate it, though.

@retyui
Copy link
Contributor Author

retyui commented Oct 25, 2022

@retyui retyui closed this as completed Oct 25, 2022
facebook-github-bot pushed a commit to facebook/metro that referenced this issue Oct 27, 2022
Summary:
`promise` module diff: [`8.2.0...8.3.0`](https://npmfs.com/compare/promise/8.2.0/8.3.0/)
- Hermes issue: facebook/hermes#766

## Changelog

[General] [Added] - Added support `Promise.any`

X-link: facebook/react-native#35080

Reviewed By: cortinico

Differential Revision: D40681373

Pulled By: jacdebug

fbshipit-source-id: ecd589186483f3aa0f48da28a1f6dfcb1e26c8bc
facebook-github-bot pushed a commit to facebook/react-native that referenced this issue Oct 27, 2022
Summary:
`promise` module diff: [`8.2.0...8.3.0`](https://npmfs.com/compare/promise/8.2.0/8.3.0/)
- Hermes issue: facebook/hermes#766

## Changelog

[General] [Added] - Added support `Promise.any`

Pull Request resolved: #35080

Test Plan:
Release notes [`promise@8.3.0`](https://github.com/then/promise/releases/tag/8.3.0)

```tsx
typeof Promise.any // function
```

Reviewed By: cortinico

Differential Revision: D40681373

Pulled By: jacdebug

fbshipit-source-id: ecd589186483f3aa0f48da28a1f6dfcb1e26c8bc
kelset pushed a commit to facebook/react-native that referenced this issue Nov 14, 2022
Summary:
`promise` module diff: [`8.2.0...8.3.0`](https://npmfs.com/compare/promise/8.2.0/8.3.0/)
- Hermes issue: facebook/hermes#766

## Changelog

[General] [Added] - Added support `Promise.any`

Pull Request resolved: #35080

Test Plan:
Release notes [`promise@8.3.0`](https://github.com/then/promise/releases/tag/8.3.0)

```tsx
typeof Promise.any // function
```

Reviewed By: cortinico

Differential Revision: D40681373

Pulled By: jacdebug

fbshipit-source-id: ecd589186483f3aa0f48da28a1f6dfcb1e26c8bc

# Conflicts:
#	package.json
#	yarn.lock
@retyui retyui reopened this Dec 2, 2022
@retyui
Copy link
Contributor Author

retyui commented Dec 2, 2022

Re open issue:

reason: facebook/react-native#35363 (comment)

@fbmal7
Copy link
Contributor

fbmal7 commented Dec 6, 2022

So, a bit of context for how we handle Promise. We actually do use a modified version of a polyfill, based on this implementation. So, Hermes actually has had support for allSettled and any.

  • allSettled was introduced here, Sep 7th.
  • any was introduced here, Oct 27th.

So, this does make sense that they have not made their way into the most recent versions of RN, at least specifically for any. However, allSettled may have had a chance to make it in.. Let me see if I can find the cut dates for the recent releases.

@fbmal7
Copy link
Contributor

fbmal7 commented Dec 6, 2022

@retyui So to follow up, this behavior you are experiencing is expected for the version you are using. RN 0.70 was first cut on Jul 15th. RN 0.71 is not fully released yet, but the first release candidate was cut on Nov 3rd.

Therefore, you can expect Promise.allSettled and Promise.any for RN 0.71+, and not in any version below. At least, this is purely from the Hermes' side of things. I'm not sure if there are any additional polyfills that RN includes when Hermes is present that could add support for these methods in other versions, but that would be question for RN.

@retyui
Copy link
Contributor Author

retyui commented Dec 7, 2022

got it, should be fixed in react-native@0.71.x

@n-kulic
Copy link

n-kulic commented Jan 8, 2023

got it, should be fixed in react-native@0.71.x

I have tested with "react-native": "0.70.6" (hermes enabled) on Android physical device (Samsung Galaxy s9) and it appears that allSettled is still undefined as I'm getting that error

Promise.allSettled([])
-[TypeError: undefined is not a function]

@neildhar
Copy link
Contributor

neildhar commented Jan 9, 2023

@n-kulic as mentioned above, this feature is available in RN versions 0.71 and newer. Version 0.70.6 is older than the minimum version that supports this feature.

OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this issue May 22, 2023
Summary:
`promise` module diff: [`8.2.0...8.3.0`](https://npmfs.com/compare/promise/8.2.0/8.3.0/)
- Hermes issue: facebook/hermes#766

## Changelog

[General] [Added] - Added support `Promise.any`

Pull Request resolved: facebook#35080

Test Plan:
Release notes [`promise@8.3.0`](https://github.com/then/promise/releases/tag/8.3.0)

```tsx
typeof Promise.any // function
```

Reviewed By: cortinico

Differential Revision: D40681373

Pulled By: jacdebug

fbshipit-source-id: ecd589186483f3aa0f48da28a1f6dfcb1e26c8bc
@leeyyl
Copy link

leeyyl commented Aug 16, 2023

@neildhar No it's wrong because I use RN 0.71.7 and I got the same issue as @n-kulic said.

@tmikov
Copy link
Contributor

tmikov commented Aug 16, 2023

@leeyyl as you can see here

core.allSettled = function (iterable) {
it is present in Hermes. According to the Git blame it was added here e8fa813 on Sep 7th 2022.

@leeyyl
Copy link

leeyyl commented Aug 17, 2023

@leeyyl as you can see here

core.allSettled = function (iterable) {

it is present in Hermes. According to the Git blame it was added here e8fa813 on Sep 7th 2022.

@tmikov So how to use the core.allSettled in Hermes? Because now I call Promise.allSettled still receive

-[TypeError: undefined is not a function]

@tmikov
Copy link
Contributor

tmikov commented Aug 17, 2023

@leeyyl As I explained, Promise.allSettled has been available in Hermes since September 2022. Download any version of Hermes, compile and run the CLI and see for yourself.

Which version of Hermes is packaged with each RN release is an orthogonal question. You might be using a version of RN without it, or there might be a polyfill that is overwriting Promise, or something else could be wrong in your setup.

We are unable to investigate problems that are outside of Hermes, so consider filing an issue with React Native. They might know what is going on, might be able to pick this change in one of their point releases, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants