Skip to content

View Transitions: Ensure animation duration defaults to 1000ms when i… - #2706

Open
sonali195 wants to merge 3 commits into
WordPress:trunkfrom
sonali195:fix/view-transitions-animation-duration-fallback
Open

sonali195 wants to merge 3 commits into
WordPress:trunkfrom
sonali195:fix/view-transitions-animation-duration-fallback

Conversation

@sonali195

Copy link
Copy Markdown

Summary

In the View Transitions plugin, the plvt_inject_animation_duration() docblock explicitly states:

@param int $animation_duration Transition duration in milliseconds. Will be converted to seconds. Defaults to 1000ms if invalid.

However, the function was calculating $seconds = $animation_duration / 1000; directly without verifying whether $animation_duration <= 0. If an invalid or zero duration was passed, it would generate a 0s or negative duration rule in CSS instead of defaulting to the documented 1000ms.

This pull request:

  1. Implements the fallback in plvt_inject_animation_duration() so that any duration <= 0 defaults to 1000ms.
  2. Adds comprehensive PHPUnit test coverage for plvt_inject_animation_duration(), plvt_sanitize_view_transitions_theme_support(), and plvt_register_view_transition_animations().

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Unit tests

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation: No.
  • I have updated the documentation accordingly: N/A.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sonali195 <sonaliprajapati@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the [Plugin] View Transitions [slug: view-transitions] label Oct 9, 2026
* @return string Modified CSS with the actual animation duration in seconds.
*/
function plvt_inject_animation_duration( string $css, int $animation_duration ): string {
if ( $animation_duration <= 0 ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is called with abs_int in https://github.com/WordPress/performance/pull/2706/changes#diff-1c421c546ad4335a5b5233d0dbb71cd84a39fb2049233e0b0e96241e0e58288aR319, but a guard may still be worthwhile in case others call the function incorrectly.

Wouldn't 0 be a valid value here?

The docblock seems inaccurate, the default is supposed to be 400 ms (settings.php:69), maybe we should fix that as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the great feedback! You are completely right on all points:

  1. Allow 0ms as valid duration: Updated the check to strictly negative ($animation_duration < 0). A value of 0 is preserved and renders 0s, which is valid CSS for instant transitions.
  2. Default to 400ms & docblock fix: Updated the docblock and fallback value to 400ms to stay consistent with settings.php and theme.php (as updated in Set default view transition duration to 400 for better alignment with browser default #2081).
  3. Test coverage: Updated the unit test suite to verify that 0ms produces 0s, and negative values default to 400ms (0.4s). Also fixed the array index offset in the theme support unit test.

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.54%. Comparing base (a25f804) to head (540824a).
⚠️ Report is 2 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2706      +/-   ##
==========================================
+ Coverage   70.50%   71.54%   +1.03%     
==========================================
  Files          91       91              
  Lines        7869     7871       +2     
==========================================
+ Hits         5548     5631      +83     
+ Misses       2321     2240      -81     
Flag Coverage Δ
multisite 71.54% <100.00%> (+1.03%) ⬆️
single 35.77% <100.00%> (+0.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonali195

Copy link
Copy Markdown
Author

Thanks for the great feedback! You are completely right on all points:

  1. Allow 0ms as valid duration: Updated the check to strictly negative ($animation_duration < 0). A value of 0 is preserved and renders 0s, which is valid CSS for instant transitions.
  2. Default to 400ms & docblock fix: Updated the docblock and fallback value to 400ms to stay consistent with settings.php and theme.php (as updated in Set default view transition duration to 400 for better alignment with browser default #2081).
  3. Test coverage: Updated the unit test suite to verify that 0ms produces 0s, and negative values default to 400ms (0.4s). Also fixed the array index offset in the theme support unit test.

(Could a maintainer also please add the [Type] Bug and no milestone labels so the PR validation checks pass? Thank you!)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] View Transitions [slug: view-transitions]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants