Skip to content

Commit 14184ed

Browse files
committed
[DREAM-801] Use useMutation for list lifecycle
Replaces the hand-rolled MutationObserver lifecycle with stimulus-use's useMutation, which owns observer creation and disconnect teardown. Events stay off via dispatchEvent: false so the placeholder insertion does not emit bubbling mutate events the manual observer never had. https://community.openproject.org/wp/DREAM-801
1 parent ced694d commit 14184ed

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

frontend/src/stimulus/controllers/dynamic/border-box-list.controller.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
//++
2828

2929
import { Controller } from '@hotwired/stimulus';
30+
import { useMutation } from 'stimulus-use';
3031

3132
export default class BorderBoxListController extends Controller<HTMLElement> {
3233
static targets = ['list', 'emptyStateTemplate'];
@@ -35,18 +36,20 @@ export default class BorderBoxListController extends Controller<HTMLElement> {
3536

3637
declare readonly emptyStateTemplateTarget:HTMLTemplateElement;
3738

38-
private observer?:MutationObserver;
39-
4039
connect():void {
4140
this.sync();
42-
this.observer = new MutationObserver(() => this.sync());
43-
this.observer.observe(this.listTarget, {
44-
childList: true, subtree: true, attributes: true, attributeFilter: ['class', 'hidden'],
41+
useMutation(this, {
42+
element: this.listTarget,
43+
childList: true,
44+
subtree: true,
45+
attributes: true,
46+
attributeFilter: ['class', 'hidden'],
47+
dispatchEvent: false,
4548
});
4649
}
4750

48-
disconnect():void {
49-
this.observer?.disconnect();
51+
mutate():void {
52+
this.sync();
5053
}
5154

5255
sync():void {

0 commit comments

Comments
 (0)