[BUGFIX 3.28] Improve assert in default store#19857
Merged
rwjblue merged 1 commit intoemberjs:release-3-28from Nov 30, 2021
Merged
[BUGFIX 3.28] Improve assert in default store#19857rwjblue merged 1 commit intoemberjs:release-3-28from
rwjblue merged 1 commit intoemberjs:release-3-28from
Conversation
778a116 to
4cca1f8
Compare
When a route has a dynamic segment, several implicit behaviors may be provided by the Ember framework or by the framework in conjunction with a library (commonly Ember Data). * If the route class exists and has a `model(` hook implemented, then that logic is the explicit implementation for data loading on that route. In the far future (say, Ember 5), we want explicit data loading to be the only way data can be loaded. * However, today there are several implicit data loading behaviors. First, the user may explicitly inject a `store` service into the route. If a `model` hook is not implemented, the `find` method on the store will be called. This is, as of this writing, valid in Ember 3 & 4 and not deprecated. * If a `model` hook is not implemented and if an explicit injection is not present, a container/owner-based implicit type or factor injection may have added the `store`. This if valid in Ember 3, but deprecated in Ember 3.28.7 (see emberjs#19854), and does not occur in Ember 4 since implicit injections are no longer supported. * If a `model` hook is not implemented, and if neither an explicit or implicit injection of `store` is made, then Ember provides a minimal "default store" implementation. This looks up a model matching the route name, and calls a `find` method on that model. If there is no model, an assertion is thrown. If there a model but it has no `find`, an assertion is thrown. This patch updates those assertions (which are very old) to better coach developers toward the APIs we prefer in modern development. These are: * If you have a route with dynamic segments, you should implement a `model` hook on the route. * Alternatively, and as a transition step for existing code, you may explicitly inject a store on the route to preserve behavior in an application which was relying on implicit injections. There are a lot of edge cases to consider in these copy changes. Many apps use Ember Data. Some apps use different data layers which also provide a `store` service. Some applications implement their own `store` and may implicitly inject it. Some use no `store` at all! Many apps use dynamic segments. Developers may not realize that if a model hook (or route class) has not been defined in Ember and Ember Data 3.28, the `store` service is being relied upon and causes these assertions to never be run. In Ember 3.28 accessing the implicit injection of `store` (and indeed all implicit injection consumption) is deprecated, so existing code should be upgraded to explicit injections and these assertions should never come into play. In Ember 4.0 developers who author: * A new dynamic segment route. * ...with no route class or no model hook. * ...and no explicit service injection. * ...but who also have `model` type factories (likely through Ember Data convention) Would see the second of the updated assertions here. This patch updates the message for 3.28 since it is plausible some non-conventional apps could be seeing this message in 3.x, especially as they upgrade to Ember 4.0.
4cca1f8 to
9937a50
Compare
rwjblue
approved these changes
Nov 30, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mirrors #19858, but for Ember 3.28.
When a route has a dynamic segment, several implicit behaviors may be provided by the Ember framework or by the framework in conjunction with a library (commonly Ember Data).
model(hook implemented, then that logic is the explicit implementation for data loading on that route. In the far future (say, Ember 5), we want explicit data loading to be the only way data can be loaded.storeservice into the route. If amodelhook is not implemented, thefindmethod on the store will be called. This is, as of this writing, valid in Ember 3 & 4 and not deprecated.modelhook is not implemented and if an explicit injection is not present, a container/owner-based implicit type or factor injection may have added thestore. This if valid in Ember 3, but deprecated in Ember 3.28.7 (see [BUGFIX 3.28] Improve implicit injections deprecation for routes #19854), and does not occur in Ember 4 since implicit injections are no longer supported.modelhook is not implemented, and if neither an explicit or implicit injection ofstoreis made, then Ember provides a minimal "default store" implementation. This looks up a model matching the route name, and calls afindmethod on that model. If there is no model, an assertion is thrown. If there a model but it has nofind, an assertion is thrown.This patch updates those assertions (which are very old) to better coach developers toward the APIs we prefer in modern development. These are:
modelhook on the route.There are a lot of edge cases to consider in these copy changes. Many apps use Ember Data. Some apps use different data layers which also provide a
storeservice. Some applications implement their ownstoreand may implicitly inject it. Some use nostoreat all!Many apps use dynamic segments. Developers may not realize that if a model hook (or route class) has not been defined in Ember and Ember Data 3.28, the
storeservice is being relied upon and causes these assertions to never be run.In Ember 3.28 accessing the implicit injection of
store(and indeed all implicit injection consumption) is deprecated, so existing code should be upgraded to explicit injections and these assertions should never come into play.In Ember 4.0 developers who author:
modeltype factories (likely through EmberData convention)
Would see the second of the updated assertions here. This patch updates the message for 3.28 since it is plausible some non-conventional apps could be seeing this message in 3.x, especially as they upgrade to Ember 4.0.