-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent crash in environments where Element.prototype.getAnimations
is not available
#3473
Conversation
This polyfill does 2 things: 1. Shows a warning with information on how to proceed 2. Results in **no** animations at all. Which means that if you test the actual timing of transitions, that this will now fail (until the polyfill is installed).
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
typeof process !== 'undefined' && | ||
typeof globalThis !== 'undefined' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we also check for typeof process.env !== 'undefined'
or make the process.env[]
lookup an optional chain, just to prevent a crash in some very weird setups:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah not a bad idea honestly
Just a note to say that So any messages should not be jsdom specific imo |
If, for whatever reason, the `process` is `null`, or it is available but `process.env` is not then this could still crash. Using `?.` should help us in all these situations.
@plavski the |
Updated the wording slightly |
Cool. It was only the wording feeling overly specific that was the issue for me, and your change has cleared that up. Thanks! |
Just tested this and it all works as expected. Without explicit polyfill there's a warning. With polyfill as suggested, no warning, see https://github.com/loculus-project/loculus/pull/2766/files for implementation details. |
…t not interceptors) (#2766) * deps(website): update headlessui and add jsdom polyfill see: - tailwindlabs/headlessui#3473 - tailwindlabs/headlessui#3469 * Update msw, pinning transitive dep msw interceptors to 0.33.3 for the time being see: - mswjs/msw#2273
Recently we made improvements to the
Transition
component and internaluseTransition
hook. We now use theElement.prototype.getAnimations
API to know whether or not all transitions are done.This API has been available in browsers since 2020, however jsdom doesn't have support for this. This results in a lot of failing tests where users rely on jsdom (e.g. inside of Jest or Vitest).
In a perfect world, jsdom is not used because it's not a real browser and there is a lot you need to workaround to even mimic a real browser.
I understand that just switching to real browser tests (using Playwright for example) is not an easy task that can be done easily.
Even our tests still rely on jsdom…
So to make the development experience better, we polyfill the
Element.prototype.getAnimations
API only in tests (process.env.NODE_ENV === 'test'
) and show a warning in the console on how to proceed.The polyfill we ship simply returns an empty array for
node.getAnimations()
. This means that it will be enough for most tests to pass. The exception is if you are actually relying ontransition-duration
andtransition-delay
CSS properties.The warning you will get looks like this:
Fixes: #3470
Fixes: #3469
Fixes: #3468