Skip to content

Twenty Nineteen: Fix console error when tapping a # menu link without a submenu - #15334

Open
HrithikDalal wants to merge 1 commit into
WordPress:trunkfrom
HrithikDalal:fix/45903-twentynineteen-menu-console-errors
Open

HrithikDalal wants to merge 1 commit into
WordPress:trunkfrom
HrithikDalal:fix/45903-twentynineteen-menu-console-errors

Conversation

@HrithikDalal

Copy link
Copy Markdown

On touch screens, tapping a primary menu item with a # URL throws TypeError: Cannot read properties of null (reading 'matches') if the item has no submenu. The touchstart handler calls event.target.nextSibling.matches(), and for those items there is no next sibling.

This switches to nextElementSibling and checks it exists first. # items that do have a submenu still open it on tap. The other error in the ticket (event.target.matches is not a function on focus) was fixed in [55970].

Also bumps the script version.

Testing

  1. Activate Twenty Nineteen and add a primary menu with a custom link to # that has no child items.
  2. Turn on device mode in Chrome DevTools (touch), load the front end and tap that menu item.
  3. On trunk you get the TypeError in the console. With this PR there's no error, and a # item with children still opens its submenu.

Trac ticket: https://core.trac.wordpress.org/ticket/45903

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Co-authoring the fix. Reviewed and tested by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

… without a submenu.

On touch screens, tapping a top-level menu item with a `#` URL checks whether the next sibling is the submenu toggle. Items without children have no next sibling, so this threw a TypeError.

Use `nextElementSibling` and check it exists before calling `matches()`.

Follow-up to [55970].

See #45903.
Copilot AI balanced review requested due to automatic review settings November 2, 2026 03:41
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props hrithikd.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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.

🟢 Approval recommended

No active review issues are reported for the touch-navigation guard and accompanying script-version update.

No open issues 🎉

What changed in this PR

This PR fixes Twenty Nineteen’s touch-navigation error when tapping a # menu link without a submenu, while preserving submenu opening for links with children.

Changes:

  • Uses nextElementSibling and checks that it exists before calling matches().
  • Bumps the touch-navigation script version to refresh cached copies.
File Description
src/​wp-content/​themes/​twentynineteen/​js/​touch-keyboard-navigation.js Guards the submenu check against a missing sibling element.
src/​wp-content/​themes/​twentynineteen/​functions.php Updates the script version for cache invalidation.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants