mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:16:41 +08:00
PERF: Client side triggering multiple requests when opening composer (#21925)
What is the problem? When opening the composer, we are seeing multiple requests made to the `/composer_messages` endpoint. This is due to our use of the `transitionend` event on the `#reply-control` element. The event is fired once for each transition event and the `#reply-control` element has multiple transition events. What is the solution? Since are only interested in the `height` transition event, we add a condition to check that the callback function is only triggered when the `propertyName` of the `transitionend` event is `height`. Why is there no tests for this change? In QUnit, we have `transition: none !important` set in the stylesheet with no easy way to disable. We'll have to accept the risk of not writing test for this performance fix.
This commit is contained in:
parent
7bd826ef11
commit
ce2bd96590
|
@ -180,8 +180,10 @@ export default Component.extend(KeyEnterEscape, {
|
|||
};
|
||||
triggerOpen();
|
||||
|
||||
this.element.addEventListener("transitionend", () => {
|
||||
triggerOpen();
|
||||
this.element.addEventListener("transitionend", (event) => {
|
||||
if (event.propertyName === "height") {
|
||||
triggerOpen();
|
||||
}
|
||||
});
|
||||
|
||||
positioningWorkaround(this.element);
|
||||
|
|
|
@ -16,6 +16,7 @@ import pretender, { response } from "../helpers/create-pretender";
|
|||
|
||||
acceptance("Composer - Messages", function (needs) {
|
||||
needs.user();
|
||||
|
||||
needs.pretender((server, helper) => {
|
||||
server.get("/composer_messages/user_not_seen_in_a_while", () => {
|
||||
return helper.response({
|
||||
|
@ -139,7 +140,9 @@ acceptance("Composer - Messages - Duplicate links", function (needs) {
|
|||
await click("button.create");
|
||||
|
||||
// Work around the lack of CSS transitions in the test env
|
||||
query("#reply-control").dispatchEvent(new Event("transitionend"));
|
||||
const event = new Event("transitionend");
|
||||
event.propertyName = "height";
|
||||
query("#reply-control").dispatchEvent(event);
|
||||
|
||||
assert
|
||||
.dom(".composer-popup")
|
||||
|
|
Loading…
Reference in New Issue
Block a user