Skip to content

Commit 29199ea

Browse files
authored
Merge pull request #19448 from sly7-7/loading-state-qp-bug
Ensure query params are preserved through an intermediate loading state transition
2 parents b64b292 + f512bfe commit 29199ea

File tree

3 files changed

+156
-5
lines changed

3 files changed

+156
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"rollup-plugin-commonjs": "^9.3.4",
142142
"rollup-plugin-node-resolve": "^4.2.4",
143143
"route-recognizer": "^0.3.4",
144-
"router_js": "^7.1.1",
144+
"router_js": "^7.2.0",
145145
"rsvp": "^4.8.5",
146146
"serve-static": "^1.14.1",
147147
"simple-dom": "^1.4.0",

packages/ember/tests/routing/substates_test.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { RSVP } from '@ember/-internals/runtime';
22
import { Route } from '@ember/-internals/routing';
3+
import Controller from '@ember/controller';
4+
35
import { moduleFor, ApplicationTestCase, runTask } from 'internal-test-helpers';
46

57
let counter;
@@ -193,6 +195,155 @@ moduleFor(
193195
});
194196
}
195197

198+
['@test Enter loading route with correct query parameters'](assert) {
199+
let deferred = RSVP.defer();
200+
201+
this.router.map(function () {
202+
this.route('dummy');
203+
});
204+
205+
this.add(
206+
'route:dummy',
207+
Route.extend({
208+
model() {
209+
step(assert, 1, 'DummyRoute#model');
210+
return deferred.promise;
211+
},
212+
})
213+
);
214+
215+
this.add(
216+
'controller:application',
217+
class extends Controller {
218+
queryParams = ['qux'];
219+
220+
qux = 'initial';
221+
}
222+
);
223+
224+
this.add(
225+
'route:loading',
226+
Route.extend({
227+
setupController() {
228+
step(assert, 2, 'LoadingRoute#setupController');
229+
},
230+
})
231+
);
232+
this.addTemplate('dummy', 'DUMMY');
233+
234+
return this.visit('/?qux=updated').then(() => {
235+
assert.equal(
236+
this.getController('application').qux,
237+
'updated',
238+
'the application controller has the correct qp value'
239+
);
240+
241+
let promise = this.visit('/dummy?qux=updated').then(() => {
242+
let text = this.$('#app').text();
243+
244+
assert.equal(text, 'DUMMY', `dummy template has been rendered`);
245+
assert.equal(
246+
this.getController('application').qux,
247+
'updated',
248+
'the application controller has the correct qp value'
249+
);
250+
});
251+
252+
assert.equal(this.currentPath, 'loading', `loading state entered`);
253+
assert.equal(
254+
this.currentURL,
255+
'/dummy?qux=updated',
256+
`during loading url reflect the correct state`
257+
);
258+
assert.equal(
259+
this.getController('application').qux,
260+
'updated',
261+
'the application controller has the correct qp value'
262+
);
263+
264+
deferred.resolve();
265+
266+
return promise;
267+
});
268+
}
269+
270+
['@test Enter child-loading route with correct query parameters'](assert) {
271+
assert.expect(9);
272+
let deferred = RSVP.defer();
273+
274+
this.router.map(function () {
275+
this.route('parent', function () {
276+
this.route('child');
277+
});
278+
});
279+
280+
this.add(
281+
'route:parent.child',
282+
Route.extend({
283+
model() {
284+
step(assert, 1, 'ChildRoute#model');
285+
return deferred.promise;
286+
},
287+
})
288+
);
289+
290+
this.add(
291+
'controller:parent',
292+
class extends Controller {
293+
queryParams = ['qux'];
294+
295+
qux = 'initial';
296+
}
297+
);
298+
299+
this.add(
300+
'route:parent.child_loading',
301+
Route.extend({
302+
setupController() {
303+
step(assert, 2, 'ChildLoadingRoute#setupController');
304+
},
305+
})
306+
);
307+
this.addTemplate('parent', 'PARENT {{outlet}}');
308+
309+
this.addTemplate('parent.child', 'CHILD');
310+
311+
return this.visit('/parent?qux=updated').then(() => {
312+
assert.equal(
313+
this.getController('parent').qux,
314+
'updated',
315+
'in the parent route, the parent controller has the correct qp value'
316+
);
317+
318+
let promise = this.visit('/parent/child?qux=updated').then(() => {
319+
let text = this.$('#app').text();
320+
321+
assert.equal(text, 'PARENT CHILD', `child template has been rendered`);
322+
assert.equal(
323+
this.getController('parent').qux,
324+
'updated',
325+
'after entered in the parent.child route, the parent controller has the correct qp value'
326+
);
327+
});
328+
329+
assert.equal(this.currentPath, 'parent.child_loading', `child loading state entered`);
330+
assert.equal(
331+
this.currentURL,
332+
'/parent/child?qux=updated',
333+
`during child loading, url reflect the correct state`
334+
);
335+
assert.equal(
336+
this.getController('parent').qux,
337+
'updated',
338+
'in the child_loading route, the parent controller has the correct qp value'
339+
);
340+
341+
deferred.resolve();
342+
343+
return promise;
344+
});
345+
}
346+
196347
['@test Slow promises returned from ApplicationRoute#model enter ApplicationLoadingRoute if present'](
197348
assert
198349
) {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8907,10 +8907,10 @@ route-recognizer@^0.3.4:
89078907
resolved "https://registry.yarnpkg.com/route-recognizer/-/route-recognizer-0.3.4.tgz#39ab1ffbce1c59e6d2bdca416f0932611e4f3ca3"
89088908
integrity sha512-2+MhsfPhvauN1O8KaXpXAOfR/fwe8dnUXVM+xw7yt40lJRfPVQxV6yryZm0cgRvAj5fMF/mdRZbL2ptwbs5i2g==
89098909

8910-
router_js@^7.1.1:
8911-
version "7.1.1"
8912-
resolved "https://registry.yarnpkg.com/router_js/-/router_js-7.1.1.tgz#cb7614a96cfb6bc65c066668b2dd32e3ad7ca38d"
8913-
integrity sha512-kOdKqBj7aj9GusG0umtWgkTtNtDspT9EfJNnJN9B8g0DDNp9CdIwpO+2Qnmf/fNos38Pj9jlfU44l/oycn5goQ==
8910+
router_js@^7.2.0:
8911+
version "7.2.0"
8912+
resolved "https://registry.yarnpkg.com/router_js/-/router_js-7.2.0.tgz#a7168155fe494f85f1e5058802a3a633c29ea243"
8913+
integrity sha512-kZBOqD/kRMDymmVbiVrX6OK3cGBoG1c9tO8egxkoxX2TgC78sBwFhvFqkAJLvK8oTEXYNcjk8+FbNIn9hg9VMA==
89148914
dependencies:
89158915
"@glimmer/env" "^0.1.7"
89168916

0 commit comments

Comments
 (0)