DEV: Do not rerender widgets on mouseup/mousedown (#21300)

Ran into an issue with these hooks preventing click events on anchors from completing (because the triggered rerender cancels the click). See:
https://github.com/discourse/discourse-header-search/pull/24

This change should have no effect on existing usage of these hooks. Current usage is limited to:

- legacy navigation (should be a no-op)
- reactions plugin (should be a no-op)
- discourse-header-search (will fix the issue!)
This commit is contained in:
Penar Musaraj 2023-05-01 14:07:49 -04:00 committed by GitHub
parent b1da670898
commit d697fd5766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -192,6 +192,7 @@ export const DefaultNotificationItem = createWidget(
method: "PUT",
data: { id: this.attrs.id },
});
this.scheduleRerender();
}
},
}

View File

@ -263,13 +263,20 @@ WidgetClickHook.setupDocumentCallback = function () {
});
$(document).on("mousedown.discourse-widget", (e) => {
nodeCallback(e.target, MOUSE_DOWN_ATTRIBUTE_NAME, (w) => {
w.mouseDown(e);
});
nodeCallback(
e.target,
MOUSE_DOWN_ATTRIBUTE_NAME,
(w) => {
w.mouseDown(e);
},
{ rerender: false }
);
});
$(document).on("mouseup.discourse-widget", (e) => {
nodeCallback(e.target, MOUSE_UP_ATTRIBUTE_NAME, (w) => w.mouseUp(e));
nodeCallback(e.target, MOUSE_UP_ATTRIBUTE_NAME, (w) => w.mouseUp(e), {
rerender: false,
});
});
$(document).on("mousemove.discourse-widget", (e) => {

View File

@ -55,7 +55,11 @@ module(
assert.ok(!exists("li.read"));
await triggerEvent("li", "mouseup", { button: 1, which: 2 });
assert.strictEqual(count("li.read"), 1);
assert.strictEqual(
count("li.read"),
1,
"only one item is marked as read"
);
assert.strictEqual(requests, 1);
});
}