Skip to content

Implement customizable transition animation duration setting#2321

Open
sarthak-19 wants to merge 9 commits intoWordPress:trunkfrom
sarthak-19:Feat/custom_animation_duration
Open

Implement customizable transition animation duration setting#2321
sarthak-19 wants to merge 9 commits intoWordPress:trunkfrom
sarthak-19:Feat/custom_animation_duration

Conversation

@sarthak-19
Copy link
Contributor

Part of a polishing issue : #2317

Summary

This PR implements the transition animation duration setting that was previously added to the UI but wasn't functional. The duration setting now properly affects view transitions on both the frontend and WordPress admin area.

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

❌ Patch coverage is 8.19672% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.30%. Comparing base (509ad26) to head (988d662).
⚠️ Report is 2 commits behind head on trunk.

Files with missing lines Patch % Lines
plugins/view-transitions/includes/settings.php 4.65% 41 Missing ⚠️
plugins/view-transitions/includes/admin.php 17.64% 14 Missing ⚠️
plugins/view-transitions/hooks.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2321      +/-   ##
==========================================
+ Coverage   69.17%   69.30%   +0.12%     
==========================================
  Files          90       90              
  Lines        7708     7763      +55     
==========================================
+ Hits         5332     5380      +48     
- Misses       2376     2383       +7     
Flag Coverage Δ
multisite 69.30% <8.19%> (+0.12%) ⬆️
single 35.34% <0.00%> (-0.05%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

@westonruter westonruter added the [Plugin] View Transitions Issues for the View Transitions plugin label Jan 4, 2026
@westonruter westonruter added this to the view-transitions n.e.x.t milestone Jan 4, 2026
@westonruter westonruter added the [Type] Enhancement A suggestion for improvement of an existing feature label Jan 4, 2026
@westonruter
Copy link
Member

Comment from @sarthak-19 in Slack:

I raised a draft PR because currently I was unsure of what more are we expecting to be delivered in this task for polishing, since the issue mentioned of Add support for customizing transition animation duration
But this was already added in the UI as well.
What I did for potential polishing items are :

  1. Added validation bounds - Duration is now clamped between 100ms and 5000ms with proper input validation
  2. Applied duration to admin - Admin view transitions now also respect the duration setting
  3. Added real-time preview - The seconds equivalent updates dynamically as you type in the > milliseconds field.
  4. Exposed in REST API - Added default_transition_animation_duration to the REST API schema
  5. Added unit tests - Tests for duration sanitization, clamping, and the injection function

@sarthak-19 sarthak-19 marked this pull request as ready for review January 18, 2026 16:25
@github-actions
Copy link

github-actions bot commented Jan 18, 2026

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.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @sarthak.jaiswal@rtCamp.com.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

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

Unlinked contributors: sarthak.jaiswal@rtCamp.com.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: sarthak-19 <sarthak8858@git.wordpress.org>

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

@westonruter

This comment was marked as resolved.

@westonruter
Copy link
Member

Another polishing idea: there could be validation added to the input fields for the CSS selectors. Maybe this would be as simple as a pattern attribute added to each with a regex that would roughly match a valid regex. A more sophisticated validation would be to use JS to put the selector into a call to document.querySelector. If it errors, then we'd know the selector is invalid and we could call setCustomValidity() on the input element. I don't think there would be any security issue introduced by running user input into a JS function like that.

@sarthak-19
Copy link
Contributor Author

@westonruter I'm not able to figure out why unit test is failing for PHP 8.3+.
Ref job : https://github.com/WordPress/performance/actions/runs/21336924141/job/61410218740?pr=2321
In my local wp-env I'm testing on PHP 8.3, it's passing.

Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 8.5.42 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.30
Time: 798 ms, Memory: 42.50 MB

OK (18 tests, 39 assertions)
✔ Ran `composer test:view-transitions` in 'tests-cli'. (in 2s 284ms)

Any ideas ?

@westonruter
Copy link
Member

@sarthak-19 Ah, it's because view transitions were added to the admin already in trunk. See Core-64470 and #2344. So in 988d662 I've skipped the tests.

However, given that this has landed in the admin, I'm not sure we should actually add a setting for that part since it has already shipped, essentially.

Comment on lines +23 to +31
try {
document.querySelector( selector );
return { valid: true };
} catch ( error ) {
return {
valid: false,
message: 'Invalid CSS selector: ' + error.message,
};
}
Copy link
Member

Choose a reason for hiding this comment

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

Gemini pointed out to me that there is a newish better way to do this via CSS.supports:

Suggested change
try {
document.querySelector( selector );
return { valid: true };
} catch ( error ) {
return {
valid: false,
message: 'Invalid CSS selector: ' + error.message,
};
}
return CSS.supports( `selector(${selector})` );

It is supported by all browsers that WP supports: https://caniuse.com/css-supports-api

This being the case, we can change this to just return a boolean.

* Validates a CSS selector by attempting to use it with document.querySelector.
*
* @param {string} selector The CSS selector to validate.
* @return {Object} Object with 'valid' boolean and optional 'message' string.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return {Object} Object with 'valid' boolean and optional 'message' string.
* @return {boolean} Whether the selector is valid.

existingError.remove();
}
} else {
input.setCustomValidity( result.message );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
input.setCustomValidity( result.message );
input.setCustomValidity( 'Invalid selector' ); // TODO: translate me!

But… the message will need to be translated.

?>
<style>
@view-transition { navigation: auto; }
::view-transition-group(*) { --plvt-view-transition-animation-duration: <?php echo (int) $duration; ?>ms; }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
::view-transition-group(*) { --plvt-view-transition-animation-duration: <?php echo (int) $duration; ?>ms; }
::view-transition-group(*) { --plvt-view-transition-animation-duration: <?php echo absint( $options['default_transition_animation_duration'] ); ?>ms; }

Let's remove $duration = absint( $options['default_transition_animation_duration'] ); with suggested change we can remove the int casting.

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

Labels

[Plugin] View Transitions Issues for the View Transitions plugin [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants