Repository navigation
Honor prefers-reduced-motion automatically - #231
Merged
Merged
Conversation
Readers who ask their system for reduced motion now get the same treatment the library already had behind `disableParallax: true` and `disableVideo: true`: the image is covered and positioned as usual but never moves with the scroll, and the background video is never inserted, so the poster stays on screen and no provider player is downloaded. Also pass the new video-worker host options through as `videoYoutubeHost` and `videoVimeoHost`, and pick up video-worker 3.1.0.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
A self-hosted video has no provider thumbnail to fall back on, so an element with no image of its own went blank under reduced motion. It is now inserted paused instead: browsers paint the first frame of a video that is not playing, as long as the placeholder poster is left off, so the block keeps something to look at. Reduced motion is no longer folded into `disableVideo`, because what replaces the video depends on the provider and that option should keep meaning only what the author asked for.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A reader whose system asks for reduced motion still got the full parallax and an autoplaying background video. Both now stop on their own, with nothing to configure.
On the parallax side the implementation adds no new rendering state:
(prefers-reduced-motion: reduce)folds into thedisableParallaxcheck, so a reduced-motion visitor lands on exactly the layout that option has always produced — a path already used for the mobile fallback and already covered by tests. The video side is decided separately, because what should replace the video depends on the provider, anddisableVideoshould keep meaning only what the author asked for.Skipping the provider iframe rather than inserting-and-pausing it is deliberate: the thumbnail is already painted as the container background, so there is nothing to gain from several hundred kilobytes of player for someone who will not see it move.
The self-hosted case
A self-hosted video has no thumbnail to borrow, so an element with no image of its own would have gone blank — trading motion sickness for an empty hero is not a win. It is inserted paused instead, which works because of one measured detail:
<video>preload="metadata", no postercurrentTime=0preload="metadata", placeholder posterThe placeholder poster is a transparent 1×1 GIF, and it is what would have covered the frame. So in this one case the poster is left off and
object-fit: coveris set directly —startednever fires, socoverImage()never gets a chance to size the element itself.Verified in Chrome 151
Playwright's
reducedMotionemulation sets the real media feature, so this exercises the actual query rather than a stub.The frame check samples the element through a canvas and measures luminance range, so "painted" means real pixels, not just a
readyState. The control run is the point: nothing changes when the preference is not set.Reduced motion is read when the instance is created. Toggling the system setting applies on the next page load; making it live means destroying and re-creating instances behind React's and jQuery's backs, which did not seem worth it for how rarely the setting changes mid-session.
Also in here
videoYoutubeHostandvideoVimeoHost, forwarded to the options added in video-worker 3.1.0. They follow the existingvideo*prefix so the data attributes stay grouped (data-video-youtube-host). Left unset they passundefined, which video-worker'sextendskips, so its own default is never pinned here a second time.video-workerbumped to^3.1.0— Vimeo backgrounds no longer play muted in Chrome, and YouTube moves off the nocookie host.npm installalphabetized two@types/react*lines inpackage.json. Incidental, not mine.npm run lint,format:check,typecheckandtest:run(50 tests) pass. The new tests cover both directions for image and video backgrounds, the poster-only insertion, and that no player is requested or played under reduced motion.Unrelated, noticed while testing: calling
jarallaxVideo()by hand on top of the UMD bundle, which already calls it, patches the prototype twice and corruptsdefaultInitImgResult. Pre-existing, not touched here.