Skip to content
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

Annotations: Add end-to-end tests for annotations API #12186

Closed
wants to merge 1 commit into from

Conversation

atimmer
Copy link
Member

@atimmer atimmer commented Nov 21, 2018

Description

After introducing prepareEditableTree we would rerender all RichText instances when typing in one RichText instance. Noted here: #11595 (comment). This was partly fixed in #12161. This PR fixes it completely and adds e2e tests to ensure that this won't happen again in the future.

How has this been tested?

Using the e2e tests and applying annotations using Yoast SEO.

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@atimmer atimmer changed the title Fix performance of annotations and the christmas light effect. Fix performance of annotations and the React christmas light effect. Nov 21, 2018
@IreneStr
Copy link
Member

I just tested this with the Yoast annotations, and it works like a charm 😄

*
* @return {Function} The onChangeEditableValue function.
*/
const createOnChangeEditableValue = memize( ( removeAnnotation, updateAnnotationRange, annotations ) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the memoization is not necessary as it's an onChange handler? And withDispatch in general don't need memoization?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not go to withDispatch, but it goes to the onChangeEditableValue prop in the HOC for RichText. I don't think we can 'route' this through withDispatch because withDispatch only accepts functions in the returned object.

It could be that this is not necessary to prevent re-renders to TinyMCE, but I do think it's necessary to prevent re-renders to RichText.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion against this change. I'd like us to move away from systemic memoization for performance optimization in the formats but handle these in the framework instead but I don't see this as a blocker for this PR.

// If we always specify this the selection will go to this RichText
// regardless whether is is actually the currently selected one.
// So check if this RichText is the selected one.
if ( this.props.isSelected ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iseulde Any thoughts about this particular change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've put some extra context about this change in the commit: 50057fc.

@atimmer atimmer added this to the WordPress 5.0.x Follow Ups milestone Nov 26, 2018
@omarreiss omarreiss added [Type] Performance Related to performance efforts [Feature] Annotations Adding annotation functionality labels Dec 6, 2018
@mtias mtias modified the milestones: WordPress 5.0.1, 4.7 Dec 6, 2018
@ellatrix
Copy link
Member

ellatrix commented Dec 8, 2018

I'll try to look at this today or tomorrow.

@ellatrix
Copy link
Member

ellatrix commented Dec 9, 2018

I'm fine with this as a temporary solution since it won't impact the default experience, but we really need to look at moving memoization into the API and making sure it gets invalidated when needed. See #12161 (comment).

@atimmer atimmer force-pushed the fix/improve-annotations-performance branch 3 times, most recently from 3b2aacb to cd76538 Compare December 9, 2018 18:26
const rerendersAfterAnnotating = await getRerenderCount();

// Typing in the second block should not trigger a re-render in the first block.
expect( rerendersAfterAnnotating ).toEqual( rerendersBeforeAnnotating + ANNOTATION_RERENDERS );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be written as toBe.

const FORMAT_NAME = 'rerender/counter';

function countRerender( formats, text ) {
if ( text.startsWith( 'RerenderCounter' ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we create a separate format type for these tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming it is already separate because it's called rerender/counter. So why do we have this check?

return formats;
}

domReady( () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a format being registered when the DOM is ready? What does the DOM have to do with this?


domReady( () => {
registerFormatType( FORMAT_NAME, {
name: FORMAT_NAME,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this attribute is not needed?


function countRerender( formats, text ) {
if ( text.startsWith( 'RerenderCounter' ) ) {
window.annotationsCountingRerenders++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange to me that this is being set in a separate file. I have no idea from looking at the other file where it's coming from. Maybe better to more this registration to the test cases?

@@ -15,9 +20,9 @@ const addAnnotationClassName = ( OriginalComponent ) => {
const annotations = select( 'core/annotations' ).__experimentalGetAnnotationsForBlock( clientId );

return {
className: annotations.map( ( annotation ) => {
className: uniq( annotations.map( ( annotation ) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what reason do we suddenly need to consider uniqueness of annotations classnames?

I'd not consider this a blocker, in that there ought not be any harm in deduplicating classes, but it'd be better if we could not apply the logic if we're not expecting it to be necessary (or at least have some confidence in whether it is or is not necessary).

@@ -15,6 +15,9 @@
var registerPlugin = wp.plugins.registerPlugin;
var PluginSidebar = wp.editPost.PluginSidebar;
var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
var applyFormat = wp.richText.applyFormat;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wp-rich-text must be defined as a dependency of this script.

@@ -15,6 +15,9 @@
var registerPlugin = wp.plugins.registerPlugin;
var PluginSidebar = wp.editPost.PluginSidebar;
var PluginSidebarMoreMenuItem = wp.editPost.PluginSidebarMoreMenuItem;
var applyFormat = wp.richText.applyFormat;
var registerFormatType = wp.richText.registerFormatType;
var domReady = wp.domReady;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wp-dom-ready must be defined as a dependency of this script.

@aduth
Copy link
Member

aduth commented Dec 10, 2018

Separate targeted pull requests were made to extract changes into #12737 and #12741 . This branch can be rebased to address the remaining item concerning end-to-end test changes.

We should also consider (separately):

  • Further refactoring to className extension
    • Is uniq necessary or desirable?
    • Do we need to override props at all if there are no active annotations?
    • Should we consider @wordpress/token-list for generating a string from an array of class names?
  • Unit tests covering packages/annotations/src/block/index.js

The test will check that one `RichText` doesn't rerender when typing
in a different `RichText`.
@atimmer atimmer force-pushed the fix/improve-annotations-performance branch from cd76538 to 222f942 Compare December 18, 2018 09:30
@youknowriad youknowriad modified the milestones: 4.8, 4.9 Dec 19, 2018
@aduth aduth changed the title Fix performance of annotations and the React christmas light effect. Annotations: Add end-to-end tests for annotations API Jan 4, 2019
@aduth aduth added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. and removed [Type] Performance Related to performance efforts labels Jan 4, 2019
@gziolo
Copy link
Member

gziolo commented Feb 5, 2019

@atimmer it looks like there are still some comments that need to be addressed. This branch also got stale because of other changes applied in master. Do you plan to continue working on it? It would be great to have better test coverage for annotations as it isn't used by Gutenberg itself.

@gziolo gziolo added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Feb 5, 2019
@atimmer
Copy link
Member Author

atimmer commented Feb 6, 2019

@gziolo This is currently not a focus. The work is still valuable, but I have no short-term plans to actively pursue this to completion.

@gziolo
Copy link
Member

gziolo commented Feb 6, 2019

Yes, it seems like a good addition, so if someone wants to move it forward, I assume it would be nice to help land this PR :)

@gziolo gziolo removed this from the 5.1 (Gutenberg) milestone Feb 7, 2019
@gziolo
Copy link
Member

gziolo commented Mar 5, 2019

It doesn't look like it is going to be worked on in the upcoming weeks. Let's close it for now. We can always reopen, refresh and land when it's more pressing. Thanks for your initial work on this PR.

@gziolo gziolo closed this Mar 5, 2019
@gziolo gziolo deleted the fix/improve-annotations-performance branch March 5, 2019 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Annotations Adding annotation functionality [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants