From 601529667743d39d4657399a5248057df5d0a019 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 14 Nov 2021 07:29:43 -0600 Subject: [PATCH 01/11] Deprecate implicit record loading in Ember Route --- text/0774-implicit-record-route-loading.md | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 text/0774-implicit-record-route-loading.md diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md new file mode 100644 index 0000000000..b5e8ef9d15 --- /dev/null +++ b/text/0774-implicit-record-route-loading.md @@ -0,0 +1,85 @@ +--- +Stage: Initial +Start Date: 2021-11-14 +Release Date: Unreleased +Release Versions: + ember-source: vX.Y.Z + ember-data: vX.Y.Z +Relevant Team(s): Ember.js +RFC PR: https://github.com/emberjs/rfcs/pull/774 +--- + +# Deprecate Implicit Record Loading in Routes + +## Summary + +This RFC seeks to deprecate and remove the default record loading behaviour on Ember's Route. By consequence, this will also deprecate and remove the default store on every Route. This behaviour is likely something you either know you have or do not know but it may be occuring in your app. + +```js +export default class PostRoute extends Route { + beforeModel() { + // do stuff + } + + afterModel() { + // do stuff + } +} +``` + +In this example, the `model` hook is not defined. However, Ember will attempt to try a few things before rendering this route's template. + +1. If there is a `store` property on your route, it will attempt to call it's `find` method. Assuming you have `ember-data` installed, you may be expecting this. The arguments will be extracted from the params. + a. For example, if a dynamic segment is `:post_id`, there exists logic to split on the underscore and and find a record of type `post`. + +2. As a fallback, it will attempt to defined a `find` method and use your `Model` instance's find method to fetch. If no `find` method exists, an assertion is thrown. + +## Motivation + +If a user does not define a `model` hook, a side effect of going to the network has long confused developers. Users have come to associate `Route.model()` with a hook that returns `ember-data` models in the absense of explicit injection. While this can be true, it is not wholly true. New patterns of data loading are becoming accepted in the community including opting to fetch data in a Component or using different libraries. + +By removing this behaviour, we will encourage developers to explicitly define what data is being fetched and from where. + +## Detailed design + +We will issue a deprecation to `findModel` notifying the user that if they want to continue this behaviour of attempting to fetch a resource implicitly, they should try and replicate with their own explicitly defined `model` hook. This will not remove returning the `transition` context when no `model` hook is defined. + +## How we teach this + +Most of this behaviour is lightly documented. Developers often come to this by mistake after some difficult searching. First, we will have to remove this sentence from the [docs](https://guides.emberjs.com/release/routing/defining-your-routes/#toc_dynamic-segments). + +> The first reason is that Routes know how to fetch the right model by default, if you follow the convention. + +A direct one to one replacement might look like this. + +```js +import { inject as service } from '@ember/service'; + +export default class PostRoute extends Route { + // assuming you have ember-data installed + @service store; + + beforeModel() { + // do stuff + } + + model({ post_id }) { + return this.store.find('post', post_id); + } + + afterModel() { + // do stuff + } +} +``` + +## Alternatives + +- Continue to provide fallback fetching behaviour but ensure no `assert` is called for users that neither a store nor a `Model` with a `find` method. + +## Open Questions + +## Related links and RFCs +- [Deprecate defaultStore located at `Route.store`](https://github.com/emberjs/rfcs/issues/377) +- [Pre-RFC: Deprecate implicit injections (owner.inject)](https://github.com/emberjs/rfcs/issues/508) +- [Deprecate implicit record loading in routes](https://github.com/emberjs/rfcs/issues/557) From 7493a7d7c0078de222e4810dec0fa920361d5bf8 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 14 Nov 2021 08:42:00 -0600 Subject: [PATCH 02/11] Update text/0774-implicit-record-route-loading.md Co-authored-by: Bert De Block --- text/0774-implicit-record-route-loading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index b5e8ef9d15..22cfbd253d 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -30,7 +30,7 @@ export default class PostRoute extends Route { In this example, the `model` hook is not defined. However, Ember will attempt to try a few things before rendering this route's template. 1. If there is a `store` property on your route, it will attempt to call it's `find` method. Assuming you have `ember-data` installed, you may be expecting this. The arguments will be extracted from the params. - a. For example, if a dynamic segment is `:post_id`, there exists logic to split on the underscore and and find a record of type `post`. + a. For example, if a dynamic segment is `:post_id`, there exists logic to split on the underscore and find a record of type `post`. 2. As a fallback, it will attempt to defined a `find` method and use your `Model` instance's find method to fetch. If no `find` method exists, an assertion is thrown. From 80facdd46bc9becf2a4511e2ccf67346fd09305d Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 14 Nov 2021 08:42:11 -0600 Subject: [PATCH 03/11] Update text/0774-implicit-record-route-loading.md Co-authored-by: Bert De Block --- text/0774-implicit-record-route-loading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index 22cfbd253d..30d8fd5aed 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -75,7 +75,7 @@ export default class PostRoute extends Route { ## Alternatives -- Continue to provide fallback fetching behaviour but ensure no `assert` is called for users that neither a store nor a `Model` with a `find` method. +- Continue to provide fallback fetching behaviour but ensure no `assert` is called for users that have neither a store nor a `Model` with a `find` method. ## Open Questions From 0c16882023ab440b5c550ce846a930b1e8e73a57 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 14 Nov 2021 08:42:16 -0600 Subject: [PATCH 04/11] Update text/0774-implicit-record-route-loading.md Co-authored-by: Bert De Block --- text/0774-implicit-record-route-loading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index 30d8fd5aed..20db1fcbda 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -32,7 +32,7 @@ In this example, the `model` hook is not defined. However, Ember will attempt t 1. If there is a `store` property on your route, it will attempt to call it's `find` method. Assuming you have `ember-data` installed, you may be expecting this. The arguments will be extracted from the params. a. For example, if a dynamic segment is `:post_id`, there exists logic to split on the underscore and find a record of type `post`. -2. As a fallback, it will attempt to defined a `find` method and use your `Model` instance's find method to fetch. If no `find` method exists, an assertion is thrown. +2. As a fallback, it will attempt to define a `find` method and use your `Model` instance's find method to fetch. If no `find` method exists, an assertion is thrown. ## Motivation From 953677859ad69e4d644459ada704276736cbcfa0 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 14 Nov 2021 08:42:22 -0600 Subject: [PATCH 05/11] Update text/0774-implicit-record-route-loading.md Co-authored-by: Bert De Block --- text/0774-implicit-record-route-loading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index 20db1fcbda..c1d4678861 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -1,5 +1,5 @@ --- -Stage: Initial +Stage: Accepted Start Date: 2021-11-14 Release Date: Unreleased Release Versions: From 537653e7b568043a58eb210d21cf745faf11ad73 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 14 Nov 2021 08:43:07 -0600 Subject: [PATCH 06/11] findRecrod instead of find --- text/0774-implicit-record-route-loading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index c1d4678861..9a9a695fd6 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -64,7 +64,7 @@ export default class PostRoute extends Route { } model({ post_id }) { - return this.store.find('post', post_id); + return this.store.findRecord('post', post_id); } afterModel() { From 4419a8fb27a0b1f32e7c755bcde786831eb11e9a Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 14 Nov 2021 09:00:11 -0600 Subject: [PATCH 07/11] clarify removal --- text/0774-implicit-record-route-loading.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index 9a9a695fd6..ed005ea13b 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -42,7 +42,9 @@ By removing this behaviour, we will encourage developers to explicitly define wh ## Detailed design -We will issue a deprecation to `findModel` notifying the user that if they want to continue this behaviour of attempting to fetch a resource implicitly, they should try and replicate with their own explicitly defined `model` hook. This will not remove returning the `transition` context when no `model` hook is defined. +We will issue a deprecation to [`findModel`](https://github.com/emberjs/ember.js/blob/017b11e2f58880869a5b8c647bf7f3199fc07f26/packages/%40ember/-internals/routing/lib/system/route.ts#L1376) notifying the user that if they want to continue this behaviour of attempting to fetch a resource implicitly, they should try and replicate with their own explicitly defined `model` hook. + +In v5.0.0, we will remove `findModel` and logic to determine arguments for this method. This will not remove returning the `transition` context when no `model` hook is defined. ## How we teach this From a3d9b56cd7eec1360bc4bcbed13e4fb4c2725f78 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 2 Oct 2022 20:44:51 -0500 Subject: [PATCH 08/11] add language for optional feature --- text/0774-implicit-record-route-loading.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index ed005ea13b..7cff29fc82 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -44,6 +44,8 @@ By removing this behaviour, we will encourage developers to explicitly define wh We will issue a deprecation to [`findModel`](https://github.com/emberjs/ember.js/blob/017b11e2f58880869a5b8c647bf7f3199fc07f26/packages/%40ember/-internals/routing/lib/system/route.ts#L1376) notifying the user that if they want to continue this behaviour of attempting to fetch a resource implicitly, they should try and replicate with their own explicitly defined `model` hook. +In addition, we will include an [optional feature](https://github.com/emberjs/ember-optional-features) to disable this feature and clear the deprecation. + In v5.0.0, we will remove `findModel` and logic to determine arguments for this method. This will not remove returning the `transition` context when no `model` hook is defined. ## How we teach this From 60a8f3ab22c52b79f257936332410f92aa0e6a55 Mon Sep 17 00:00:00 2001 From: Scott Newcomer Date: Sun, 2 Oct 2022 20:49:38 -0500 Subject: [PATCH 09/11] update header --- text/0774-implicit-record-route-loading.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index 7cff29fc82..b1fe2168ec 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -1,12 +1,12 @@ --- -Stage: Accepted -Start Date: 2021-11-14 -Release Date: Unreleased -Release Versions: - ember-source: vX.Y.Z - ember-data: vX.Y.Z -Relevant Team(s): Ember.js -RFC PR: https://github.com/emberjs/rfcs/pull/774 +stage: accepted +start-date: 2021-11-14 +release-date: +release-versions: +teams: # delete teams that aren't relevant + - framework +prs: + accepted: https://github.com/emberjs/rfcs/pull/774 --- # Deprecate Implicit Record Loading in Routes From d22616f97fb296aa9d2f6b5733a094551723646f Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Fri, 3 Feb 2023 14:19:03 -0500 Subject: [PATCH 10/11] Update text/0774-implicit-record-route-loading.md Co-authored-by: Peter Wagenet --- text/0774-implicit-record-route-loading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index b1fe2168ec..1f10b82d1f 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -32,7 +32,7 @@ In this example, the `model` hook is not defined. However, Ember will attempt t 1. If there is a `store` property on your route, it will attempt to call it's `find` method. Assuming you have `ember-data` installed, you may be expecting this. The arguments will be extracted from the params. a. For example, if a dynamic segment is `:post_id`, there exists logic to split on the underscore and find a record of type `post`. -2. As a fallback, it will attempt to define a `find` method and use your `Model` instance's find method to fetch. If no `find` method exists, an assertion is thrown. +2. As a fallback, it will attempt to define a `find` method and use your `Model` instance's find method to fetch. If a `Model` cannot be found or if the found `Model` does not have a `find` method, an assertion is thrown. ## Motivation From 5353a68c5e16b58d20fad1635b35452b0ea56fac Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Fri, 3 Feb 2023 14:19:17 -0500 Subject: [PATCH 11/11] Update text/0774-implicit-record-route-loading.md Co-authored-by: Peter Wagenet --- text/0774-implicit-record-route-loading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/text/0774-implicit-record-route-loading.md b/text/0774-implicit-record-route-loading.md index 1f10b82d1f..3a5ae917d5 100644 --- a/text/0774-implicit-record-route-loading.md +++ b/text/0774-implicit-record-route-loading.md @@ -46,7 +46,7 @@ We will issue a deprecation to [`findModel`](https://github.com/emberjs/ember.js In addition, we will include an [optional feature](https://github.com/emberjs/ember-optional-features) to disable this feature and clear the deprecation. -In v5.0.0, we will remove `findModel` and logic to determine arguments for this method. This will not remove returning the `transition` context when no `model` hook is defined. +In v6.0.0, we will remove `findModel` and logic to determine arguments for this method. This will not remove returning the `transition` context when no `model` hook is defined. ## How we teach this