PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | src/Toolbar/toolbar.js +29 -17 3.1.5 → trunk View file →
@@ -70,30 +70,42 @@
70 70 * the Zustand store so we don't have to share a chunk with the
71 71 * agent bundle.
72 72 */
73 73 function watchAgentSidebar(toolbar, aiBtn) {
74 - let attached = false;
74 + const setOpen = (open) => {
75 + toolbar.classList.toggle('ext-tb-agent-open', open);
76 + if (!aiBtn) return;
77 + aiBtn.inert = open;
78 + if (open) {
79 + aiBtn.setAttribute('tabindex', '-1');
80 + aiBtn.setAttribute('aria-hidden', 'true');
81 + } else {
82 + aiBtn.removeAttribute('tabindex');
83 + aiBtn.removeAttribute('aria-hidden');
84 + }
85 + };
86 + // A resize past the mobile breakpoint replaces this node, so never latch on one.
87 + let watched = null;
88 + let inertObserver = null;
75 89 const observer = watch(
76 90 document.body,
77 91 { childList: true, subtree: true },
78 92 () => {
79 93 const sidebar = document.getElementById(AGENT_SIDEBAR_ID);
80 - if (!sidebar || attached) return;
81 - attached = true;
82 - const update = () => {
83 - const open = !sidebar.hasAttribute('inert');
84 - toolbar.classList.toggle('ext-tb-agent-open', open);
85 - if (!aiBtn) return;
86 - aiBtn.inert = open;
87 - if (open) {
88 - aiBtn.setAttribute('tabindex', '-1');
89 - aiBtn.setAttribute('aria-hidden', 'true');
90 - } else {
91 - aiBtn.removeAttribute('tabindex');
92 - aiBtn.removeAttribute('aria-hidden');
93 - }
94 - };
95 - watch(sidebar, { attributes: true, attributeFilter: ['inert'] }, update);
94 + if (sidebar === watched) return;
95 + watched = sidebar;
96 + inertObserver?.disconnect();
97 + inertObserver = null;
98 + if (!sidebar) {
99 + setOpen(false);
100 + return;
101 + }
102 + const update = () => setOpen(!sidebar.hasAttribute('inert'));
103 + inertObserver = watch(
104 + sidebar,
105 + { attributes: true, attributeFilter: ['inert'] },
106 + update,
107 + );
96 108 update();
97 109 },
98 110 );
99 111 if (document.getElementById(AGENT_SIDEBAR_ID)) observer.takeRecords();