From e5313dda981348f184f15c315f683686536c8199 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 20 Feb 2022 09:49:15 -0600 Subject: [PATCH] RFC: ember data deprecate RSVP.Promise for native Promises --- text/0796-ember-data-deprecate-rsvp.md | 75 ++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 text/0796-ember-data-deprecate-rsvp.md diff --git a/text/0796-ember-data-deprecate-rsvp.md b/text/0796-ember-data-deprecate-rsvp.md new file mode 100644 index 0000000000..04c7a62752 --- /dev/null +++ b/text/0796-ember-data-deprecate-rsvp.md @@ -0,0 +1,75 @@ +--- +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 existed 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. + +## Detailed design + +Two steps will be required to fulfill deprecating `RSVP.Promise`. + +First, we will issue a deprecation 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-promise-hanging` + +Second, we will introduce a feature flag replacing all instances of `RSVP.Promise` with native Promises. + +The implementation follows the standard feature-flagging process in Ember and Ember Data. The final implementation will look something like: + +```js + ajax(options) { + if (DS__NATIVE_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`. + +## 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 continuing to use `rsvp`, users can add `rsvp` to their package.json. + +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 + +- 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. \ No newline at end of file