Add support for chronological and pagination transitions#2336
Add support for chronological and pagination transitions#2336b1ink0 wants to merge 4 commits intoWordPress:trunkfrom
Conversation
Co-authored-by: Felix Arntz <felixarntz@google.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #2336 +/- ##
==========================================
- Coverage 69.17% 68.75% -0.42%
==========================================
Files 90 90
Lines 7708 7787 +79
==========================================
+ Hits 5332 5354 +22
- Misses 2376 2433 +57
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This might not be necessary. Since admin view transitions have been merged into core, if we do something there it maybe should go into Trac. |
|
@westonruter What do you think about removing the table navigation scope from this PR and handling it in a separate PR instead? It would depend on the implementation of the chronological and pagination transition support that this PR introduces. Since Core currently doesn’t support chronological or pagination transitions, from my perspective it makes sense to first add this functionality to the plugin. Once that’s in place and validated, we can then look at bringing it into Core. |
|
Yes, this PR can be targeted at the frontend only. Any post list table navigation can be considered later, but it seems what is currently in the admin is fine for this. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| oldPageMatches = oldPathname.match( /\/page\/(\d+)\/?$/ ); | ||
| newPageMatches = newPathname.match( /\/page\/(\d+)\/?$/ ); |
There was a problem hiding this comment.
The page slug is configurable via \WP_Rewrite::$pagination_base. That value should be getting exported from PHP to JS for reuse here.
There was a problem hiding this comment.
Pull request overview
Adds support for choosing transition types based on navigation direction/context (chronological and pagination), and exposes new “Chronological and Pagination” options in the plugin’s default transition animation setting.
Changes:
- Introduces JS logic to determine and apply a view-transition “type” (default/chronological/pagination; forwards/backwards) during navigation.
- Extends theme support/config to include additional transition-type-specific animations and attempts to scope CSS to those transition types.
- Adds new settings UI options to enable chronological + pagination transitions for Slide/Swipe/Wipe.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
plugins/view-transitions/js/view-transitions.js |
Adds transition-type detection and assigns the computed type during pageswap/pagereveal. |
plugins/view-transitions/js/types.ts |
Adds a NavigationHistoryEntry type used by the JS transition-type logic. |
plugins/view-transitions/includes/theme.php |
Adds theme support defaults and loads/scopes additional per-type animation CSS and JS config. |
plugins/view-transitions/includes/settings.php |
Adds new “Chronological and Pagination” animation options and maps them to per-type animation settings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| wp_add_inline_style( | ||
| 'plvt-view-transitions', | ||
| plvt_scope_animation_stylesheet_to_transition_type( $additional_animation_stylesheet, $transition_type ) |
There was a problem hiding this comment.
Additional transition stylesheets are added without wrapping them in the same @media (prefers-reduced-motion: no-preference) guard used for the default animation (see line 337). This means chronological/pagination animations may run even when users prefer reduced motion. Wrap the scoped additional CSS in that media query as well.
| wp_add_inline_style( | |
| 'plvt-view-transitions', | |
| plvt_scope_animation_stylesheet_to_transition_type( $additional_animation_stylesheet, $transition_type ) | |
| $scoped_additional_animation_stylesheet = plvt_scope_animation_stylesheet_to_transition_type( $additional_animation_stylesheet, $transition_type ); | |
| $wrapped_additional_animation_stylesheet = "@media (prefers-reduced-motion: no-preference) {\n" . $scoped_additional_animation_stylesheet . "\n}"; | |
| wp_add_inline_style( | |
| 'plvt-view-transitions', | |
| $wrapped_additional_animation_stylesheet |
| $additional_animation_args = isset( $theme_support[ $transition_type . '-animation-args' ] ) ? (array) $theme_support[ $transition_type . '-animation-args' ] : array(); | ||
| $additional_animation_stylesheet = $animation_registry->get_animation_stylesheet( $theme_support[ $transition_type . '-animation' ], $additional_animation_args ); | ||
| if ( '' !== $additional_animation_stylesheet ) { | ||
| wp_add_inline_style( | ||
| 'plvt-view-transitions', | ||
| plvt_scope_animation_stylesheet_to_transition_type( $additional_animation_stylesheet, $transition_type ) | ||
| ); |
There was a problem hiding this comment.
The additional transition animation stylesheet is not passed through plvt_inject_animation_duration(), so chronological/pagination animations will ignore the configured default-animation-duration and instead use the CSS file’s default (typically 1s). Apply the same duration injection used for the default animation to each additional transition stylesheet before scoping/adding it.
| if ( isset( $chronological_pagination_animations[ $args['default-animation'] ] ) ) { | ||
| $base_animation = $chronological_pagination_animations[ $args['default-animation'] ]; | ||
| $args['chronological-forwards-animation'] = $base_animation . '-from-right'; | ||
| $args['chronological-backwards-animation'] = $base_animation . '-from-left'; | ||
| $args['pagination-forwards-animation'] = $base_animation . '-from-right'; | ||
| $args['pagination-backwards-animation'] = $base_animation . '-from-left'; | ||
| } |
There was a problem hiding this comment.
When the special *-chronological-pagination option is selected, $args['default-animation'] remains set to that value, but it is not a registered animation slug/alias in the animation registry. As a result, the default transition falls back to the browser default (fade) instead of the intended slide/swipe/wipe. Map $args['default-animation'] to a real registry alias/slug (e.g. the base animation or a concrete direction) when enabling these special options.
| export type NavigationHistoryEntry = { | ||
| url: string; | ||
| }; |
There was a problem hiding this comment.
While adding NavigationHistoryEntry, note that the runtime config.animations now includes values that aren’t represented in the TS types: plvt_load_view_transitions() can emit false for disabled transition types and currently also emits a targetName field. Update ViewTransitionsConfig.animations / ViewTransitionAnimationConfig accordingly (or remove unused fields from the JS config) so the typings match actual data.
| $additional_transition_types = array( | ||
| 'chronological-forwards', | ||
| 'chronological-backwards', | ||
| 'pagination-forwards', | ||
| 'pagination-backwards', | ||
| ); | ||
|
|
There was a problem hiding this comment.
New behavior is introduced for additional transition types (chronological/pagination) and CSS scoping, but the existing PHP unit tests in plugins/view-transitions/tests/test-theme.php don’t cover any of this (e.g. ensuring disabled types remain disabled, and enabled types enqueue scoped CSS). Please add/update tests around the additional transition type handling to prevent regressions.
| foreach ( $additional_transition_types as $transition_type ) { | ||
| if ( isset( $theme_support[ $transition_type . '-animation' ] ) ) { | ||
| $additional_animation_args = isset( $theme_support[ $transition_type . '-animation-args' ] ) ? (array) $theme_support[ $transition_type . '-animation-args' ] : array(); | ||
| $additional_animation_stylesheet = $animation_registry->get_animation_stylesheet( $theme_support[ $transition_type . '-animation' ], $additional_animation_args ); | ||
| if ( '' !== $additional_animation_stylesheet ) { | ||
| wp_add_inline_style( | ||
| 'plvt-view-transitions', | ||
| plvt_scope_animation_stylesheet_to_transition_type( $additional_animation_stylesheet, $transition_type ) | ||
| ); | ||
| } | ||
|
|
||
| $animations_js_config[ $transition_type ] = array( | ||
| 'useGlobalTransitionNames' => $animation_registry->use_animation_global_transition_names( $theme_support[ $transition_type . '-animation' ], $additional_animation_args ), | ||
| 'usePostTransitionNames' => $animation_registry->use_animation_post_transition_names( $theme_support[ $transition_type . '-animation' ], $additional_animation_args ), | ||
| 'targetName' => isset( $additional_animation_args['target-name'] ) ? $additional_animation_args['target-name'] : '*', // Special argument. | ||
| ); | ||
| } else { | ||
| $animations_js_config[ $transition_type ] = false; | ||
| } | ||
| } |
There was a problem hiding this comment.
In the additional transition types loop, isset( $theme_support[ $transition_type . '-animation' ] ) will be true even when the value is false (default), so disabled transition types get treated as enabled and produce a truthy JS config entry. This causes determineTransitionType() to select e.g. chronological-forwards even when the theme support explicitly disables it. Use a truthiness/type check (e.g., non-empty string) rather than isset() and only build $animations_js_config[$transition_type] when an actual animation alias is configured; otherwise set it to false.
Summary
Fixes #2318
Relevant technical choices
The implementation of this PR is based on WordPress/wordpress-develop#8370.
Other than that, this PR adds new options to the existing Default Transition Animation setting, allowing users to select chronological and pagination transitions for the supported transition types: Slide, Swipe, and Wipe.
TODO:
View transition between paginated list table navigations in the admin dashboardWill be added in a subsequent PR. This PR will focus on the frontend only for now.