[SSR] Removed call of requestAnimationFrame outside of function#975
[SSR] Removed call of requestAnimationFrame outside of function#975fezproof wants to merge 6 commits into
Conversation
This allows the base library of @adobe/react-spectrum to used in Gatsby Fixes #842
| // if we're using a high res timer, make sure timestamp is not the old epoch-based value. | ||
| // http://updates.html5rocks.com/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision | ||
| if (fixTs) { | ||
| if (t < 1e12) { |
There was a problem hiding this comment.
Actually, I think this is the opposite of what we need? If the time is less than 1e12 then it's a high res timer already. I think we want t > 1e12 here instead?
There was a problem hiding this comment.
And also we might need to check the resolution of performance.now() as the above check does. e.g. in safari performance.now() is less than 1e12 (I think after the spectre/meltdown attacks).
Maybe we should just put the check above in an if statement to check if requestAnimationFrame even exists?
There was a problem hiding this comment.
I will experiment with this and get back to you!
There was a problem hiding this comment.
@devongovett Finished testing, doing the compare inside the animation seems to be the only option :(
I have updated the PR + added some consts to ease my conscience 😁
|
Merged manually |
This allows the base library of @adobe/react-spectrum to used in Gatsby
Closes #842
✅ Pull Request Checklist:
📝 Test Instructions:
Without this change, the gatsby build will try to run rAF as it is outside of a actually hook function that would normally be called in the render loop. This caused the error in #835. With this simple change, functionality is essentially the same, but it will now compile in a Gatsby enviroment.
The only real loss is that the check will happen every animation frame, but it is a semi-cheap comparison so it shouldn't effect any actual animations.
See https://developers.google.com/web/updates/2012/05/requestAnimationFrame-API-now-with-sub-millisecond-precision#feature_detection to show the change shouldn't make any reasonable difference to the code.