Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions text/0796-ember-data-deprecate-rsvp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
Stage: Proposed
Start Date: 2022-02-20
Release Date: Unreleased
Release Versions:
ember-source: vX.Y.Z
ember-data: vX.Y.Z
Relevant Team(s): ember-data
RFC PR: https://github.com/emberjs/rfcs/pull/796
---

# Deprecate `RSVP.Promise` for native Promise

## Summary

All methods currently returning an `RSVP.Promise` will return a native Promise. In addition, all documentation will be updated accordingly.

## Motivation

With the removal of IE11 from our build infrastructure and browser requirements, we can now safely remove `RSVP.Promise`. From the [docs](https://github.com/tildeio/rsvp.js/):

> Specifically, it is a tiny implementation of Promises/A+. It works in node and the browser (IE9+, all the popular evergreen ones).

RSVP was Ember's polyfill since an early v1.0.0 version during a time when native Promises didn't exist in any browser. In addition, Promises have been supported since Node 0.12.

By removing `RSVP.Promise` in favor of native Promises, we can drop an unnecessary dependency for both client side and server side fetching of data.

According to [bundlephobia](https://bundlephobia.com/package/rsvp@4.8.5), this would allow us to remove a significant chunk of dependency weight.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


## Detailed design

Two steps will be required to fulfill deprecating `RSVP.Promise`.

First, we will issue a deprecation `DEPRECATE_RSVP_PROMISE` to async callbacks that might be relying on a convenient feature of `RSVP.Promise`. Namely, an `RSVP.Promise` may still be hanging by the time the underlying model instance or store has been destroyed. This will help users surface instances where their test suite or code is dealing with dangling promises. After the removal of this deprecation, this will throw an Error.

- `id: ember-data:rsvp-unresolved-async`

Second, we will also utilize the deprecation to replace all instances of `RSVP.Promise` with native Promises.

The final implementation will look something like:

```js
ajax(options) {
if (DEPRECATE_RSVP_PROMISE) {
return new Promise((resolve, reject) => {
...
});
} else {
return new RSVPPromise((resolve, reject) => {
...
});
}
},
```

## How we teach this

We do not believe this requires any update to the Ember curriculum. API documentation may be needed to remove traces of `RSVP.Promise`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to include the information that goes into the deprecation guide.
You will also need to document the optional feature, especially if you want to flip the availability down the line, right?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been my experience that many feel that RSVP offers two features not available in native Promises: .hash() and test waiters support (await settled() support).

If this is not that case—

  1. Can we add to the "How we teach this" how to support .hash() or offer an alternative using native promises.
  2. Can we add ti the "How do we teach this" an explanation why native promises are test-waiter compatible and that the integration that RSVP offered is no longer needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sukima

  1. whether we return a native promise or an rsvp promise does not change anyone's ability to use hash.
  2. good call out, it's unnecessary because the test waiters aren't waiting on RSVP Promises in this case either, they are waiting on various other things, which ember-data already installs waiters for.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! This RFC is for Ember-data I thought it was for Ember proper gotcha. 👍


See the informal [docs](https://github.com/emberjs/data/blob/fa18fd148e9881a860343eabf0ba15b6f048c3ea/packages/private-build-infra/addon/current-deprecations.ts) on how to configure your compatibility with ember-data deprecations.

## Drawbacks

For users relying on `RSVP.onerror`, they will have to either refactor their code to set the global Promise to RSVP or configure [onunhandledrejection](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunhandledrejection) appropriately.

If users continue to use `rsvp` after it is dropped from ember-data, users can add `rsvp` to their package.json explicitly if they were depending on it transitively.

Lastly, RSVP gives meaningful labels so that the promise can be debugged easily. We may need to take this into account with a native Promise wrapper, especially how it interacts with the Ember Inspector.

## Alternatives

Continue resolving async paths with `RSVP.Promise` will allowing users a convenient override to use native Promises.

## Unresolved questions

- What level of an abstraction should we provide over native Promise. Derived state for `isPending`, `isResolved`, and `isRejected` seem like probable derived state we want to expose to users to avoid significant churn in their codebase.
- Consideration of Ember's continued use of RSVP.
- After scanning the codebase, the non native equivalent methods we use from RSVP is `defer` in test files. This is an implementation detail that doesn't need to be flushed out here.