Skip to content
4 changes: 4 additions & 0 deletions packages/block-library/src/playlist/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ function render_block_core_playlist( $attributes, $content, $block ) {
continue;
}

if ( false === ( $inner_block->parsed_block['attrs']['metadata']['blockVisibility'] ?? null ) ) {
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @yashjawale, This won't work as expected when it's being hidden only on a single viewport or combination. The attributes we would be getting would be something like this. So all of this needs to be consider.

[metadata] => Array
        (
            [blockVisibility] => Array
                (
                    [viewport] => Array
                        (
                            [desktop] => 
                            [mobile] => 
                        )
                )
        )

Also, $inner_block->parsed_block['attrs']['metadata']['blockVisibility'], instead we are having $track_attributes, let's use that for the check instead of getting it again from the innerblock.

Screen.Recording.2026-11-19.at.2.58.46.PM.mov

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also update the test case to include all this scenario.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Updated to use $track_attributes and now handling partially hidden blocks in viewjs script.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also included additional test cases for different scenarios.

$track_id = 'track-' . count( $playlist_tracks );
$playlist_tracks[] = $track_id;

Expand Down
34 changes: 34 additions & 0 deletions phpunit/blocks/render-block-playlist-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,40 @@ public function test_renders_multiple_tracks_in_context() {
$this->assertSame( array( 'track-0', 'track-1', 'track-2' ), $context['tracks'] );
}

/**
* @covers ::render_block_core_playlist
*/
public function test_skips_hidden_tracks() {
$markup = $this->build_playlist_markup(
array(),
array(
array(
'title' => 'Song One',
'src' => 'http://example.com/song1.mp3',
'metadata' => array( 'blockVisibility' => false ),
),
array(
'title' => 'Song Two',
'src' => 'http://example.com/song2.mp3',
),
)
);

$output = do_blocks( $markup );
$p = new WP_HTML_Tag_Processor( $output );
$p->next_tag( 'figure' );
$context = json_decode( $p->get_attribute( 'data-wp-context' ), true );
$this->assertSame( array( 'track-0' ), $context['tracks'] );

$p->next_tag( array( 'class_name' => 'wp-block-playlist-track__button' ) );
$button_context = json_decode( $p->get_attribute( 'data-wp-context' ), true );
$this->assertSame( 'track-0', $button_context['trackId'] );

$state = wp_interactivity_state( 'core/playlist' );
$playlist = reset( $state['playlists'] );
$this->assertSame( 'http://example.com/song2.mp3', $playlist['tracks']['track-0']['url'] );
}

/**
* @covers ::render_block_core_playlist
* @covers ::render_block_core_playlist_track
Expand Down
Loading