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

Refactored PostTextEditor to use React Hook #23897

Merged
merged 8 commits into from
Aug 10, 2020

Conversation

javidalkaruzi
Copy link
Contributor

@javidalkaruzi javidalkaruzi commented Jul 13, 2020

Description

See #22890

Refactored PostTextEditor to use React Hook.

How has this been tested?

Tested using existing unit tests.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@ZebulanStanphill ZebulanStanphill added the [Type] Code Quality Issues or PRs that relate to code quality label Jul 13, 2020
@javidalkaruzi
Copy link
Contributor Author

Hi @ntsekouras. When you have time, could you have another look at this pull request?

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I left some small comments but I tested it and seems to be okay.

My main concern was about the getDerivedStateFromProps change. After consulting @youknowriad he noted these very useful things:

I think the difficulty in this component is due to the fact that we want:

  1. Changes to the blocks (or the content property) in the store to reflect immediately in the editor
  2. Changes in the editor to only change the blocks property when persisting and avoid parsing/serialization on each key strike

Reading the previous code getDerivedStateFromProps it seems to be used to update the state value (the rendered value) of the text editor when external changes happen (prop value changes) but only if we’re not editing the textarea (isdirty state)

I don’t think we should be too strict with keeping the exact same logic, but it’s definitely a fragile component that needs to be tested properly. (Autosaves should not impact editing, clearing the textarea should be possible, switching after edits updates the visual editor, clicking save after edits reflects the edits in the saved content, post is not dirty until we make an edit)

I have tested all the above and it LGTM compared to previous functionality on master.

packages/editor/src/components/post-text-editor/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for your work @javidalkaruzi 👍

@ntsekouras ntsekouras merged commit 39d5086 into WordPress:master Aug 10, 2020
@github-actions github-actions bot added this to the Gutenberg 8.8 milestone Aug 10, 2020
@javidalkaruzi javidalkaruzi deleted the refactor/post-text-editor branch August 10, 2020 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants