Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function radiate_scripts() {
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'radiate-genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3.1' );

wp_enqueue_script( 'radiate-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
wp_enqueue_script( 'radiate-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20260930', true );

wp_enqueue_script( 'radiate-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );

Expand Down
4 changes: 4 additions & 0 deletions js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ jQuery(document).ready(function() {
var container;
container = document.getElementById( 'site-navigation' );

if ( ! container ) {
return;
}

/**
* Toggles `focus` class to allow submenu access on tablets.
*/
Expand Down
34 changes: 34 additions & 0 deletions tests/e2e/specs/mobile-menu/navigation-missing-container.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { test, expect } from "../../fixtures";

/**
* @area mobile-menu
* @tier fresh
* @guards themegrill/radiate-pro#28
* @source fix/28-navigation-guard 2026-09-30; js/navigation.js
* @why The touch-submenu handler in navigation.js read #site-navigation
* without a null check (the first handler already had one), so any page
* without that element (a child theme whose header.php drops the nav)
* threw "Cannot read properties of null (reading 'querySelectorAll')".
* Removes the <nav> while the page loads to reproduce that header, and
* asserts the page raises no script error.
*/
test("navigation.js raises no error when #site-navigation is missing @fresh @mobile-menu", async ({
page,
}) => {
// Drop the <nav> as the parser adds it, so it is gone before the footer scripts run.
await page.addInitScript(() => {
new MutationObserver(() =>
document.getElementById("site-navigation")?.remove(),
).observe(document, { childList: true, subtree: true });
});

const errors: string[] = [];
page.on("pageerror", (e) => errors.push(e.message));

await page.goto("/");
await page.waitForLoadState("networkidle");

await expect(page.locator("#site-navigation")).toHaveCount(0);
await expect(page.locator("script[src*='navigation']")).toHaveCount(1);
expect(errors, "script errors").toEqual([]);
});
Loading