perf: defer autoUpdate until menu is open to fix slow profile icon rendering

autoUpdate from @floating-ui/dom was being started in connect(), causing
immediate layout/size calculations for every menu instance on page load
even while closed. Moved autoUpdate to only run when the menu is open,
and stop when closed/toggled off.

https://claude.ai/code/session_01FkTsyLvEod4qN6T5dNidkL
This commit is contained in:
Claude
2026-03-28 12:13:41 +00:00
parent e7af0ad99b
commit 96b981caba

View File

@@ -24,7 +24,6 @@ export default class extends Controller {
this.show = this.showValue;
this.boundUpdate = this.update.bind(this);
this.addEventListeners();
this.startAutoUpdate();
}
disconnect() {
@@ -66,14 +65,18 @@ export default class extends Controller {
this.show = !this.show;
this.contentTarget.classList.toggle("hidden", !this.show);
if (this.show) {
this.startAutoUpdate();
this.update();
this.focusFirstElement();
} else {
this.stopAutoUpdate();
}
};
close() {
this.show = false;
this.contentTarget.classList.add("hidden");
this.stopAutoUpdate();
}
focusFirstElement() {