Skip to content

Commit c8c6573

Browse files
authored
Skip CSS minification via PHP
Remove the gutenberg_get_minified_styles function (#29624)
1 parent 8094cd0 commit c8c6573

File tree

2 files changed

+2
-80
lines changed

2 files changed

+2
-80
lines changed

lib/blocks.php

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,10 @@ function gutenberg_maybe_inline_styles() {
222222
// Build an array of styles that have a path defined.
223223
foreach ( $wp_styles->queue as $handle ) {
224224
if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) {
225-
$block_styles = false;
226-
$styles_size = filesize( $wp_styles->registered[ $handle ]->extra['path'] );
227-
228-
// Minify styles and get their minified size if SCRIPT_DEBUG is not enabled.
229-
if ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) {
230-
// Get the styles and minify them by removing comments & whitespace.
231-
$block_styles = gutenberg_get_minified_styles( file_get_contents( $wp_styles->registered[ $handle ]->extra['path'] ) );
232-
// Get the styles size.
233-
$styles_size = strlen( $block_styles );
234-
}
235-
236225
$styles[] = array(
237226
'handle' => $handle,
238227
'path' => $wp_styles->registered[ $handle ]->extra['path'],
239-
'size' => $styles_size,
240-
'css' => $block_styles,
228+
'size' => filesize( $wp_styles->registered[ $handle ]->extra['path'] ),
241229
);
242230
}
243231
}
@@ -268,7 +256,7 @@ function( $a, $b ) {
268256
}
269257

270258
// Get the styles if we don't already have them.
271-
$style['css'] = $style['css'] ? $style['css'] : file_get_contents( $style['path'] );
259+
$style['css'] = file_get_contents( $style['path'] );
272260

273261
// Set `src` to `false` and add styles inline.
274262
$wp_styles->registered[ $style['handle'] ]->src = false;
@@ -281,21 +269,6 @@ function( $a, $b ) {
281269
}
282270
add_action( 'wp_head', 'gutenberg_maybe_inline_styles', 1 );
283271

284-
/**
285-
* Minify styles.
286-
*
287-
* Removes inline comments and whitespace.
288-
*
289-
* @param string $styles The styles to be minified.
290-
* @return string
291-
*/
292-
function gutenberg_get_minified_styles( $styles ) {
293-
$re1 = '(?sx)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|/\\* (?> .*? \\*/ )';
294-
$re2 = '(?six)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')|\\s*+ ; \\s*+ ( } ) \\s*+|\\s*+ ( [*$~^|]?+= | [{};,>~] | !important\\b ) \\s*+|\\s*([+-])\\s*(?=[^}]*{)|( [[(:] ) \\s++|\\s++ ( [])] )|\\s+(:)(?![^\\}]*\\{)|^ \\s++ | \\s++ \\z|(\\s)\\s+';
295-
296-
return preg_replace( array( "%{$re1}%", "%{$re2}%" ), array( '$1', '$1$2$3$4$5$6$7$8' ), $styles );
297-
}
298-
299272
/**
300273
* Complements the implementation of block type `core/social-icon`, whether it
301274
* be provided by core or the plugin, with derived block types for each

phpunit/class-gutenberg-utils-test.php

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -127,55 +127,4 @@ public function test_invalid_parameters_set() {
127127
array( 'a' => 2 )
128128
);
129129
}
130-
131-
/**
132-
* Test gutenberg_get_minified_styles().
133-
*/
134-
public function test_gutenberg_get_minified_styles() {
135-
$cases = array(
136-
array(
137-
'in' => '
138-
/**
139-
* Comment
140-
*/
141-
.foo {
142-
bar: 1;
143-
}
144-
',
145-
'out' => '.foo{bar:1}',
146-
),
147-
array(
148-
'in' => '/* Comment */#foo{content:" "; bar: 0;
149-
}',
150-
'out' => '#foo{content:" ";bar:0}',
151-
),
152-
array(
153-
'in' => '.foo { width: calc(50% - .625em) }',
154-
'out' => '.foo{width:calc(50% - .625em)}', // Preserve spaces inside calc().
155-
),
156-
array(
157-
'in' => '@supports (-webkit-overflow-scrolling: touch) { .foo { background-attachment: scroll; } }',
158-
'out' => '@supports (-webkit-overflow-scrolling:touch){.foo{background-attachment:scroll}}',
159-
),
160-
array(
161-
'in' => '@media (prefers-reduced-motion: reduce) { .foo { background: linear-gradient(-135deg, #7adcb4 0%, #00d082 100%); background-attachment: scroll; animation: components-animate__appear-animation 0.1s cubic-bezier(0, 0, 0.2, 1) 0s; } }',
162-
'out' => '@media (prefers-reduced-motion:reduce){.foo{background:linear-gradient(-135deg,#7adcb4 0%,#00d082 100%);background-attachment:scroll;animation:components-animate__appear-animation 0.1s cubic-bezier(0,0,0.2,1) 0s}}',
163-
),
164-
array(
165-
'in' => '@keyframes components-animate__appear-animation { from { transform: translateY(-2em) scaleY(0) scaleX(0); } to { transform: translateY(0%) scaleY(1) scaleX(1); } }',
166-
'out' => '@keyframes components-animate__appear-animation{from{transform:translateY(-2em) scaleY(0) scaleX(0)}to{transform:translateY(0%) scaleY(1) scaleX(1)}}',
167-
),
168-
array(
169-
'in' => '.selector { --foo: calc( var(--bar, calc(1em - 10px ) ); }',
170-
'out' => '.selector{--foo:calc(var(--bar,calc(1em - 10px))}',
171-
),
172-
);
173-
174-
foreach ( $cases as $case ) {
175-
$this->assertSame(
176-
gutenberg_get_minified_styles( $case['in'] ),
177-
$case['out']
178-
);
179-
}
180-
}
181130
}

0 commit comments

Comments
 (0)