Repository: rust-lang/mdBook (language: rust)

Issue:
Sidebar opening/closing sometimes doesn't open/close it
### Problem

Sometimes the button to open sidebar seems to do nothing.

### Steps

1. Go to https://doc.rust-lang.org/nightly/reference/type-coercions.html
2. open dev tools
3. click on the hamburger in the left top corner until one of your clicks doesn't make the sidebar open/close
4. observe the fact that `<body>` has incorrect class (`sidebar-visible` is the sidebar is hidden and vice-versa)
5. click on the hamburger again and observe that the classes are still incorrect

### Possible Solution(s)

_No response_

### Notes

The bug is random, so sometimes you need to click a lot before it happens. And sometimes it happens once in about 4 clicks. :shrug:

Also is reproducible in both firefox and chrome.

### Version

I can reproduce with `mdbook v0.4.43`


Discussion / hints:
I've not been able to reproduce this. Does it happen in safe mode, or a fresh profile?
Can you share a screen recording?

Yes, I was able to reproduce this in a empty profile in safe mode.

Screen recording: https://youtu.be/47A2avkPNNs

Fix patch:
diff --git a/src/theme/book.js b/src/theme/book.js
index 178f1e902d..a5c255500c 100644
--- a/src/theme/book.js
+++ b/src/theme/book.js
@@ -449,6 +449,7 @@ function playground_text(playground, hidden = true) {
     var sidebar = document.getElementById("sidebar");
     var sidebarLinks = document.querySelectorAll('#sidebar a');
     var sidebarToggleButton = document.getElementById("sidebar-toggle");
+    var sidebarToggleAnchor = document.getElementById("sidebar-toggle-anchor");
     var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
     var firstContact = null;
 
@@ -475,22 +476,16 @@ function playground_text(playground, hidden = true) {
     }
 
     // Toggle sidebar
-    sidebarToggleButton.addEventListener('click', function sidebarToggle() {
-        if (body.classList.contains("sidebar-hidden")) {
+    sidebarToggleAnchor.addEventListener('change', function sidebarToggle() {
+        if (sidebarToggleAnchor.checked) {
             var current_width = parseInt(
                 document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
             if (current_width < 150) {
                 document.documentElement.style.setProperty('--sidebar-width', '150px');
             }
             showSidebar();
-        } else if (body.classList.contains("sidebar-visible")) {
-            hideSidebar();
         } else {
-            if (getComputedStyle(sidebar)['transform'] === 'none') {
-                hideSidebar();
-            } else {
-                showSidebar();
-            }
+            hideSidebar();
         }
     });
 


Test patch: