-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
[Fiber] Check for requestAnimationFrame throws when react-dom is required on the server #9102
Comments
A workaround that achieves my expected behavior is for each consumer of React to define a little polyfill in a file that's imported before the others but I expect many people to run into this issue. This is what it looks like: global.window = global;
window.addEventListener = () => {};
window.requestAnimationFrame = () => {
throw new Error('requestAnimationFrame is not supported in Node');
}; |
We could fix this by lazily initializing |
Can't run tests due to facebook/react#9102
You shouldn't run it on the server, but importing it is fine. Otherwise how would you write a component that uses
No, the test doesn’t catch this because we set up a global rAF polyfill as part of our testing environment. |
Edit: The PR is just for illustration. Just ran the unit tests. No linting and prettier run yet. Opened a PR to put down the idea in code. I moved the check for But now, I lost the ability to throw if the |
Do you want to request a feature or report a bug?
Bug-ish
What is the current behavior?
When doing server-side rendering with React, requiring
react-dom
(which transitively requiresReactDOMFrameScheduling.js
) throws an exception because rAF is not defined.This can happen if you have a universal component that has top-level imports of client-side libraries, like
react-router-scroll
, that requirereact-dom
instead ofreact-dom/server
.What is the expected behavior?
I would expect not to get this error unless requestAnimationFrame were actually called. Ex: lazily check for rAF and define rIC.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.0.0-alpha.3 on Node 7.7.1. This started happening in alpha 3, which shipped and enabled Fiber.
The text was updated successfully, but these errors were encountered: