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

Rich Text: Remove componentDidUpdate deep equality conditions #7648

Closed
wants to merge 2 commits into from

Conversation

aduth
Copy link
Member

@aduth aduth commented Jun 30, 2018

This pull request seeks to simplify the RichText component, removing two deep equality conditions performed on each component update. These were introduced in #5100 to resolve an issue described in #5081. The issue is in-fact related to forceful focusing caused by updateContent, which is slated to be separately resolved by #7620 in checking that the editor has focus when restoring the stored bookmark when setting content.

Thus, this pull request is considered blocked by #7620. There is an added end-to-end test here which fails as expected from the steps described in #5081, and are expected to pass once #7620 is merged and this pull request rebased.

Speaking more broadly, it is an issue that we cannot trust that content has changed unexpectedly without a deep equality check. We should not need to rely on these conditions. Strict equality should be sufficient.

Testing instructions:

Repeat testing instructions from #5100.

Ensure end-to-end tests pass:

npm run test-e2e

@aduth aduth added [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Performance Related to performance efforts labels Jun 30, 2018
// This fixes issues in multi richText blocks like quotes when moving the focus between
// the different editables.
! isEqual( this.props.value, prevProps.value ) &&
! isEqual( this.props.value, this.savedContent )
Copy link
Member

Choose a reason for hiding this comment

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

Would there be any point in keeping the check to log a warning in dev mode if values are the same but an update is triggered?

Copy link
Member Author

Choose a reason for hiding this comment

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

Would there be any point in keeping the check to log a warning in dev mode if values are the same but an update is triggered?

I love that idea!

Copy link
Member Author

Choose a reason for hiding this comment

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

Scolding added in 320c96e7108fbc6fd1e536656ee2304ae32ece49

@ellatrix
Copy link
Member

ellatrix commented Jul 3, 2018

Looks good to me after #7620. I guess this would still require a change in the quote blocks (eventually)? Looked at this as will as part of the quote nesting PR #6520, which we'll probably wait the merge for a while.

@aduth
Copy link
Member Author

aduth commented Jul 3, 2018

I usually add something like const { warn, log, error, ... } = window.console to browser dependencies to avoid the eslint comment and be explicit. Up to you though :)

Mentioned elsewhere, while I can get on board with this for things which are proper browser dependencies, I don't think console qualifies here, as it's also available in Node and Web Workers, neither of which are "browsers".

The Console object can be accessed from any global object.

https://developer.mozilla.org/en-US/docs/Web/API/Console

Could even be argued that targeting window.console makes for needless tangling dependency to the DOM.

@aduth aduth force-pushed the remove/rich-text-did-update-deep-equal branch from 320c96e to 59cfb2c Compare July 3, 2018 17:53
@aduth
Copy link
Member Author

aduth commented Jul 3, 2018

Rebased to account for the since-merged #7620 blocker.

I'm finding there's an unexpected failing end-to-end test now though, in the multi-selection suite. I can sometimes reproduce in the browser, but it's mostly to do with where the click occurs (e.g. in sibling inserter space, which is technically outside of the event scope of the onPointerDown in BlockListBlock).

It also led me to find that our quote block, with it's Array#map, passes a new value to RichText on every render:

value={ toRichTextValue( value ) }

(Made evidenced by our wonderful new scolding logging)

@aduth aduth force-pushed the remove/rich-text-did-update-deep-equal branch from 59cfb2c to ce4cb90 Compare July 23, 2018 18:51
@aduth
Copy link
Member Author

aduth commented Jul 23, 2018

Rebased to keep this one fresh. It's something I'd still like to move forward on. There's two failing end-to-end tests either, neither of which I'm yet certain the cause.

  1. Splitting / Merging

This one is intermittent. I'm wondering if it could perhaps be an issue of TinyMCE initialization time. I had seen this at one point earlier in authoring end-to-end tests (#6467, which included some hacks/workarounds like waitUntilNthParagraphActive)

splitting and merging blocks › Should merge into inline boundary position

    expect(value).toMatchSnapshot()

    Received value does not match stored snapshot "splitting and merging blocks Should merge into inline boundary position 1".

    - Snapshot
    + Received

      "<!-- wp:paragraph -->
    - <p>Bar</p>
    + <p><strong>FBar</strong></p>
      <!-- /wp:paragraph -->"

      69 | 		await page.keyboard.type( 'Bar' );
      70 | 
    > 71 | 		expect( await getEditedPostContent() ).toMatchSnapshot();
         | 		                                       ^
      72 | 	} );
      73 | } );
      74 | 

      at Object._callee3$ (test/e2e/specs/splitting-merging.test.js:71:42)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
      at asyncGeneratorStep (test/e2e/specs/splitting-merging.test.js:11:103)
      at _next (test/e2e/specs/splitting-merging.test.js:13:194)
  1. Multi-block selection
Multi-block selection › Should select/unselect multiple blocks

    expect(received).toEqual(expected)

    Expected value to equal:
      StringContaining "is-multi-selected"
    Received:
      "editor-block-list__block is-selected"

      29 | 				const className = await page.$eval( selector, ( element ) => element.className );
      30 | 				if ( areMultiSelected ) {
    > 31 | 					expect( className ).toEqual( expect.stringContaining( multiSelectedCssClass ) );
         | 					                    ^
      32 | 				} else {
      33 | 					expect( className ).not.toEqual( expect.stringContaining( multiSelectedCssClass ) );
      34 | 				}

      at _callee2$ (test/e2e/specs/multi-block-selection.test.js:31:26)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
      at asyncGeneratorStep (test/e2e/specs/multi-block-selection.test.js:17:103)
      at _next (test/e2e/specs/multi-block-selection.test.js:19:194)

@gziolo
Copy link
Member

gziolo commented Aug 13, 2018

I'm not sure why I put it API freeze. It doesn't look like it touches public API. Anyways, it needs another rebase. When you do it please include in the milestone :)

@aduth
Copy link
Member Author

aduth commented Nov 27, 2018

Superseded by #7890

@aduth aduth closed this Nov 27, 2018
@aduth aduth deleted the remove/rich-text-did-update-deep-equal branch January 25, 2019 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants