Opened 3 weeks ago
Closed 8 days ago
#63613 closed defect (bug) (fixed)
Twenty Twenty-One: menu toggle is not responsive until after "load" event
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.8.2 | Priority: | normal |
Severity: | minor | Version: | 5.6 |
Component: | Bundled Theme | Keywords: | fixed-major dev-reviewed |
Focuses: | javascript | Cc: |
Description
The bundled theme "Twenty Twenty-One" primary navigation / menu toggle is not functional until the load
event triggers on mobile.
This means that the menu might be unusable for multiple seconds.
Can be reproduced by:
- Pick a page with this theme and some heavier resources / images.
- Simulate a mobile browser + slow connection speed.
- Attempt to open the primary navigation between the DOMContentLoaded (DCL) and
"load"
events.
Reading the code for primary-navigation.js
, it looks to me like the only dependency for this script would be that the DOM element for the menu exists.
As of #59316, the script is loading as defer
, meaning that the required DOM elements for the menu will always be ready by the time primary-navigation.js
executes.
I would suggest to improve page responsiveness by removing the event listener completely and initializing the menu immediately when primary-navigation.js
executes.
One alternative considered would be to change from "load" to "DOMContentLoaded", but I don't think that brings any benefits compared to just getting rid of the event listener logic completely.
Attachments (2)
Change History (13)
#1
@
3 weeks ago
- Focuses javascript added
- Summary changed from Bundled theme "twentytwentyone" menu toggle is not responsive until after "load" event to Twenty Twenty-One: menu toggle is not responsive until after "load" event
- Version changed from trunk to 5.6
#2
@
3 weeks ago
I'd love to see the mobile menu reimplemented with dialog
and Invoker Commands to eliminate the JavaScript dependency altogether, at some point. See also: https://github.com/WordPress/gutenberg/pull/69720#issuecomment-2795480829
#3
@
3 weeks ago
- Keywords has-patch added
- Milestone changed from Awaiting Review to 6.9
- Owner set to westonruter
- Status changed from new to accepted
I agree there is no reason to wait for the load
event to initialize the nav menu.
@gernberg thanks for reporting this great issue and providing a patch!
#4
@
3 weeks ago
- Milestone changed from 6.9 to 6.8.2
Since there is another ticket (#60196) for this theme milestoned for the next minor release, I'll milestone this ticket likewise.
#5
@
3 weeks ago
I'm iterating on the patch to opt for the DOMContentLoaded
event. Even though defer
is used, it is possible (although unlikely) that another dependent script could be registered which does not have the defer
strategy, in which case this primary-navigation.js
script would fall back to the blocking loading strategy as well. Since the script is printed in the head
this would result in the nav menu not working at all since the script would be executed before the body
is constructed in the DOM. So using the DOMContentLoaded
will ensure the nav menu is constructed after the the DOM is completely constructed, regardless of the loading strategy.
#7
@
3 weeks ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Re-opening for 6.8.2 consideration.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
3 weeks ago
#9
@
3 weeks ago
- Keywords dev-reviewed added; has-patch removed
We ran into this ticket during today's 6.8.2 bug scrub.
The changeset is pretty straightforward and it makes sense to include such a small change given we already have another issue milestoned to 6.8.2 for TT1.
Marking this as dev-reviewed
(double committer sign-off) so it is ready for a 6.8 backport.
Suggested patch