-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Delay TinyMCE initialisation to focus #10723
Conversation
b756ec9
to
c6903c1
Compare
Sounds like a safer approach to start with. I have a question: What happens if we try to hit the formatting toolbar before initialization (should we try to trigger the initialization explicitely when we apply a format for instance?) |
The format bar only appears when the editor is initialised. This is not needed though, as we no longer need TinyMCE to apply formats. So we can just show it without MCE being initialised. |
@youknowriad Atm it is needed that the toolbar only initialises after TinyMCE because we're registering shortcuts though TinyMCE. After the format API PR this dependency disappears. |
There are some failing tests. Unsure why those specifically atm. I was actually expecting more failures. |
There is one issue though, try to click on bold, anchor or italic in the middle of |
I was wondering if we can initialize all |
What's that?
That's exactly what #9040 tries to do. I think this approach is a bit less extreme as a first step. |
It doesn't matter anymore since you fixed it :) |
That's not true though. The format toolbar can be visible but the editor not focused (which means TinyMCE not initialized).
Yes, but if I remember properly we used to avoid rerendering the TinyMCE component which means if the content changes externally (by applying a format or something else), it's not refreshed. (Maybe this changed, I didn't follow everything) |
That's not true anymore. See #10723 (comment). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall.
Note: when starting a fresh Gutenberg session, I can feel the latency upon the first focusing of a block. Subsequent focus switches don't lead to any noticeable difference. I think the overall benefit of this PR clearly outweighs this.
ace7b50
to
8ff5fe5
Compare
I added this in 4.2 because I think it's very important to get in beta. At least we can test it a little bit before RC. |
I rebased and pushed the new snapshots for the unit tests as they seemed legit to me. |
In dc5a085 I update the |
Here's the status of the two remaining failures in e2e tests:
Thoughs? |
@@ -108,7 +108,7 @@ export const settings = { | |||
blocks: [ 'core/paragraph' ], | |||
transform: ( { value, citation } ) => { | |||
const paragraphs = []; | |||
if ( value ) { | |||
if ( value && value !== '<p></p>' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recall a discussion about this being non-ideal. Is this a "gotta get worse before getting better" thing? Do we have an issue to track the improvements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #10763.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@youknowriad After the enter "fix", do we still need these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I think we do, that's something else I think. In this case we don't even focus the editor so the value is not changed.
Slightly related PR, which may help alleviate issue here: #10328. It would move Alternative might be to set a class at the end of TinyMCE init and check for that in the e2e test, instead of just the normal TinyMCE classes. Unsure at which stage those are added. |
@iseulde Both these two things seem reasonable to me.
If this fixes, the "delay" issue, it would be awesome.
Seems like a good thing to avoid relying on TinyMCE classnames in the tests. Even If I'd love to get this in ASAP, It does feel like we're not ready there to ship for 4.2 though, so thinking we should punt but make sure we follow-up quickly on it? |
dc5a085
to
783d168
Compare
783d168
to
b5a36c9
Compare
a751275
to
4cc3a13
Compare
So I found a way to fix the issue: Call This fix is a bug actually: A bug happening when you type really really fast. It's also a bug we already have even without this PR which results in inconsistent tests ( So this PR makes this bug more "visible" because we delayed the initialization a bit. But at the moment I'm thinking the advantages of this PR are bigger than this bug and the removal of |
See #6021. I can try to address it as soon as possible after this release. I think it's okay to merge this and work on a fix for enter separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Was there a concern with this? It seemed to me one of the safer steps of this approach in #9040. |
As far as I remember we discussed that we should take one step at the time. We should continue exploring destroying on |
This PR seems to have resulted in this bug: Looking into it now, seems a pretty urgent one to fix. The bug seems to be caused by focus not triggering reliably in the table cells, causing them to not be selected. When a table cell doesn't have selection the onChange does nothing and values in the table aren't updated: gutenberg/packages/block-library/src/table/edit.js Lines 113 to 129 in b7d8fbf
Now I know what the bug is, I'm looking into the exact cause and what the best fix would be. |
My best guess right now is a race condition. Perhaps since Initialisation of TinyMCE now happens onFocus: The editor event isn't always registered in time:
|
I'll have a test of that - I've got a fix here as well that seems to do the trick. Not sure if there's a drawback to using the react event instead of the editor event: |
Yep, looks like #11287 contains exactly the same fix. Confirmed it resolves the issue. |
Yes, it moves the keydown and keyup handlers as well. :) |
This PR appears to have caused #12113. My method of figuring this out was kind of manual — I simply checked out commits to master, and got to this page: https://github.com/WordPress/gutenberg/commits/master?before=01be7ac89b97b76c490d57a15c16466657240770+371 ☝️ "Port nextpage block to the ReactNative mobile app" is the last commit where the Enter key worked perfectly in IE11. The regression as noted in #12113 appears right in the next commit, i.e. this PR. |
Description
This PR is similar to #9040, with the difference that it does not destroy TinyMCE on blur. It merely delays TinyMCE initialisation to the point where the user focuses the field.
How has this been tested?
Screenshots
Types of changes
Checklist: