-
Notifications
You must be signed in to change notification settings - Fork 384
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 CSS parsing by stripping BOM #1611
Conversation
Sometimes this appears in $parsed_selector['tags'], and the logic look for the presence of the tag on the page. This would apply well if it were an HTML tag like div, but @font-face wouldn't appear as an element in an HTML document. So add a conditional to check if the tag is in the 'allowed_at_rules'. Still, this might not be the best solution. Also, it looks like @font-face should appear at the top of the stylesheet.
@kienstra What's the status on this PR? |
Status Hi @hellofromtonya, |
In the Essence Pro theme, the ionicons CSS file has a "\ufeff" character. For some reason, this blocks the style rule from applying on the AMP endpoint, though it doesn't affect the non-AMP endpoint.
Byte Order Mark
wp_enqueue_style(
'ionicons',
'https://unpkg.com/ionicons@4.1.2/dist/css/ionicons.min.css',
);
Strangely, the https://unpkg.com/ionicons@4.1.2/dist/css/ionicons.min.css If you run this snippet inside PhpStorm, it'll show that the character is in the file: preg_match( '/\x{FEFF}/u', wp_remote_get( 'https://unpkg.com/ionicons@4.1.2/dist/css/ionicons.min.css' )['body'] ) So 35c7386 removes this character from the concatenated CSS. I'm not sure this is the right solution, but it has worked so far as a workaround. |
Request For Review Hi @westonruter, Thanks! |
@kienstra I think the issue is fully resolved simply be stripping the BOM before the CSS is parsed. I believe this is a bug with the PHP-CSS-Parser, so I've opened MyIntervals/PHP-CSS-Parser#150. Please take a look to confirm. I'm now seeing the expected @font-face{font-family:"Ionicons";src:url("//unpkg.com/ionicons@4.1.2/dist/fonts/ionicons.eot?v=4.1.1");src:url("//unpkg.com/ionicons@4.1.2/dist/fonts/ionicons.eot?v=4.1.1#iefix") format("embedded-opentype"),url("//unpkg.com/ionicons@4.1.2/dist/fonts/ionicons.woff2?v=4.1.1") format("woff2"),url("//unpkg.com/ionicons@4.1.2/dist/fonts/ionicons.woff?v=4.1.1") format("woff"),url("//unpkg.com/ionicons@4.1.2/dist/fonts/ionicons.ttf?v=4.1.1") format("truetype"),url("//unpkg.com/ionicons@4.1.2/dist/fonts/ionicons.svg?v=4.1.1#Ionicons") format("svg");font-weight:normal;font-style:normal} |
Looks Good, Thanks For Fixing Hi @westonruter, As expected, the Ionicons load on AMP endpoints with Essence Pro: I bumped the cache group locally to force re-processing the stylesheet, but there's of course no need to bump that here. |
Steps to reproduce
wp_enqueue_style()
snippet below in another theme)0
bytes in the<style amp-custom>
:
4. Actual: the stylesheet has 0 bytes...it seems that it's stripped in tree-shaking:This stylesheet is enqueued in the Essence Pro theme's
functions.php
:This PR outputs the
ionicons
@font-face
, as shown in the 'Expected' screenshot. Still, this approach probably needs more thought.This issue doesn't look to exist on other Genesis themes that use an
ionicons
stylesheet. They use a different URL for the stylesheet, and it seems to appear fine.