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

Ensure query params are preserved through an intermediate loading state transition #319

Merged
merged 2 commits into from
Mar 4, 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
3 changes: 3 additions & 0 deletions lib/router/transition-intent/named-transition-intent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export default class NamedTransitionIntent<T extends Route> extends TransitionIn
}

merge(newState.queryParams, this.queryParams || {});
if (isIntermediate && oldState.queryParams) {
merge(newState.queryParams, oldState.queryParams);
}

return newState;
}
Expand Down
19 changes: 7 additions & 12 deletions tests/router_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5376,7 +5376,7 @@ scenarios.forEach(function (scenario) {
});

test('intermediateTransitionTo() has the correct RouteInfo objects', function (assert) {
assert.expect(6);
assert.expect(9);
routes = {
application: createHandler('application'),
foo: createHandler('foo', {
Expand All @@ -5394,28 +5394,23 @@ scenarios.forEach(function (scenario) {
router.routeWillChange = (transition: Transition) => {
if (enteredCount === 0) {
assert.equal(transition.to!.name, 'foo', 'going to');
enteredCount++;
assert.equal(transition.to!.queryParams.qux, '42', 'going to with query params');
} else if (enteredCount === 1) {
assert.equal(transition.to!.name, 'loading', 'entering');
assert.equal(transition.to!.queryParams.qux, '42', 'intermediate also has query params');
// https://github.com/emberjs/ember.js/issues/14438
assert.equal(transition[STATE_SYMBOL].routeInfos.length, 2, 'with routeInfos present');
enteredCount++;
} else {
assert.equal(transition.to!.name, 'foo', 'back to');
enteredCount++;
}
enteredCount++;
assert.equal(transition.from, null);
};

router.routeDidChange = (transition: Transition) => {
if (enteredCount === 1) {
assert.equal(transition.to!.name, 'loading');
} else {
assert.equal(transition.to!.name, 'foo', 'landed at');
}
assert.equal(transition.to!.name, 'foo', 'landed at');
assert.equal(enteredCount, 2);
};

transitionTo(router, '/foo');
transitionTo(router, '/foo?qux=42');
});

test("intermediateTransitionTo() forces an immediate intermediate transition that doesn't cancel currently active async transitions", function (assert) {
Expand Down