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

Update current route in willChangeRoute during an intermediate transition #19450

Merged
merged 2 commits into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-node-resolve": "^4.2.4",
"route-recognizer": "^0.3.4",
"router_js": "^7.2.0",
"router_js": "^7.3.0",
"rsvp": "^4.8.5",
"serve-static": "^1.14.1",
"simple-dom": "^1.4.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/@ember/-internals/routing/lib/system/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ class EmberRouter extends EmberObject {

routeWillChange(transition: Transition) {
router.trigger('routeWillChange', transition);
// in case of intermediate transition we update the current route
// to make router.currentRoute.name consistent with router.currentRouteName
// see https://github.com/emberjs/ember.js/issues/19449
if (transition.isIntermediate) {
router.set('currentRoute', transition.to);
}
}

routeDidChange(transition: Transition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let InstrumentedRoute = Route.extend({
let service = get(this, 'routerService');
service.on('routeWillChange', (transition) => {
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} routeWillChange: ${transition.from && transition.from.name} - ${
transition.to.name
}`,
Expand All @@ -26,7 +26,7 @@ let InstrumentedRoute = Route.extend({
});
service.on('routeDidChange', (transition) => {
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} routeDidChange: ${transition.from && transition.from.name} - ${
transition.to.name
}`,
Expand All @@ -38,7 +38,7 @@ let InstrumentedRoute = Route.extend({
activate() {
let service = get(this, 'routerService');
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} activate`,
service.get('currentURL'),
]);
Expand All @@ -47,7 +47,7 @@ let InstrumentedRoute = Route.extend({
redirect() {
let service = get(this, 'routerService');
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} redirect`,
service.get('currentURL'),
]);
Expand All @@ -56,7 +56,7 @@ let InstrumentedRoute = Route.extend({
beforeModel() {
let service = get(this, 'routerService');
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} beforeModel`,
service.get('currentURL'),
]);
Expand All @@ -65,7 +65,7 @@ let InstrumentedRoute = Route.extend({
model() {
let service = get(this, 'routerService');
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} model`,
service.get('currentURL'),
]);
Expand All @@ -77,7 +77,7 @@ let InstrumentedRoute = Route.extend({
afterModel() {
let service = get(this, 'routerService');
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} afterModel`,
service.get('currentURL'),
]);
Expand All @@ -87,7 +87,7 @@ let InstrumentedRoute = Route.extend({
willTransition(transition) {
let service = get(this, 'routerService');
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} willTransition: ${transition.from && transition.from.name} - ${
transition.to.name
}`,
Expand All @@ -98,7 +98,7 @@ let InstrumentedRoute = Route.extend({
didTransition() {
let service = get(this, 'routerService');
results.push([
service.get('currentRouteName'),
`${service.get('currentRouteName')} - ${service.get('currentRoute.name')}`,
`${this.routeName} didTransition`,
service.get('currentURL'),
]);
Expand All @@ -108,7 +108,7 @@ let InstrumentedRoute = Route.extend({
});

moduleFor(
'Router Service - currentURL | currentRouteName',
'Router Service - currentURL | currentRouteName | currentRoute.name',
class extends RouterTestCase {
constructor() {
super(...arguments);
Expand Down Expand Up @@ -189,18 +189,26 @@ moduleFor(
return this.visit('/')
.then(() => {
assert.deepEqual(results, [
[null, 'parent.index routeWillChange: null - parent.index', null],
[null, 'parent.index beforeModel', null],
[null, 'parent.index model', null],
[null, 'parent.loading activate', null],
[null, 'parent.loading routeWillChange: null - parent.loading', null],
[null, 'parent.index routeWillChange: null - parent.loading', null],
['parent.loading', 'parent.index afterModel', '/'],
['parent.loading', 'parent.index redirect', '/'],
['parent.loading', 'parent.index activate', '/'],
['parent.loading', 'parent.index didTransition', '/'],
['parent.index', 'parent.loading routeDidChange: null - parent.index', '/'],
['parent.index', 'parent.index routeDidChange: null - parent.index', '/'],
['null - undefined', 'parent.index routeWillChange: null - parent.index', null],
['null - undefined', 'parent.index beforeModel', null],
['null - undefined', 'parent.index model', null],
['null - undefined', 'parent.loading activate', null],
['null - undefined', 'parent.loading routeWillChange: null - parent.loading', null],
['null - undefined', 'parent.index routeWillChange: null - parent.loading', null],
['parent.loading - parent.loading', 'parent.index afterModel', '/'],
['parent.loading - parent.loading', 'parent.index redirect', '/'],
['parent.loading - parent.loading', 'parent.index activate', '/'],
['parent.loading - parent.loading', 'parent.index didTransition', '/'],
[
'parent.index - parent.index',
'parent.loading routeDidChange: null - parent.index',
'/',
],
[
'parent.index - parent.index',
'parent.index routeDidChange: null - parent.index',
'/',
],
]);

results = [];
Expand All @@ -209,27 +217,63 @@ moduleFor(
})
.then(() => {
assert.deepEqual(results, [
['parent.index', 'parent.index willTransition: parent.index - parent.child', '/'],
['parent.index', 'parent.child routeWillChange: parent.index - parent.child', '/'],
['parent.index', 'parent.loading routeWillChange: parent.index - parent.child', '/'],
['parent.index', 'parent.index routeWillChange: parent.index - parent.child', '/'],
['parent.index', 'parent.child beforeModel', '/'],
['parent.index', 'parent.child model', '/'],
['parent.index', 'parent.loading activate', '/'],
['parent.index', 'parent.child routeWillChange: parent.index - parent.loading', '/'],
['parent.index', 'parent.loading routeWillChange: parent.index - parent.loading', '/'],
['parent.index', 'parent.index routeWillChange: parent.index - parent.loading', '/'],
['parent.loading', 'parent.child afterModel', '/child'],
['parent.loading', 'parent.child redirect', '/child'],
['parent.loading', 'parent.child activate', '/child'],
['parent.loading', 'parent.child didTransition', '/child'],
['parent.child', 'parent.child routeDidChange: parent.index - parent.child', '/child'],
[
'parent.child',
'parent.index - parent.index',
'parent.index willTransition: parent.index - parent.child',
'/',
],
[
'parent.index - parent.index',
'parent.child routeWillChange: parent.index - parent.child',
'/',
],
[
'parent.index - parent.index',
'parent.loading routeWillChange: parent.index - parent.child',
'/',
],
[
'parent.index - parent.index',
'parent.index routeWillChange: parent.index - parent.child',
'/',
],
['parent.index - parent.index', 'parent.child beforeModel', '/'],
['parent.index - parent.index', 'parent.child model', '/'],
['parent.index - parent.index', 'parent.loading activate', '/'],
[
'parent.index - parent.index',
'parent.child routeWillChange: parent.index - parent.loading',
'/',
],
[
'parent.index - parent.index',
'parent.loading routeWillChange: parent.index - parent.loading',
'/',
],
[
'parent.index - parent.index',
'parent.index routeWillChange: parent.index - parent.loading',
'/',
],
['parent.loading - parent.loading', 'parent.child afterModel', '/child'],
['parent.loading - parent.loading', 'parent.child redirect', '/child'],
['parent.loading - parent.loading', 'parent.child activate', '/child'],
['parent.loading - parent.loading', 'parent.child didTransition', '/child'],
[
'parent.child - parent.child',
'parent.child routeDidChange: parent.index - parent.child',
'/child',
],
[
'parent.child - parent.child',
'parent.loading routeDidChange: parent.index - parent.child',
'/child',
],
['parent.child', 'parent.index routeDidChange: parent.index - parent.child', '/child'],
[
'parent.child - parent.child',
'parent.index routeDidChange: parent.index - parent.child',
'/child',
],
]);
});
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8907,10 +8907,10 @@ route-recognizer@^0.3.4:
resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3"
integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g==

router_js@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/router_js/-/router_js-7.2.0.tgz#a7168155fe494f85f1e5058802a3a633c29ea243"
integrity sha512-kZBOqD/kRMDymmVbiVrX6OK3cGBoG1c9tO8egxkoxX2TgC78sBwFhvFqkAJLvK8oTEXYNcjk8+FbNIn9hg9VMA==
router_js@^7.3.0:
version "7.3.0"
resolved "https://registry.yarnpkg.com/router_js/-/router_js-7.3.0.tgz#6c061b6b097cfec537fa0d6c5a5c6e317730799f"
integrity sha512-A+iVTfG03XNks7oC/KGXq+EKp9kAac9BOYuomq2KouXUM4U57Io20/tuQq1kx+OwHB4gEY0XaRQjuHwljkbRHg==
dependencies:
"@glimmer/env" "^0.1.7"

Expand Down