Skip to content

Commit

Permalink
Remove prefers-reduced-motion emulation (#27)
Browse files Browse the repository at this point in the history
Unfortunately, the `transition-duration` in
Ie1c6c1ba7263c232d874263fdae7427a5ec489f6 is causing elements to behave in an
unpredictable manner. Removing the `prefers-reduced-motion` is now more
stable/predictable than using it.

Also, wait until next frame in `fastForwardAnimations`. Note there is still some
flakiness with the visibility of the mobile sidebar that needs to be sorted out
but this should help with the other random stuff.
  • Loading branch information
Nick Ray authored May 17, 2022
1 parent 963ff02 commit f3ed2a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/engine-scripts/puppet/fastForwardAnimations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @param {import("puppeteer").Page} page
*/
async function fastForwardAnimations( page ) {
return page.evaluate( () => {
return page.evaluate( async () => {
// Adapted from https://github.com/microsoft/playwright/blob/0a401b2d86a39df85e57ad30bcec9ef81618abd0/packages/playwright-core/src/server/screenshotter.ts#L174
document.getAnimations().forEach( ( animation ) => {
if ( animation.playbackRate === 0 || !animation.effect ) {
Expand All @@ -22,6 +22,15 @@ async function fastForwardAnimations( page ) {
animation.cancel();
}
} );

// Wait until the next frame before resolving.
return new Promise( ( resolve ) => {
requestAnimationFrame( () => {
requestAnimationFrame( () => {
resolve();
} );
} );
} );
} );
}

Expand Down
3 changes: 0 additions & 3 deletions src/engine-scripts/puppet/jsReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* @param {import("puppeteer").Page} page
*/
module.exports = async ( page ) => {
await page.emulateMediaFeatures( [
{ name: 'prefers-reduced-motion', value: 'reduce' }
] );
await page.evaluate( async () => {
// eslint-disable-next-line no-undef
const skin = mw.config.get( 'skin' );
Expand Down
2 changes: 1 addition & 1 deletion src/engine-scripts/puppet/menuState.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const menuState = async ( page, buttonSelector, isClosed ) => {
}, buttonSelector, isClosed );

// Vector-2022 menus currently have transition animations when opened.
fastForwardAnimations( page );
await fastForwardAnimations( page );
};

module.exports = menuState;

0 comments on commit f3ed2a7

Please sign in to comment.