-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking: fix inserter menu no-results issue #41168
Tracking: fix inserter menu no-results issue #41168
Conversation
This PR does not affect the size of JS and CSS bundles shipped to the user's browser. Generated by performance advisor bot at iscalypsofastyet.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a clever PR and a nice use of Slots. I'm mildly concerned that we're relying on experimental features, but I guess you'll have to be conscious of checking the progress of the feature as it moves towards becoming stable in Core.
This PR changes the way to track no-results search result from the Inserter Menu, replacing event delegation by using an Slot, through of the, experimental, inserter menu extension.
I wanted to check - is the purpose of the PR to fix a bug in the original event delegation approach or is this an entirely new approach? If the later, what advantages does this approach provide over the original?
I guess my concern is we may be adding another possible tracking approach, which is halfway between delegation and full Redux which adds further complexity to the tracking system.
I could be wrong...
Testing Results
I'm not entirely clear from the testing instructions whether I need to test against different Gutenberg versions and how to do this. So I decided to go with "stable" and "edge" versions on Dotcom:
I tested on a site stickered with Gutenberg Edge (running Gutenberg 7.9.0-rc.1
) and I encountered the following error:
I then tested on a non-stickered site with 7.8.1
and I got the expected results and no errors:
I think there could be a problem with this on rc-1
. If that is the case, then I would come back to whether this PR is adding additional complexity. If the delegation solution still works then do we need to add this more complex approach?
Thanks for your work here. Your knowledge of Gutenberg is impressive 👍
apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-navigation-menu-search-handler.js
Outdated
Show resolved
Hide resolved
apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-navigation-menu-search-handler.js
Show resolved
Hide resolved
apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-navigation-menu-search-handler.js
Show resolved
Hide resolved
apps/wpcom-block-editor/src/wpcom/features/tracking/wpcom-navigation-menu-search-handler.js
Outdated
Show resolved
Hide resolved
Yeah, right. This is an experimental feature but I hope it could get stable. Anyway, we need to pay attention to changes in it.
Both of them. Event delegation wasn't the issue but DOM inspection. In short, we are realying on a DOM select query to detect the
It means that every time that something changes here, it could affect the tracking data. The slot approach has an API that fits better for our requeriments. The
Event delegation should we replaced by a better one as soon as possible, imo. Relying to the DOM tree, that wasn't designed for it, sounds fragile. In fact, it's failing right now in production for this reason.
Me too :-)
Sorry, my bad. Updating testing instructions.
This is perfect. I've updated the PR adding a debug line to make it easier to test.
I don't think so. We need to check the string
Not enough, tbh. Thanks for your words. |
…gation-menu-search-handler.js Co-Authored-By: Dave Smith <[email protected]>
795008a
to
38564b2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I retested this and for both 7.8.0
(stable) and 7.9.0
("Gutenberg edge") it worked as expected. No more errors.
I'd say this is a good improvement because we're avoiding reliance on the DOM.
I'd like to understand more about whether using Slots is going to be a method of tracking we can use elsewhere to avoid reliance on event delegation. If it is then would you update the FG entry to ensure that it is documented as a preferred option over and above event delegation but below pure Redux? This will ensure folks are aware of it.
My take is that we won't be able to completely drop event delegation in al circumstances so it should remain "as is" - a last resort after all other options for tracking have been exhausted.
Thanks again for the great work here 👍
* once a new version of core is available in dotcom. | ||
*/ | ||
useEffect( () => { | ||
// Skip whether isn't the 7.8.1 version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Skip whether isn't the 7.8.1 version. | |
// Skip when isn't Gutenberg version 7.8.1. |
/** | ||
* Internal dependencies | ||
*/ | ||
import './features/deprecate-coblocks-buttons'; | ||
import './features/fix-block-invalidation-errors'; | ||
import './features/reorder-block-categories'; | ||
import './features/tracking'; | ||
|
||
import InserterMenuTrackingEvent from './features/tracking/wpcom-navigation-menu-search-handler'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be in ./features/tracking
and just imported here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, should we register the plugin there as well then, right?
@getdave slots are a primary extensibility interface that we encourage as it's more idiomatic and easier to test maintain. We aim for slots to be semantic so that there are no weird couplings. For this use case, it makes sense also because I'd imagine you might also want to render helpful guides for certain queries (like "page" returning something about "here's how you can create a new page"). |
This comment makes me more confident about the approach that we did since my concerning point was just that: how reliable is this feature to considering to put it working on prod. |
Changes proposed in this Pull Request
This PR changes the way to track
no-results
search result from theInserter Menu
, replacing event delegation by using an Slot, through of the, experimental, inserter menu extension.Also, it implements a fallback implementation for the
7.8.1
core plugin version, since unfortunately, it has a bug. Basically, thehasItems
parameter is alwaystrue
, so we can't rely on it.So, it checks the plugin version and applies the respective behavior according to this value. We should remove the fallback code once a new version of core-editor ships.
Markable changes
__experimentalInserterMenuExtension
component.Testing instructions
A hard refresh is needed.
Inserter Menu
selectorwpcom_block_picker_search_term
event, as the screenshot shows below.blocks found event
When there aren't blocks there, it also should trigger the
wpcom_block_picker_no_results
event too:blocks not found event
You can see what version is currently running in your site inspecting the debug line:
Fixes #41149