Skip to content

[RNMobile] Story block: added use of mediaFilesBlockReplaceSync bridge method - #18540

Merged
mzorz merged 3 commits into
masterfrom
rnmobile/stories-bridge-deferred-event-clean
Feb 5, 2021
Merged

mzorz merged 3 commits into
masterfrom
rnmobile/stories-bridge-deferred-event-clean

Conversation

@mzorz

@mzorz mzorz commented Jan 25, 2021 •

Copy link
Copy Markdown
Contributor

Changes proposed in this Pull Request:

This PR adds a new bridge method that allows the native side of things learn if a new clientId has been assigned to a newly loaded block that was edited externally.

Basically, when the signal to launch an external editor for Stories is sent, we save the current block's hash on the native side so we know which block we'll need to replace later on, after edits have taken place.

Then, when the Post is again loaded in Gutenberg (before applying edits), Gutenberg gives blocks new clientIds, so we need to take these and figure out which block matches which new edits. At this point, the new bridge method mediaFilesBlockReplaceSync gets called, and helps the native app identify whether this is in effect the block that needs to get replaced with new content or not.

This only affects the native side of things. See related PRs:

Jetpack product discussion

  • n/a

Does this pull request change what data or activity we track or use?

  • no

Testing instructions:

  • Please read the WPAndroid PR linked to above.

Proposed changelog entry for your changes:

  • n/a

@mzorz mzorz added Enhancement Changes to an existing feature — removing, adding, or changing parts of it Touches WP.com Files [Block] Story labels Jan 25, 2021
@matticbot

Copy link
Copy Markdown
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello mzorz! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D55979-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@jetpackbot

jetpackbot commented Jan 25, 2021 •

Copy link
Copy Markdown
Collaborator

Scheduled Jetpack release: February 16, 2021.
Scheduled code freeze: February 8, 2021

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Generated by 🚫 dangerJS against 1ff2ee1

@mzorz

mzorz commented Jan 25, 2021

Copy link
Copy Markdown
Contributor Author

Note for the reviewers: I'm getting the following lint warning:

/home/runner/work/jetpack/jetpack/projects/plugins/jetpack/extensions/blocks/story/edit.native.js
Warning: 57:5 warning React Hook useEffect has a missing dependency: 'mediaFiles'. Either include it or remove the dependency array react-hooks/exhaustive-deps

✖ 1 problem (0 errors, 1 warning)

This is for this part of code:

	// also sync in case we need to replace this block
	useEffect( () => {
		mediaFilesBlockReplaceSync( mediaFiles, clientId );
	}, [ clientId ] );

I think the code is good as is, because I actually intend for the side effect to be run when the clientId changes (as a matter of fact, I could as well just omit the clientId entirely given we know the block will still be running this side effect at first load anyway). But the linter is complaining (and possibly blocking?) the merge with this - leaving this comment here for discussion, I'm inclined to think the code should be fine as is and should be merged but open to suggestions and removing the array entirely if needed.

@mzorz
mzorz requested a review from jd-alexander January 26, 2021 00:04
@jd-alexander

Copy link
Copy Markdown

Note for the reviewers: I'm getting the following lint warning:

/home/runner/work/jetpack/jetpack/projects/plugins/jetpack/extensions/blocks/story/edit.native.js
Warning: 57:5 warning React Hook useEffect has a missing dependency: 'mediaFiles'. Either include it or remove the dependency array react-hooks/exhaustive-deps

✖ 1 problem (0 errors, 1 warning)

This is for this part of code:

	// also sync in case we need to replace this block
	useEffect( () => {
		mediaFilesBlockReplaceSync( mediaFiles, clientId );
	}, [ clientId ] );

I think the code is good as is, because I actually intend for the side effect to be run when the clientId changes (as a matter of fact, I could as well just omit the clientId entirely given we know the block will still be running this side effect at first load anyway). But the linter is complaining (and possibly blocking?) the merge with this - leaving this comment here for discussion, I'm inclined to think the code should be fine as is and should be merged but open to suggestions and removing the array entirely if needed.

Hi @mzorz I haven't looked into this in-depth as yet but I found this resource on Stack Overflow and it has several promising solutions https://stackoverflow.com/questions/55840294/how-to-fix-missing-dependency-warning-when-using-useeffect-react-hook Let me know if you have seen this before so I can determine if I need to dig in more and do some more research on the matter.

@mzorz

mzorz commented Feb 3, 2021

Copy link
Copy Markdown
Contributor Author

Hi @mzorz I haven't looked into this in-depth as yet but I found this resource on Stack Overflow and it has several promising solutions https://stackoverflow.com/questions/55840294/how-to-fix-missing-dependency-warning-when-using-useeffect-react-hook Let me know if you have seen this before so I can determine if I need to dig in more and do some more research on the matter.

Thank you for the pointers @jd-alexander ! I went ahead and added the linter skip directive given AFAIU we know what we're doing - unless the Jetpack crew team thinks otherwise when it gets on their plate to review 👍

@jd-alexander jd-alexander left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for these changes @mzorz LGTM 🚢

@mzorz mzorz added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Team Review Obsolete. Use Needs Review instead. labels Feb 4, 2021
@jeherve jeherve added this to the 9.5 milestone Feb 5, 2021
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Feb 5, 2021
@mzorz
mzorz merged commit 609c992 into master Feb 5, 2021
@mzorz
mzorz deleted the rnmobile/stories-bridge-deferred-event-clean branch February 5, 2021 16:25
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Feb 5, 2021
@jeherve

jeherve commented Feb 25, 2021

Copy link
Copy Markdown
Member

r221667-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Story Enhancement Changes to an existing feature — removing, adding, or changing parts of it Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants