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 prioritization of TT1 stylesheet after core theme sanitizer changes #6625

Merged
merged 1 commit into from
Sep 28, 2021

Conversation

westonruter
Copy link
Member

Summary

While working on #6624, I realized that in Twenty Twenty-One the theme stylesheet was getting excluded when a large plugin stylesheet was present earlier in the document. This ended up being a bug with the prioritization logic caused by the core theme sanitizer, where we set the src of the stylesheet to false to make an alias that isn't printed but which we then attach inline styles for the entire stylesheet source with fixes for AMP compatibility.

So this adds a special case for what the plugin uniquely does with the Twenty Twenty-One.

Considering the following plugin being active:

<?php
/**
 * Plugin Name: Add Style To Beginning of Head
 */

add_action('wp_head', function () {
	?>
	<style>
		body:after {
			content: '<?php echo str_repeat( 'a', 28324 ) ?>';
		}
	</style>
	<?php
}, 0);
Before After
Screen Shot 2021-09-28 at 12 29 42 Screen Shot 2021-09-28 at 12 29 57

Notice the Twenty Twenty-One style now has the proper priority and thus it is not selected for exclusion.

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@westonruter westonruter added this to the v2.2 milestone Sep 28, 2021
@github-actions
Copy link
Contributor

Plugin builds for d20eba5 are ready 🛎️!

@westonruter westonruter merged commit 5c97869 into develop Sep 28, 2021
@westonruter westonruter deleted the fix/tt1-stylesheet-prioritization branch September 28, 2021 20:12
@westonruter westonruter changed the title Fix priorization of TT1 stylesheet after core theme sanitizer changes Fix prioritization of TT1 stylesheet after core theme sanitizer changes Sep 30, 2021
@delawski delawski self-assigned this Dec 1, 2021
@delawski
Copy link
Collaborator

delawski commented Dec 1, 2021

QA Passed

With TT1 theme active, after activating a script like this:

<?php
/**
 * Plugin Name: Add Style To Beginning of Head
 */

add_action('wp_head', function () {
	?>
	<style>
		body:after {
			content: '<?php echo str_repeat( 'a', 68324 ) ?>';
		}
	</style>
	<?php
}, 0);

and revalidating one of the URLs, the excessive CSS issue was attributed to the plugin and not to the theme:

Screenshot 2021-12-01 at 16 12 51

✅ The TT1 stylesheet has not been excluded:

Screenshot 2021-12-01 at 16 15 12

Tested on AMP Version 2.2.0-alpha-20211123T020732Z-5405daa

@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes. CSS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants