-
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
Block directory: aggressive <script
replacement
#23158
Comments
cc @spacedmonkey :) |
@jdevalk Can you have any idea what you doing on the plugin end that is making this error happen? |
@spacedmonkey from what I could gather:
<script>
wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "http://acceptance.test/wp-json/" ) );
wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "a6392f23cf" );
wp.apiFetch.use( wp.apiFetch.nonceMiddleware );
wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );
wp.apiFetch.nonceEndpoint = "http://acceptance.test/wp-admin/admin-ajax.php?action=rest-nonce";
wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( {"\/":{"body":{"name":"Yoast acceptance WP site","..............."}}}) );
</script>
But it now contains unescaped quotes because As a possible fix: would it be sufficient to run this replace only on the first instance of |
@Djennez The bug is in this line - https://github.com/WordPress/gutenberg/pull/22721/files#diff-ced9b72e7d9418c27bc2fbb5fba83ebaR34 It is a simple fix to replace |
Example
|
@spacedmonkey I think Gutenberg shouldn't be changing the Yoast SEO output at all, to be honest :) |
No clearly, that is a mistake. But it because Yoast is doing something a little weird here. Do you want to work on a fix @Djennez ? |
I don't think what we're doing is weird at all. We have output, like any plugin could have, core is changing it :) seems to me the fault is not on our end. @Djennez is a member of our QA team, I honestly think someone with more insight into the code should fix it :) |
I don't think it's our intention to put our data as json on these pages. That seems to be done by core adding preloaded API responses. @spacedmonkey I'm not comfortable creating a PR for this, because I don't know what the original code's intended purpose is and I don't want to break things 😃 However, I did toy around a bit with possible fixes because I do think I know what needs to happen here.
$tag = preg_replace( '/(^|\n)<script/', "$1" . sprintf( '<script data-handle="%s"', esc_attr( $handle ) ), $tag ); Note that I had to carry over the match to the replacement with I am also not sure how much overhead this regex generates, as there are a lot of |
@spacedmonkey, it should be non-issue once it’s integrated into WordPress core as we will be able to update the code that prints script tags to include this data attribute only when there is src set. For the existing filter, would that help to use preg replace that ensures that both src and the handle are set? |
We need to change to |
@spacedmonkey: I was talking to @ellatrix and @tellyworth about what we need in order to remove the experimental status from the Block Directory (#23378). It's clear that this issue — given the popularity of Yoast, but also given the uncertainty on who else is affected — needs a solution if we want more people to use the Gutenberg plugin to test the Block Directory ahead of its inclusion in Core. Switching to That said, before that, I'm interested in knowing why we need #22721 right now. Don't get me wrong: I think #22703 is a worthwhile achievement that I look forward to, but it doesn't seem like that functionality will be ready before WP 5.5 Beta 1, correct? That's why I'm thinking that reverting #22721 might be the safest and quickest way to unblock @ellatrix and @tellyworth, who I understood to be racing against the clock. |
The fact that we're racing to get something in 5.5 without giving plugins like our own the ability to understand and adapt to this might give us some reason for pause too. |
I don't think there is any blind commitment to get BD in 5.5. When I mentioned racing against the clock, I had the plugin release cycle in mind. The sooner we can get BD out of experimental, the sooner we can get a sense of how well it works for people. If it doesn't, then it won't be in 5.5. |
To make it clear, this change is necessary to work on performance optimizations for the block editor in general. It isn't specific to Block Directory, but in the long run this is where it would bring the most benefits. You can learn about work started by @saramarcondes to lazy load TinyMCE in this comment #2768 (comment). If this is something that is causing so much trouble, we should revert it. In the meantime, we can safely apply the same changes in WordPress core in a proper way (without hooks) which should be enough for the sake of development in a branch. If we decide to land optimizations sooner, we will have to use a bit modified hook that works with existing plugins. |
After looking at this, it didn't seem like using a regular expression was needed, just a more specific match/replace. In #23407 I've matched the full |
Closed by #23407 |
Describe the bug
The introduction of the
data-handle
in #22721 seems to introduce an aggressive search and replace for the script tag. This can break escaped json output by introducing unescaped quotes"
to otherwise valid escaped json data. This can cause the "New post" page to show a white screen and errors in the console:The part the line and column are referring to is (in our case):
Though this is not the only instance.
To reproduce
Steps to reproduce the behavior:
Block experiment
in Gutenberg -> ExperimentsExpected behavior
To be able to use the post editor without errors.
Screenshots
Editor version (please complete the following information):
Desktop (please complete the following information):
Smartphone (please complete the following information):
N/A
The text was updated successfully, but these errors were encountered: