-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Editor: Avoid double-encoding sourcecode shortcode content #8325
Conversation
b7d33d6
to
03c11f4
Compare
It works nicely in the It still doesn't work properly when editing only in HTML mode: Steps to reproduce
It looks like it works if we paste the example XML and switch to Visual mode and then back to HTML and refresh. So we might be missing some event callback in the HTML mode. I'm not really sure :) I also think that this PR is a really great improvement, so if that it is really hard to fix then we may deploy it as it is. In that case I'm giving 👍 to 🚢 . Code changes look good, but I must admit I haven't worked with with TinyMCE API for couple of years :) |
I can confirm the issue that @gziolo is seeing above. It seems to be only happening when you have the HTML editor view open and open the post directly via a URL (refresh or otherwise) |
The issue seems to be an intermittent race condition which occurs if the post contents have loaded from the API before TinyMCE has finished loading, resulting in this condition not passing (and therefore the content not being filtered).
Only a handful of entities are replaced. This is a holdover from the original forked plugin, so I'm not sure whether there was a purpose to not include more. Lodash's |
I decided to address the issue by backing out previous changes to filter the content using the TinyMCE plugin and instead always decode entities when assigning the textarea content into state. I think this may have simply been a case of React gotchas related to HTML entities, as demonstrated in the following JSBin: http://jsbin.com/hiquyoxose/edit?html,js,output @gziolo @alisterscott Would you mind taking another look? |
This is great, thanks. I tested all scenarios listed above including editing from posts list, editing directly, refreshing, using both HTML and visual views and couldn't get it to break the code formatting 👍 |
@gziolo It's like playing a game of editor whack-a-mole! Appears this latest issue was a consequence of previous change decoding entities before setting value of textarea. Looking closer, if TinyMCE is initialized using the value of the textarea (decoded), entities need to be replaced before setting to the visual editor, else they appear as DOM nodes. This is unlike other cases where the editor is initialized by content from the REST API, which is already escaped. Kinda confusing, so I added a clarifying comment and improved tests for the plugin along with the fix in f8e1220. |
I did some more testing but couldn't break it; I'll leave that to the master of breaking it: @gziolo I did notice that switching between HTML and Visual makes the editor think there are changes so it gives warnings about leaving the editor when nothing has actually changed. When saving the 'changes' in this situation a new revision isn't created so there aren't actually changes. Any ideas why @aduth? |
@alisterscott I double checked how it work on production, and it seems like it isn't something new. We should open follow up PR, because switching between modes shouldn't trigger any change in the content. I tested again, and everything works perfectly fine. Great job @aduth! 🎉 |
Yeah, it's a known issue related to differences in how the content is formatted between TinyMCE and the textarea fields. It's tracked at #6869 (though the "double prompt" aspect is since resolved), with an attempted unfinished fix at #6880 by @nylen . |
Fixes #1426
This pull request seeks to resolve an issue which sometimes causes content of a
[sourcecode]
shortcode to be double-encoded.This happens because:
initial
value into thesetContent
arguments when assigning content to TinyMCE from a post which is loaded or a post which had been edited previously within the same Calypso sessionTesting Instructions:
Repeat testing instructions from #1426 (comment)
Also verify that code appears correct when switching between editing modes, and when refreshing while viewing either editing mode (specifically verifying that HTML content is decoded upon load).
cc @alisterscott @azaozz