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

Send changed to the native bridge if html changed since last time #242

Merged
merged 3 commits into from Nov 15, 2018

Conversation

Tug
Copy link
Contributor

@Tug Tug commented Nov 15, 2018

#226 caused a regression in the js to native bridge. We're not sending the changed parameter anymore when calling provideToNative_Html. This PR fixes it.

Note: it's currently causing a problem in wordpress-mobile/WordPress-iOS#10461 when you tap "Publish" on parent app it crashes.

@Tug Tug self-assigned this Nov 15, 2018
@Tug Tug requested a review from pinarol November 15, 2018 17:52
@pinarol
Copy link
Contributor

pinarol commented Nov 15, 2018

cc @hypest

Copy link
Contributor

@pinarol pinarol left a comment

Choose a reason for hiding this comment

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

Tested with the WPiOS app and working OK. 👍

@Tug Tug merged commit 66f244b into master Nov 15, 2018
@Tug Tug deleted the fix/bridge branch November 15, 2018 18:38
@hypest
Copy link
Contributor

hypest commented Nov 15, 2018

If I understand the code correctly, it detects the change compared to the last time it was sent up to the parent. I think that's not the intended logic and it's not what it was in place before.

Because it seems that parsing and then serializing the blocks again does not produce the original html, we need to check if the html we pass back to the parent is the same as the html originally passed down to the RN app. The previous solution was keeping the md5 hash of the original html so to compare it with the current and report "changed" or not.

I tested with the wpandroid integration and indeed, the post is reported as "changed" with the current PR (master by now), I'm guessing because lastHtmlSent starts undefined anyway? Let's create a new PR to fix this by comparing to the original html passed down. WDYT?

@pinarol
Copy link
Contributor

pinarol commented Nov 16, 2018

That's right @hypest I missed this because this flag is not utilized in iOS side while closing the editor. There's an internal logic to decide if content has changed so it is not using the Javascript flag while closing. I am just setting the last version of html and it is taking care of the rest(to give more detail, it creates a revision on opening and compares the new content with that revision), if there's no change it just closes the editor without extra prompts.

The only use case of such a flag on iOS side is enabling/disabling the Publish button. Currently the publish button is always active because we don't have the capability yet on the Gutenberg side that informs us the every editing action unlike Aztec. So it turns out currently I am not actually utilizing that flag. 🤔 (I mean I am using it but it is ignored.)

@pinarol
Copy link
Contributor

pinarol commented Nov 16, 2018

btw this PR #243 makes it possible to get a more decent test result, it is not merged to master yet so I did a temp merge to my own branch directly from that PR.

@hypest
Copy link
Contributor

hypest commented Nov 16, 2018

There's an internal logic to decide if content has changed so it is not using the Javascript flag while closing

Where does that logic live? Is it the parent app, the bridge or the RN layer?

Since what we're dealing with here are involuntary changes by the editing component itself, the logic needs to live in the RN side and the initial "snapshot" to compare against needs to take into account those self-inflicted changed. That's why the original implementation needed to serialize the blocks again before it computed the "initial hash". See here in the original PR: https://github.com/wordpress-mobile/gutenberg-mobile/pull/225/files#diff-969b5637d99e6ae15745bc85e7f3519fR16

cc @Tug as this relates to what to consider "initial html".

@pinarol
Copy link
Contributor

pinarol commented Nov 16, 2018

Where does that logic live? Is it the parent app, the bridge or the RN layer?

@hypest In the parent iOS app. If you want to dig more into it you can check out the class AbstractPost, there's a hasLocalChanges method in it. It simply compares the latest content with its original content and returns the result, this has always been this way. Whenever user makes a change on aztec editor the lates content in the post is updated, "hasLocalChanges" is computed where necessary.

So what happens is:

  • We open the Gutenberg editor with the original content
  • Tap close button
  • Request html from gutenberg side
  • Gutenberg html arrives with a callback, we update the latest content in the AbstractPost
  • Proceed with close operation
  • Close operation inside checks the ”hasLocalChanges” flag in the post and and does what’s necessary, if it is true for example it prompts the user if they want to keep/discard changes.

There are huge differences between iOS and Android apps both in terms of user experience and implementation. So I am having hard time saying both sides need the exact same flag. I think we can move this conversation to the #mobile-gutenberg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants