Fix : Pattern validation and context encoding - #186
Conversation
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Enhances the rtCarousel examples and deprecated saves to support accessible live announcements and additional carousel context fields, while standardizing how data-wp-context is encoded.
Changes:
- Added a screen-reader live region (
role="status",aria-live="polite") to announce slide changes in all carousel patterns. - Expanded
data-wp-contextin patterns with new configuration fields (e.g.,transition,countLabelPattern,announcementPattern,carouselId). - Updated deprecated save implementations to encode
data-wp-contextusing the newencodeContexthelper.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/blocks/carousel/deprecated.tsx | Switches deprecated saves to encodeContext for data-wp-context serialization. |
| examples/patterns/hero-carousel.php | Adds new context fields and a live-region announcer span. |
| examples/patterns/logo-showcase.php | Adds new context fields, enables autoplay in pattern attrs, and adds live-region span. |
| examples/patterns/query-loop.php | Adds new context fields and a live-region announcer span. |
| examples/patterns/terms-query.php | Adds new context fields and a live-region announcer span. |
| examples/patterns/testimonial-carousel.php | Adds new context fields and a live-region announcer span. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…tion for data-wp-context in deprecated block saves
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (2)
examples/patterns/hero-carousel.php:21
- New user-facing strings (
countLabelPattern/announcementPattern) are hard-coded in English insidedata-wp-context. Since these patterns are PHP-based, consider generating those strings via WordPress i18n functions (and then injecting them into the encoded context) so the announcement/labels are localizable. This same issue appears in the other updated pattern files as well.
<div class="wp-block-rt-carousel-carousel alignwide rt-carousel wp-block-carousel-carousel" role="region" aria-roledescription="carousel" aria-label="Hero Carousel" dir="ltr" data-axis="x" data-loop="true" data-wp-interactive="rt-carousel/carousel" data-wp-context="{"transition":"slide","options":{"loop":true,"dragFree":false,"align":"start","containScroll":"trimSnaps","direction":"ltr","axis":"x","slidesToScroll":1},"autoplay":{"delay":5000,"stopOnInteraction":true,"stopOnMouseEnter":false},"isPlaying":true,"timerIterationId":0,"selectedIndex":-1,"scrollSnaps":[],"canScrollPrev":false,"canScrollNext":false,"scrollProgress":0,"slideCount":0,"ariaLabelPattern":"Go to slide %d","countLabelPattern":"Slide {{currentSlide}} of {{totalSlides}}","announcement":"","shouldAnnounce":false,"announcementPattern":"Slide {{currentSlide}} of {{totalSlides}}","autoScroll":false,"useTabs":false,"carouselId":""}" data-wp-init="callbacks.initCarousel" style="--rt-carousel-gap:0px"><!-- wp:rt-carousel/carousel-viewport {"className":"wp-block-carousel-carousel-viewport"} -->
examples/patterns/testimonial-carousel.php:16
- The
data-wp-contextJSON is manually embedded as a very large HTML-entity-escaped string. This is fairly brittle to edit (easy to break quoting/escaping) and makes future context changes harder. Since these are PHP pattern files, consider constructing the context as a PHP array and serializing it withwp_json_encode(), then escaping the attribute (e.g.,esc_attr()) to avoid maintaining"-encoded JSON by hand. (Same applies to the other pattern files updated in this PR.)
<div class="wp-block-rt-carousel-carousel rt-carousel wp-block-carousel-carousel" role="region" aria-roledescription="carousel" aria-label="Customer Testimonials" dir="ltr" data-axis="x" data-loop="true" data-wp-interactive="rt-carousel/carousel" data-wp-context="{"transition":"slide","options":{"loop":true,"dragFree":false,"align":"center","containScroll":"trimSnaps","direction":"ltr","axis":"x","slidesToScroll":1},"autoplay":{"delay":4000,"stopOnInteraction":true,"stopOnMouseEnter":false},"isPlaying":true,"timerIterationId":0,"selectedIndex":-1,"scrollSnaps":[],"canScrollPrev":false,"canScrollNext":false,"scrollProgress":0,"slideCount":0,"ariaLabelPattern":"Go to slide %d","countLabelPattern":"Slide {{currentSlide}} of {{totalSlides}}","announcement":"","shouldAnnounce":false,"announcementPattern":"Slide {{currentSlide}} of {{totalSlides}}","autoScroll":false,"useTabs":false,"carouselId":""}" data-wp-init="callbacks.initCarousel" style="--rt-carousel-gap:32px"><!-- wp:heading {"textAlign":"center","className":"is-style-default","fontSize":"x-large"} -->
This pull request enhances accessibility and adds new configuration options to all carousel pattern examples, as well as improves how context data is encoded in the block's deprecated save functions.
Accessibility improvements:
<span>withrole="status"andaria-live="polite"to announce carousel changes for screen readers in all carousel pattern files (hero-carousel.php,logo-showcase.php,query-loop.php,terms-query.php,testimonial-carousel.php). [1] [2] [3] [4] [5]Configuration and context enhancements:
data-wp-contextattribute in all carousel pattern files to include new fields such astransition,countLabelPattern,announcement,shouldAnnounce,announcementPattern,autoScroll,useTabs, andcarouselId, improving flexibility and accessibility feedback. [1] [2] [3] [4] [5]Code improvements:
src/blocks/carousel/deprecated.tsxto use the newencodeContextfunction for encoding thedata-wp-contextattribute, ensuring consistent and safe context serialization. [1] [2] [3]Summary
Describe the change and why it is needed.
Type of change
Related issue(s)
N/A
What changed
Breaking changes
Does this introduce a breaking change? If yes, describe the impact and migration path below.
Testing
Describe how this was tested.
Test details:
🧪 QA Test Plan:
rtCarouselPattern Validation Fixes📋 Prerequisites & Setup
Run the build script to ensure all compiled JS/CSS files are up-to-date:
cd wp-content/plugins/rt-carousel npm run builddefine( 'WP_DEBUG', true );in yourwp-config.php, ORPlugins > Installed Plugins.Test Case 1: Inserting Patterns from Block Inserter (New Content)
Objective:
Verify that all 5
rtCarouselblock patterns insert into the Block Editor cleanly without triggering "Attempt Block Recovery".Steps:
+(Toggle block inserter) button at the top left of the editor.rtCarousel: Hero CarouselrtCarousel: Testimonial CarouselrtCarousel: Logo ShowcasertCarousel: Query Loop CarouselrtCarousel: Terms Query CarouselExpected Result:
Test Case 2: Post Save & Editor Reload (Persistence Check)
Objective:
Verify that saving a post containing
rtCarouselpatterns retains valid block structure upon reload.Steps:
rtCarouselpatterns into the post (e.g.,Hero Carousel&Logo Showcase).Cmd + RorCtrl + F5) to reload the block editor.Expected Result:
Test Case 3: Frontend Interactivity Verification
Objective:
Verify that pattern blocks render and operate correctly on the public frontend site.
Steps:
>) and Prev (<) buttons as well as navigation dots.Expected Result:
F12 > Console).Test Case 4: Backward Compatibility & Migration Check (Deprecations)
Objective:
Verify that posts created with older versions of
rt-carousel(prior tocountLabelPatternand live-region additions) load smoothly without block errors.Steps:
Ctrl + Shift + Alt + Mor top right 3 dots menu > Code Editor).Expected Result:
SaveV200/SaveV203) matches the legacy markup.Test Case 5: Automated Test Suite
Objective:
Verify all automated JS unit tests pass.
Steps:
Run unit tests from the plugin directory:
cd wp-content/plugins/rt-carousel npm run test:jsExpected Result:
Screenshots / recordings
If applicable, add screenshots or short recordings.
Checklist