Skip to content

Fix hasUnsupportedBlocks check.#790

Merged
etoledom merged 5 commits intomasterfrom
hotfix/v1.1.2
Mar 28, 2019
Merged

Fix hasUnsupportedBlocks check.#790
etoledom merged 5 commits intomasterfrom
hotfix/v1.1.2

Conversation

@etoledom
Copy link
Copy Markdown
Contributor

This PR fixes a problem where the hasUnsupportedBlocks sent to the native apps was always false.

The reason is that after this refactor, the block list is not available on AppContainer until the "editor is ready", thus this.props.blocks will always be empty on componentDidMount.

The solution is to wait for props.isReady to be true to check and send hasUnsupportedBlocks with the appropriate value.

Note: componentDidUpdate is the best place I found to do this check, but sending hasUnsupportedBlocks as part of the editorDidMount (from componentDidUpdate) feels not optimal. I'm open to suggestions (as always). But as a hotfix, it works.

  • I'd rename the editorDidMount message sent to native, but I'd prefer to do it on a separate PR on develop, since it will require native code on both platforms to be modified.
  • Other possibility is to split editorDidMount and create a separate message specific for hasUnsupportedBlocks.

Note 2: After it's approved, I'll create a new JS Bundle before merging.

To test:

  • Run the project from Xcode (open ios/gutenberg.xcodeproj).
  • Check in the Xcode console that the message gutenbergDidMount(hasUnsupportedBlocks: true) is written.
  • Run this branch on WPAndroid.
  • Check that the proper hasUnsupportedBlocks is received.

@etoledom etoledom self-assigned this Mar 27, 2019
@etoledom etoledom requested review from Tug and hypest March 27, 2019 22:15
@etoledom
Copy link
Copy Markdown
Contributor Author

cc @koke - This should fix what I mentioned on #643 (review)

Copy link
Copy Markdown
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

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

LGTM!

✅ Check in the Xcode console that the message gutenbergDidMount(hasUnsupportedBlocks: true) is written.
✅ Check that the proper hasUnsupportedBlocks is received in WPAndroid

componentDidUpdate is the best place I found to do this check, but sending hasUnsupportedBlocks as part of the editorDidMount (from componentDidUpdate) feels not optimal.

I guess I wouldn't worry too much about his since the "editor mount" can have various meanings since it's not a proper React lifecycle method name. We can leave it as is until we trip on it and then rename.

@etoledom
Copy link
Copy Markdown
Contributor Author

Thank you @hypest !
I'll push the new bundles to create the WP Apps PRs.

@koke
Copy link
Copy Markdown
Member

koke commented Mar 28, 2019

I'm fine with this as a hotfix, but also not super happy with the naming of things. I think it's OK if we need to abandon the didMount naming and have an editorReady event that we ensure fires just once as soon as the editor is initially set up.

I am concerned that componentDidUpdate is not called in the initial render, so the event won't be triggered unless the props/state change. With this refactor I understand this is happening right now (otherwise the code on componentDidMount would still work), but it doesn't seem future-proof.

What if a future refactor changes the behaviour again and everything is ready on componentDidMount, and the component doesn't update until the user makes a change (which sounds like the desired behaviour)? In that case, the user could open a post, the editor_session_start even wouldn't get triggered right away, and they could potentially switch to classic/html without having triggered the session start.

@koke koke mentioned this pull request Mar 28, 2019
@etoledom
Copy link
Copy Markdown
Contributor Author

I agree!
For those reasons I'd prefer to keep sending the editorDidMount event from the componentDidMount component lifecycle, and separate hasUnsupportedBlocks to be more flexible on when to emit that event. Whenever we emit it, we need to be sure that props.isReady == true, and to be sure we are sending it just once.

@etoledom etoledom merged commit acd6854 into master Mar 28, 2019
@hypest
Copy link
Copy Markdown
Contributor

hypest commented Mar 28, 2019

I'd prefer if we don't expose/bubble RN/React lifecycle events to the parents, as it makes it hard to understand what the intention is by looking at the interface. Instead, the interface to the parents should be as close as possible to certain functionalities.

We already do various things in wpandroid based on the editorDidMount event (sending analytics, hiding a progress bar, focusing the title bar and initiate a new media block), which means we already overloaded the initial intent (signal the presence of unsupported blocks) so, separating the events into 2 makes sense. Since this PR is about a hotfix of an important regression though, it makes sense to keep it short and quick as is, and handle the events splitting in a separate PR.

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Mar 28, 2019

Ah oh, by the way, great job adding a test for the regression @etoledom ! 👏

@etoledom etoledom deleted the hotfix/v1.1.2 branch April 25, 2019 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants