File tree 4 files changed +56
-2
lines changed
e2e-tests/plugins/interactive-blocks/router-styles-wrapper
interactivity-router/src/assets
test/e2e/specs/interactivity
4 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 7
7
* @phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable
8
8
*/
9
9
10
+ add_action (
11
+ 'wp_enqueue_scripts ' ,
12
+ function () {
13
+ wp_enqueue_style (
14
+ 'wrapper-styles-from-link ' ,
15
+ plugin_dir_url ( __FILE__ ) . 'style-from-link.css ' ,
16
+ array ()
17
+ );
18
+ }
19
+ );
20
+
10
21
$ wrapper_attributes = get_block_wrapper_attributes ();
11
22
?>
12
23
<div <?php echo $ wrapper_attributes ; ?> >
38
49
<p data-testid="all-from-inline" class="red-from-inline green-from-inline blue-from-inline">All</p>
39
50
</fieldset>
40
51
52
+ <!-- This one should remain green after navigation. -->
53
+ <fieldset>
54
+ <legend>Rule order checker</legend>
55
+ <p data-testid="order-checker" class="order-checker">I should remain green</p>
56
+ </fieldset>
57
+
41
58
<!-- Links to pages with different blocks combination. -->
42
59
<nav data-wp-interactive="test/router-styles">
43
60
<?php foreach ( $ attributes ['links ' ] as $ label => $ link ) : ?>
Original file line number Diff line number Diff line change
1
+ .wp-block-test-router-styles-wrapper .order-checker {
2
+ color : rgb (255 , 0 , 0 );
3
+ }
4
+
5
+ .wp-block-test-router-styles-wrapper .order-checker {
6
+ color : rgb (0 , 255 , 0 );
7
+ }
Original file line number Diff line number Diff line change @@ -41,8 +41,9 @@ const sheetFromLink = async (
41
41
if ( elementSheet ) {
42
42
return getCachedSheet ( sheetId , ( ) => {
43
43
const sheet = new CSSStyleSheet ( ) ;
44
- for ( const { cssText } of elementSheet . cssRules ) {
45
- sheet . insertRule ( withAbsoluteUrls ( cssText , sheetUrl ) ) ;
44
+ for ( let i = 0 ; i < elementSheet . cssRules . length ; i ++ ) {
45
+ const { cssText } = elementSheet . cssRules [ i ] ;
46
+ sheet . insertRule ( withAbsoluteUrls ( cssText , sheetUrl ) , i ) ;
46
47
}
47
48
return Promise . resolve ( sheet ) ;
48
49
} ) ;
Original file line number Diff line number Diff line change @@ -229,4 +229,33 @@ test.describe( 'Router styles', () => {
229
229
await expect ( blue ) . toHaveCSS ( 'color' , COLOR_BLUE ) ;
230
230
await expect ( all ) . toHaveCSS ( 'color' , COLOR_BLUE ) ;
231
231
} ) ;
232
+
233
+ test ( 'should preserve rule order from referenced style sheets' , async ( {
234
+ page,
235
+ } ) => {
236
+ const csn = page . getByTestId ( 'client-side navigation' ) ;
237
+ const orderChecker = page . getByTestId ( 'order-checker' ) ;
238
+
239
+ await expect ( orderChecker ) . toHaveCSS ( 'color' , COLOR_GREEN ) ;
240
+
241
+ await page . getByTestId ( 'link red' ) . click ( ) ;
242
+
243
+ await expect ( csn ) . toBeVisible ( ) ;
244
+ await expect ( orderChecker ) . toHaveCSS ( 'color' , COLOR_GREEN ) ;
245
+
246
+ await page . getByTestId ( 'link green' ) . click ( ) ;
247
+
248
+ await expect ( csn ) . toBeVisible ( ) ;
249
+ await expect ( orderChecker ) . toHaveCSS ( 'color' , COLOR_GREEN ) ;
250
+
251
+ await page . getByTestId ( 'link blue' ) . click ( ) ;
252
+
253
+ await expect ( csn ) . toBeVisible ( ) ;
254
+ await expect ( orderChecker ) . toHaveCSS ( 'color' , COLOR_GREEN ) ;
255
+
256
+ await page . getByTestId ( 'link all' ) . click ( ) ;
257
+
258
+ await expect ( csn ) . toBeVisible ( ) ;
259
+ await expect ( orderChecker ) . toHaveCSS ( 'color' , COLOR_GREEN ) ;
260
+ } ) ;
232
261
} ) ;
You can’t perform that action at this time.
0 commit comments