Skip to content

Code Quality fix within the Sidebar#28840

Open
ahaywood wants to merge 8 commits intoproductionfrom
ad-ced-403-code-quality-sidebar
Open

Code Quality fix within the Sidebar#28840
ahaywood wants to merge 8 commits intoproductionfrom
ad-ced-403-code-quality-sidebar

Conversation

@ahaywood
Copy link
Contributor

@ahaywood ahaywood commented Mar 6, 2026

Summary

Problem

The sidebar search initialization function was being called twice on page load when document.readyState !== "loading":

  1. Once in the conditional else block (line 294)
  2. Once unconditionally immediately after (line 298)

This caused duplicate event listeners to be attached for:

  • Search input events
  • Keyboard shortcuts (Escape and "/" focus)
  • Global search link clicks

Solution

Removed the unconditional initSidebarSearch() call at line 298. The conditional block already handles both scenarios correctly:

  • If DOM is still loading → waits for DOMContentLoaded event
  • If DOM is already loaded → initializes immediately

Impact

  • Prevents duplicate event listener registration
  • Eliminates potential for multiple tracking events per user action
  • Reduces unnecessary function calls on page load

kodster28 and others added 8 commits March 5, 2026 10:23
The problem: When document.readyState !== "loading" (which is the common case after initial page load), the code:
1. Calls initSidebarSearch() at line 294 (in the else block)
2. Immediately calls initSidebarSearch() again at line 298 (unconditionally)

This creates duplicate event listeners for:
- The search input's input event (line 243)
- The search input's keydown event (line 250)
- The global search link's click event (line 258)
- The document's keydown event for "/" shortcut (line 265)

The fix: Remove the unconditional call at line 298. The comment suggests it's for SPA-like navigation, but Astro handles view transitions differently, and this unconditional call is incorrect.
@ahaywood ahaywood requested review from a team and kodster28 as code owners March 6, 2026 23:19
@github-actions github-actions bot added the size/m label Mar 6, 2026
@ahaywood ahaywood requested a review from mvvmm March 6, 2026 23:19
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
*.astro @cloudflare/content-engineering, @kodster28
* @cloudflare/pcx-technical-writing

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants