Skip to content

Fix - navigation.js null errors on pages without the theme header - #147

Open
rajatgautam755421 wants to merge 1 commit into
developfrom
fix/85-navigation-null-guards
Open

rajatgautam755421 wants to merge 1 commit into
developfrom
fix/85-navigation-null-guards

Conversation

@rajatgautam755421

Copy link
Copy Markdown

Changes proposed in this Pull Request:

Free-theme part of themegrill/spacious-pro#85. Pro PR: themegrill/spacious-pro#197.

js/navigation.js assumes the theme header is on the page. On wp-admin > Widgets every block preview iframe loads the theme's front-end scripts but has no header, so it throws Cannot read properties of null (reading 'querySelectorAll') at navigation.js:80, once per preview (11 on a default setup).

This adds two guards where the header was used unchecked:

  • Tablet submenu touch handler: return if #site-navigation is missing.
  • "Keep menu items on one line" ready handler: also return when #site-navigation is missing (the widths above it already fall back to 0).

The free version needs fewer guards than Pro: its out-of-viewport submenu code uses jQuery only, and its ready handler already guards the width lookups.

Effect on existing sites

  • Pages with the theme header: no change. The guards only return where the old code would have thrown.
  • Pages without it (Widgets block previews, templates or plugins that replace the header): the script now stops quietly instead of throwing.

How to test the changes in this Pull Request:

  1. Open wp-admin > Widgets and wait for the block previews to load.
  2. Before: the console shows TypeError: Cannot read properties of null (reading 'querySelectorAll') at navigation.js:80, once per preview. After: none.
  3. On the front end, check the menu still works, including the mobile menu toggle below 768px.

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (modification of the currently available functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you successfully ran tests with your changes locally? Verified manually in the browser with Playwright (details below). No automated test was added.
  • Have you updated the documentation accordingly?

Changelog entry

Fix - JavaScript errors from navigation.js on the Widgets screen and other pages without the theme header.

Verification (WordPress 7.1.2, theme 1.9.12)

Check Before After
Widgets screen, navigation.js errors (11 previews loading the free theme's script) 11 0
Widgets screen, other errors 1 core (core/interface already registered) same
Front end 1366px: toggle handler set, no console errors yes yes
Front end 375px: menu toggle opens/closes working working, no console errors
  • JSHint (repo .jshintrc): same messages as develop, none added.

🤖 Generated with Claude Code

…dgets screen previews)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rajatgautam755421 rajatgautam755421 self-assigned this Sep 25, 2026
@tg-autopilot
tg-autopilot requested a lite review from Copilot September 25, 2026 08:13
@github-actions

Copy link
Copy Markdown

QA suite — refused, no regression spec

This PR changes product source but adds no spec, so the suite was
refused before booting WordPress — running it just to report the same
thing at the end costs runner minutes for nothing. Run
/claudegrill:verify-fix locally and let write-spec add the guard
to this branch, then push again.

Source files changed with no matching spec
js/navigation.js

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The guards address the reported errors while preserving existing navigation behavior.

Review effort: Lite
Findings: None

What changed in this PR

Fixes null errors in navigation.js on pages without the theme header.

Changes:

  • Guards tablet submenu initialization when #site-navigation is absent.
  • Guards one-line menu setup against missing navigation markup.
File Description
js/​navigation.js Adds null checks for header-dependent navigation logic.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

2 participants