diff --git a/packages/@ember/-internals/environment/lib/env.ts b/packages/@ember/-internals/environment/lib/env.ts index e7a7eb4dda2..6008a14e936 100644 --- a/packages/@ember/-internals/environment/lib/env.ts +++ b/packages/@ember/-internals/environment/lib/env.ts @@ -142,6 +142,22 @@ export const ENV = { */ _DEFAULT_ASYNC_OBSERVERS: false, + /** + Whether the app still has default record-loading behavior in the model + hook from RFC https://rfcs.emberjs.com/id/0774-implicit-record-route-loading + This will also remove the default store property from the route. + + This is not intended to be set directly, as the implementation may change in + the future. Use `@ember/optional-features` instead. + + @property _NO_IMPLICIT_ROUTE_MODEL + @for EmberENV + @type Boolean + @default false + @private + */ + _NO_IMPLICIT_ROUTE_MODEL: false, + /** Controls the maximum number of scheduled rerenders without "settling". In general, applications should not need to modify this environment variable, but please diff --git a/packages/@ember/routing/route.ts b/packages/@ember/routing/route.ts index f4526ba13af..8a060e23747 100644 --- a/packages/@ember/routing/route.ts +++ b/packages/@ember/routing/route.ts @@ -7,6 +7,7 @@ import { } from '@ember/-internals/metal'; import type Owner from '@ember/owner'; import { getOwner } from '@ember/-internals/owner'; +import { ENV } from '@ember/-internals/environment'; import { BucketCache } from '@ember/routing/-internals'; import EmberObject, { computed, get, set, getProperties, setProperties } from '@ember/object'; import Evented from '@ember/object/evented'; @@ -1251,6 +1252,9 @@ class Route extends EmberObject.extend(ActionHandler, Evented) @private */ findModel(type: string, value: unknown) { + if (ENV._NO_IMPLICIT_ROUTE_MODEL) { + return; + } deprecate( `The implicit model loading behavior for routes is deprecated. ` + `Please define an explicit model hook for ${this.fullRouteName}.`, diff --git a/packages/@ember/routing/tests/system/route_test.js b/packages/@ember/routing/tests/system/route_test.js index 9f9ab0cfb4d..072192a567b 100644 --- a/packages/@ember/routing/tests/system/route_test.js +++ b/packages/@ember/routing/tests/system/route_test.js @@ -1,4 +1,5 @@ import { setOwner } from '@ember/-internals/owner'; +import { ENV } from '@ember/-internals/environment'; import { runDestroy, buildOwner, moduleFor, AbstractTestCase } from 'internal-test-helpers'; import Service, { service } from '@ember/service'; import EmberObject from '@ember/object'; @@ -22,6 +23,17 @@ moduleFor( route = routeOne = routeTwo = lookupHash = undefined; } + ['@test noops if _NO_IMPLICIT_ROUTE_MODEL is true'](assert) { + this._NO_IMPLICIT_ROUTE_MODEL = ENV._NO_IMPLICIT_ROUTE_MODEL; + ENV._NO_IMPLICIT_ROUTE_MODEL = true; + assert.equal( + route.findModel('post', 1), + undefined, + 'When _NO_IMPLICIT_ROUTE_MODEL is true, findModel does nothing' + ); + ENV._NO_IMPLICIT_ROUTE_MODEL = this._NO_IMPLICIT_ROUTE_MODEL; + } + ['@test default store utilizes the container to acquire the model factory'](assert) { assert.expect(5); diff --git a/tests/docs/expected.js b/tests/docs/expected.js index 374ed0282d8..d02bb5986d7 100644 --- a/tests/docs/expected.js +++ b/tests/docs/expected.js @@ -10,6 +10,7 @@ module.exports = { '_APPLICATION_TEMPLATE_WRAPPER', '_DEBUG_RENDER_TREE', '_DEFAULT_ASYNC_OBSERVERS', + '_NO_IMPLICIT_ROUTE_MODEL', '_RERENDER_LOOP_LIMIT', '_TEMPLATE_ONLY_GLIMMER_COMPONENTS', 'Input',