Repository navigation
Conversation
|
Taking a second look at the code, this could be simply fixed by changing when the global event listeners are executed, setting Inside gutenberg/packages/interactivity-router/src/full-page.ts Lines 23 to 30 in 337e5b0 That would make the global event listeners skip those events. |
|
Great catch! We can rely on that, which would actually it'd be much better since it will not bail out for things like analytics 🙂 Can we close this PR, since that's already how it works? Or perhaps you want to add an end-to-end test to document that case? |
I've created this PR in Gutenberg to fix this. We can continue the discussion there. I'm closing this draft. |
What?
The Interactivity Router uses event delegation to capture
clickandmouseenterevents from all links to callactions.navigateandactions.prefetchrespectively.This PR prevents doing so for link elements that already have directives for that purpose, e.g., links on a Pagination block inside a Query Loop with "Reload full page" disabled.
Why?
To prevent unnecessary or duplicated navigation by giving more precedence to block-specific actions.
How?
It checks the
event.targetelements fordata-wp-on--clickordata-wp-on--mouseenterdirectives (also fordata-wp-on-asyncwith the same events). If they are found, the router actions are not called. Directives with a unique ID are also considered (e.g.,data-wp-on--click--navigation).This is a heuristic we can iterate on later, as these directives could be unrelated to router actions (e.g., CSS animations or analytics callbacks).