Skip to content

Commit

Permalink
Deprecate Location.detect
Browse files Browse the repository at this point in the history
We're only showing the deprecation warning for locations other
than 'auto', since auto already have it's own deprecation message.

We're also moving the rootURL trailing slash check from detect
to initState. That assert has nothing to do with detection, but it
was likely added there because that method is called *after*
the rootURL value is set on the location (by the router).

Luckily, the initState method is also called after that value is set,
so we can use that hook instead.

We're hijacking a method for something that isn't it's primary purpose,
but that was the case with the existing code too, so this seems
like a reasonable solution.
  • Loading branch information
sandstrom committed Sep 4, 2021
1 parent 5af5b9f commit f74ef2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ export default class NoneLocation extends EmberObject implements EmberLocation {
// Set in reopen so it can be overwritten with extend
declare rootURL: string;

detect(): void {
initState(): void {
this._super(...arguments);

let { rootURL } = this;

// This assert doesn't have anything to do with state initialization,
// but we're hijacking this method since it's called after the route has
// set the rootURL property on its Location instance.
assert(
'rootURL must end with a trailing forward slash e.g. "/app/"',
rootURL.charAt(rootURL.length - 1) === '/'
Expand Down
16 changes: 16 additions & 0 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,22 @@ class EmberRouter extends EmberObject.extend(Evented) implements Evented {
// detecting history support. This gives it a chance to set its
// `cancelRouterSetup` property which aborts routing.
if (typeof location.detect === 'function') {
if (this.location !== 'auto') {
deprecate(
'The `detect` method on the Location object is deprecated. If you need detection you can run your detection code in app.js, before setting the location type.',
false,
{
id: 'deprecate-auto-location',
until: '5.0.0',
url: 'https://emberjs.com/deprecations/v3.x#toc_deprecate-auto-location',
for: 'ember-source',
since: {
enabled: '4.1.0',
},
}
);
}

location.detect();
}

Expand Down

0 comments on commit f74ef2a

Please sign in to comment.