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(carousel): avoid editor crash on empty #2058

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/blocks/carousel/create-swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export default function createSwiper( els, config = {} ) {
},

slideChange() {
if ( this.slides.length < 1 ) {
return; // No slides, no need to do anything.
}
const currentSlide = this.slides[ this.activeIndex ];

deactivateSlide( this.slides[ this.previousIndex ] );
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/carousel/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Edit extends Component {
initializeSwiper( initialSlide ) {
const { latestPosts } = this.props;

if ( latestPosts && latestPosts.length ) {
if ( latestPosts ) {
const { aspectRatio, autoplay, delay, slidesPerView } = this.props.attributes;
const swiperInstance = createSwiper(
{
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/carousel/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function newspack_blocks_render_block_carousel( $attributes ) {

$article_query = new WP_Query( Newspack_Blocks::build_articles_query( $attributes, apply_filters( 'newspack_blocks_block_name', 'newspack-blocks/carousel' ) ) );
if ( false === $article_query->have_posts() ) {
return;
return '';
Copy link
Member Author

Choose a reason for hiding this comment

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

The docs said it return string, so I changed that to ''.

}

$counter = 0;
Expand Down