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

fix/2829: force onChange to be updated with TinyMCE content before merge #3450

Merged
merged 3 commits into from
Nov 15, 2017

Conversation

BoardJames
Copy link

Description

The issue #2829 was caused by the React state not correctly mirroring TinyMCE's state before the merge operation. This was despite the call to onChange directly before calling merge - however onChange was gated on TinyMCE's isDirty and it seems that the isDirty function had not updated to match reality in time (Note: I am told that isDirty functions are really hard to implement efficiently so, while we will tell the TinyMCE team about this, I doubt it is fixable within TinyMCE.). The easiest fix seems to be to force the update of React's state even if the editor doesn't think it has changed which is what I have done here.

How Has This Been Tested?

Manually tested on Firefox and Chrome.

Types of changes

Bug fix.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@BoardJames BoardJames added the [Type] Bug An existing feature does not function as intended label Nov 13, 2017
@BoardJames BoardJames self-assigned this Nov 13, 2017
@codecov
Copy link

codecov bot commented Nov 13, 2017

Codecov Report

Merging #3450 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3450   +/-   ##
=======================================
  Coverage   34.64%   34.64%           
=======================================
  Files         260      260           
  Lines        6737     6737           
  Branches     1219     1219           
=======================================
  Hits         2334     2334           
  Misses       3717     3717           
  Partials      686      686
Impacted Files Coverage Δ
blocks/editable/index.js 10.79% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4312160...d711a1a. Read the comment docs.

onChange() {
if ( ! this.editor.isDirty() ) {
onChange( forced ) {
if ( ! forced && ! this.editor.isDirty() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a comment to explain that isDirty should be enough but due to a bug, we need to force sometimes?

Copy link
Author

Choose a reason for hiding this comment

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

On talking to the TinyMCE team it's more of a known deficiency needed due to efficiency requirements.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This fixes the issue for me. A small comment might be good

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

This fixes it for me. Minor suggestion: renaming forced to shouldForce, feel free to ignore.

@BoardJames
Copy link
Author

Ok I will add a comment and rename forced to shouldForce.

@BoardJames BoardJames merged commit ceb4e69 into master Nov 15, 2017
@BoardJames BoardJames deleted the fix/2829-force-onChange-before-merge branch November 15, 2017 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants