-
Notifications
You must be signed in to change notification settings - Fork 67
Fix (carousel block): display correct layout and remove frontend console errors #3619
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
Conversation
WalkthroughAdds defensive checks in the carousel’s frontend JS to avoid accessing missing clone elements during scrolling/dragging. Updates block and editor SCSS to extend alignment selectors so carousel-wrapped content respects center/wide/full alignment constraints. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Carousel
participant Clones as Clones (if any)
User->>Carousel: Wheel / Drag / Scroll
Carousel->>Carousel: Check infinite scrolling enabled?
alt Infinite on
Carousel->>Clones: Are clones present?
alt Clones present
Carousel->>Carousel: Compute clone offsets
Carousel->>Carousel: Apply offset-adjusted slide position
else No clones
Note over Carousel: Fallback offsets = 0 / []
Carousel->>Carousel: Slide using fallback offsets
end
else Infinite off
Note over Carousel: Skip clone offset logic
Carousel->>Carousel: Slide normally
end
Carousel-->>User: Updated slide position (no errors)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 Pull request artifacts
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/block/carousel/frontend-carousel.js (1)
329-331: Consider adding defensive guards to other clone accesses for consistency.While the current fixes resolve the reported issue, there are a few other places where
this.clonesis accessed without guards:
- Line 329-331 (swapSlides):
this.clones.slice(startIndex, endIndex)- Line 338-339 (swapSlides):
this.clones[this.clones.length - 1]andthis.clones[0]- Line 663 (onScroll):
[...this.slideEls, ...this.clones]These are likely safe due to the conditional logic around them (only executed when
infiniteScrollis true), but adding similar guards would make the code more robust and consistent with the defensive pattern established in this PR.Example for line 663:
-const slideEls = this.infiniteScroll ? [ ...this.slideEls, ...this.clones ] : this.slideEls +const slideEls = this.infiniteScroll && this.clones?.length ? [ ...this.slideEls, ...this.clones ] : this.slideElsAlso applies to: 338-339, 663-663
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/block/carousel/frontend-carousel.js(2 hunks)src/styles/block.scss(1 hunks)src/styles/editor-block.scss(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: PHP 8.2 and WP 6.7.2
- GitHub Check: PHP 8.2 and WP 6.6.2
- GitHub Check: PHP 7.3 and WP 6.5.5
- GitHub Check: PHP 8.2 and WP 6.5.5
- GitHub Check: PHP 8.2 and WP latest
- GitHub Check: PHP 7.3 and WP latest
🔇 Additional comments (4)
src/styles/block.scss (1)
56-58: LGTM! Carousel alignment handled correctly.The new selector properly extends the alignment rules to accommodate the carousel's extra wrapper structure (
.stk-block-carousel__content-wrapper). The pattern is consistent with the existing selector above it, ensuring carousel content respects the same center/wide/full alignment constraints.src/block/carousel/frontend-carousel.js (2)
495-496: Excellent defensive guards that fix the reported error.These checks directly address the "Cannot read properties of undefined (reading '0')" error by ensuring
this.clonesexists and has elements before accessingthis.clones[0]or calling.map(). The fallback values (0 and []) are appropriate and prevent runtime exceptions.
552-552: LGTM! Consistent defensive pattern.This guard follows the same pattern as lines 495-496, protecting against undefined clones during drag operations.
src/styles/editor-block.scss (1)
106-109: LGTM! Editor alignment rules extended correctly.The new selector (line 109) properly extends the max-width rules to carousel blocks in the editor, mirroring the changes made to
block.scss. This ensures consistent alignment behavior between the frontend and editor for carousel-wrapped content.

fixes #3615, #3616
Summary by CodeRabbit