You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
docs: copy-file buttons bind duplicate click handlers; error dialog is unstyled and leaks its Escape listener #78586
Duplicate handlers. The component's inline script is emitted once per button, and each copy binds a click handler to every button. On a page with N buttons, each button gets N handlers, so one click fetches the file N times.
Unstyled error dialog. The error modal is created by script, so it never gets Astro's scoped class. None of the .error-modal* styles apply.
Leaked Escape listener. The dialog adds a keydown listener to document but only removes it when the dialog is closed with Escape. Closing it with the × button or an outside click leaves the listener attached.
How to reproduce
Open a docs page that has more than one "Copy entire file" button and open the browser Network tab.
Click one button. The file is requested once for each button on the page.
Block that request (for example, with DevTools request blocking) and click again. The error dialog shows with no styling.
Close the dialog with ×. A keydown listener stays on document. Repeat this and the listeners pile up.
Plan
In the inline script, skip buttons that are already bound, for example with a data-copy-handler-attached flag.
Change the .error-modal* selectors to :global(...).
Declare handleEscape before closeModal, and make closeModal remove the listener, so every close path cleans up. handleEscape then only calls closeModal.
Tests:
Count document keydown listeners before the dialog opens, while it is open, and after it closes, for each close path (×, outside click, Escape). The count must return to its starting value.
Check that one click causes one fetch.
Check that the dialog has styling.
Done when
One click causes one fetch.
The error dialog is styled.
The listener count returns to its starting value for all three close paths.
The same commit changes the copy-button tests to fetch from a small real local server (docs/tests/helpers/local-server.ts) instead of mocked routes, and to expect CRLF clipboard text on Windows. It relies on the clipboard Playwright project from the commit in issue 6.
A working version of this fix is on my fork, in branch angelica/docs-playwright-fixes (all changes vs main). With all 10 commits applied, the full docs Playwright suite passes (239/239). Feel free to reuse the commit linked above, or to implement the plan differently.
Activity