mirror of
https://github.com/discourse/discourse.git
synced 2025-03-04 03:38:41 +08:00
FIX: Modal onClose
was being called repeatedly
This happened because the modal controller was not clearing the `name` attribute, which is used for looking up the controller to call `onClose` on. Every page navigation would call the method over and over, breaking state in odd ways.
This commit is contained in:
parent
e44d56e4d2
commit
f57fdee2f6
@ -156,11 +156,18 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, {
|
|||||||
this.render("hide-modal", { into: "modal", outlet: "modalBody" });
|
this.render("hide-modal", { into: "modal", outlet: "modalBody" });
|
||||||
|
|
||||||
const route = getOwner(this).lookup("route:application");
|
const route = getOwner(this).lookup("route:application");
|
||||||
const name = route.controllerFor("modal").get("name");
|
let modalController = route.controllerFor("modal");
|
||||||
const controller = getOwner(this).lookup(`controller:${name}`);
|
const controllerName = modalController.get("name");
|
||||||
|
|
||||||
|
if (controllerName) {
|
||||||
|
const controller = getOwner(this).lookup(
|
||||||
|
`controller:${controllerName}`
|
||||||
|
);
|
||||||
if (controller && controller.onClose) {
|
if (controller && controller.onClose) {
|
||||||
controller.onClose();
|
controller.onClose();
|
||||||
}
|
}
|
||||||
|
modalController.set("name", null);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { acceptance } from "helpers/qunit-helpers";
|
import { acceptance, controllerFor } from "helpers/qunit-helpers";
|
||||||
import showModal from "discourse/lib/show-modal";
|
import showModal from "discourse/lib/show-modal";
|
||||||
|
|
||||||
acceptance("Modal");
|
acceptance("Modal");
|
||||||
|
|
||||||
QUnit.test("modal", async assert => {
|
QUnit.test("modal", async function(assert) {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
@ -14,11 +14,15 @@ QUnit.test("modal", async assert => {
|
|||||||
await click(".login-button");
|
await click(".login-button");
|
||||||
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
|
assert.ok(find(".d-modal:visible").length === 1, "modal should appear");
|
||||||
|
|
||||||
|
let controller = controllerFor("modal");
|
||||||
|
assert.equal(controller.name, "login");
|
||||||
|
|
||||||
await click(".modal-outer-container");
|
await click(".modal-outer-container");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
find(".d-modal:visible").length === 0,
|
find(".d-modal:visible").length === 0,
|
||||||
"modal should disappear when you click outside"
|
"modal should disappear when you click outside"
|
||||||
);
|
);
|
||||||
|
assert.equal(controller.name, null);
|
||||||
|
|
||||||
await click(".login-button");
|
await click(".login-button");
|
||||||
assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
|
assert.ok(find(".d-modal:visible").length === 1, "modal should reappear");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user