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

Deprecate implicit record loading in routes #557

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Nov 27, 2019

@runspired
Copy link
Contributor

This behavior and implicit store are unrelated to EmberData. EmberData implements the find method and injects itself eagerly in order to correct the behavior of the default for users of EmberData, but if you are not using EmberData you will still have a store and this auto find behavior.

This RFC should likely deprecate defaultStore and it’s behaviors more widely.

@NullVoxPopuli
Copy link
Contributor Author

, but if you are not using EmberData you will still have a store and this auto find behavior.

what is loaded? I've never heard of defaultStore before today.

@NullVoxPopuli
Copy link
Contributor Author

oof. ok. thanks. yeah, this deprecation should def include deprecating that as well :D

@joukevandermaas
Copy link

BIG fan of this RFC. A few weeks ago I spent half a day trying to figure out why our app was doing an unexpected request, until I stumbled upon this gem of functionality 😅.

Yes, the behavior is fun if you know about it, but if you don't it can be very confusing.

@runspired
Copy link
Contributor

@NullVoxPopuli are you going to update this RFC to eliminate defaultStore?

Also for the alternatives I would note that defaultStore negatively impacts users of EmberData as well, and forces EmberData to do hacky things that we don't want to do. We have wished for this to be deprecated and removed for years. Thank you for taking it on <3

@tniezurawski
Copy link

Removing a bit of magic that isn't explained anywhere sounds good 👍

I'm not sure about the Motivation section and enforcing the case on params/variables. I believe that's not a subject of this RFC and should stay in devs' lint configs. IMO the true motivation is to remove that implicit record loading. Although I cringe every time I have to use something else than camelCase I think we shouldn't force anything.

Copy link
Member

rwjblue commented Dec 6, 2019

Although I cringe every time I have to use something else than camelCase I think we shouldn't force anything.

Yes, I definitely agree with this point.

@dcyriller
Copy link
Contributor

For reference, the functionality (default store + implicit record loading) is explained in this article: https://blog.pablobm.com/2019/01/15/store-without-ember-data.html


## Motivation

Recently, [eslint-plugin-ember](https://github.com/ember-cli/eslint-plugin-ember/issues/410) introduced a lint rule to _enforce_ the `snake_case` convention of dynamic segments. I and a few others don't like `snake_case` in JavaScript, as the convention is `camelCase`. We looked into submitting an RFC for changing the default to `camelCase`, but encountered [this code](https://github.com/emberjs/ember.js/blob/b4456779d0f5f5b99da853c4e1f0688ce96cc27c/packages/%40ember/-internals/routing/lib/system/route.ts#L1167-L1186) that suggests some implicit data loading behavior for `snake_case` params _ending_ in `_id` and if you _happen_ to have a service named `store`.
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, it isn't just when you have service named store. Ember itself has a default this.store property on @ember/routing/route:

https://github.com/emberjs/ember.js/blob/b4456779d0f5f5b99da853c4e1f0688ce96cc27c/packages/%40ember/-internals/routing/lib/system/route.ts#L2220

Copy link
Member

Choose a reason for hiding this comment

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

Also, this link:

https://github.com/emberjs/ember.js/blob/b4456779d0f5f5b99da853c4e1f0688ce96cc27c/packages/%40ember/-internals/routing/lib/system/route.ts#L1167-L1186

Is actually showing two different issues:

This RFC is (AFAICT) only talking about deprecating the first thing and not the second.


We don't teach this behavior, so the transition path should be fairly light.

if someone _doesn't_ define a `model` hook on their route, and are taking advantage of the implicit record loading behavior, they will be presented with a deprecation warning in the console [triggered from here](https://github.com/emberjs/ember.js/blob/b4456779d0f5f5b99da853c4e1f0688ce96cc27c/packages/%40ember/-internals/routing/lib/system/route.ts#L1209) -- showing that removal will happen in Ember v4.
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs a bit more details.

  • How do you determine that they are taking advantage of the implicit record loading behaviors? Is it only when that this.findModel invocation actually returns a value?
  • We should also deprecate using the implicit this.store on @ember/routing/route (the one here). This would not affect ember-data users because ember-data clobbers with an initializer injection on all routes, or users already leveraging @service store in their Route file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Implicit injections have now been removed for 4.0!

#680


Ember Guides shouldn't need updating.

Adding an entry to the deprecation guides should be sufficient, briefly explaining the before/after from above should be sufficient.
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the content of this section with the deprecation guide entry contents? IMHO this is really the main part of this particular RFC and being able to discuss the actual suggestions / prose would be really useful.


Drawbacks only exist for people who are utilizing this implicit behavior. For them, the drawbacks are:
- they now have to define a model hook
- they may have to create a route file where previously the route was implicitly defined for them and implicitly loading the record for them as well
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this isn't a drawback 😉

@rwjblue rwjblue added the T-framework RFCs that impact the ember.js library label May 20, 2020
@rwjblue rwjblue self-assigned this May 20, 2020
@jelhan
Copy link
Contributor

jelhan commented Aug 8, 2020

Moving this forward would be great. The bugs caused by this magic are hard to debug and very confusing to people new to ember.

It so easy to miss defining a model hook. It's very likely that developer notice what's going wrong when dealing with a this.model or @model, which is undefined. But due to this magic often an error is thrown, which causes confusion and pulls the developer on a wrong track.

Maybe that should be mentioned also explicitly in the motivation section.


## How We Teach This

Ember Guides shouldn't need updating.
Copy link

Choose a reason for hiding this comment

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

Actually, the guides will need to be changed. The auto model loading behavior is mentioned in the Dynamic segments section.

@wagenet
Copy link
Member

wagenet commented Jul 23, 2022

@NullVoxPopuli where does this stand?

@NullVoxPopuli
Copy link
Contributor Author

I don't know if it's worth pursuing if our next routing system is just.. different entirely 🙃

maybe we/i/someone need to spike out what that next routing system would be like (actual usage / code, rather than readme-driven development), and see if there is a way to integrate that into the current system, and then maybe route-by-route opt in to it, and eventually deprecate the old thing.

Having interop between routers could be interesting tho -- need to look in to where the constraints are.

@runspired
Copy link
Contributor

I think it's heavily worth pursuing, if for no other reason it removes one more crazy piece that the next system would have to account for the transition for. We know we don't want this behavior, may as well discard it now.

@NullVoxPopuli
Copy link
Contributor Author

excellent -- well if anyone wants to help out with this RFC, applying the above feedback, that'd be super :D

@NullVoxPopuli
Copy link
Contributor Author

Superseded by: #774

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-framework RFCs that impact the ember.js library
Projects
None yet
Development

Successfully merging this pull request may close these issues.