You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
requestAnimationFrame warnings on tests since React 16 #3199
I expected the testing to complete without warnings out-of-the-box (as it did pre-R16).
Actual Behavior
All tests pass, but prints message:
console.error node_modules/fbjs/lib/warning.js:33
Warning: React depends on requestAnimationFrame. Make sure that you load a polyfill in older browsers. http://fb.me/react-polyfills
I know React 16 needs that polyfill, my point is that create-react-app could provide it by default, taking the burden out of its users shoulders. For instance, it could depend on the raf package and change the test script in package.json to
{
"scripts": {
"test": "react-scripts test --env=jsdom --setupTestFrameworkScriptFile=raf/polyfill",
},
}
Reacted by Bryan Focht, Michael, Michael Liendo, Roger Albino, Filipe Dos Santos Mendes, Lufty Wiranda, Caroline Benn, patstockwell, Olaolu Akinsete, Fernando Montoya and 29 more
Great point!
We know we need to start providing a Map and Set polyfill by default now, but we want to figure out a better story for including the polyfills (so they're not included for React 15 bundles, etc).
More to come on this soon, but happy to discuss further if you have some ideas!
On the point of providing a Map and Set polyfill by default, my understanding is that babel-core loads said polyfill's automatically as per the babel-polyfilldocs
@lukerollans I'm not sure what you're referring to, we do not depend on or include babel-polyfill by default.
Babel itself (babel-core) does not concern itself with polyfilling anything except some language features it uses itself (like Object.assign, via its _extends helper).
Polyfills wouldn't conflict with one another, so someone who uses babel-polyfill in their application wouldn't experience any bad side-effect (but you should never use the entirety of babel-polyfill or core-js).
@Timer i meant specifically for testing. Map and Set are already supported in Node 0.12+, so I think we can leave this issue just for CRA default test setup.
We'll figure something out soon. Sorry about that. This was the biggest release we ever did, there's also a new website we're launching today, and between all that there's a few kinks we still need to iron out.
Reacted by Oleksiy Dubovyk, Zach Holman, Pascal Helbig, Jonathan Crossman, MOZGIII, Vitor Alencar, Massimo Mauri, Jonas Olofsson, Luke Owens, Alex Dong and 57 more
Reacted by Jonathan Irving
Reacted by Luke Rollans, Eric Schoonover, Alex Le, Mike Bifulco, Anna Su, Markoz Peña, Dávid Csejtei, Lukáš Linhart, Adam Seckel, Ilia Sidorenko and 15 more
@holman FYI I had the same problem RE shim not working. The gotcha is that polyfill/shim needs to be in it's own file, and loaded before any dependencies. See jestjs/jest#4545 (comment).
Reacted by Mike Bifulco, André Herculano, Kristoffer, Luke Clark, John, Mirko Guarnier, Nemanja Milosavljevic, Paul Darragh, Farzad Yousefzadeh, DreamAwakening and 2 more
@unutoiul probably not the place for such questions but for making API calls, or dealing with side effects, you would want redux-thunk (Dan's project :p), or redux-sage. There's a lot of options tbh.
Sadly @unutoiul solution does not work for me :(. The only difference is i'm using react-scripts-ts - TypeScript.
When i had only polyfill in setupTests.ts it worked, but after i added Enzyme and separated polyfill to a new file i cannot get this to work:
import raf from 'tempPolyfill';
import Enzyme, { shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({adapter: new Adapter()});
// Make Enzyme functions available in all test files without importing
global.shallow = shallow;
Any clues?
Reacted by David Guan, Frank, Nikolay, Lee Zhen Yong, BrunoLM and Balogun Oghenerobo Philip
Can you provide a minimal example demonstrating this please? That sounds like a bug to me. It’s just a console.error() call so I don’t see why it would be a non-zero exit.
(If you configured your tests to fail on console.error then of course it would be a non-zero code, but configuring them as such would be your decision, not our default.)
I think we'll fix this by updating to Jest version that already has a polyfill.
Or maybe we'll copy it over. I'll try to get it done today.
Reacted by Cezar Neaga, Danyal Aytekin, Sean Poulter, Nick Ribal, Roman Smolkin, Leonhardt Koepsell, zhaozhiming, Scott Davis, Jason Wong, Alonso A. Ortega and 5 more
Reacted by Martin Møller, Alex Petersen and Scott Davis
Reacted by Maxence Poutord, Andi Wilson, Danyal Aytekin, Charles Riley, Nate Radebaugh, Chung-Min Cheng, Morteza Ziyaeimehr, Dan Vitoriano 🌈, Jarek Cichy, Tomas Chmelevskij and 2 more
Reacted by Scott Davis, Leonhardt Koepsell, Michael Herman, Maciej Kasprzyk, Andi Wilson, Danyal Aytekin, Charles Riley, John, Marion Livet, Nick Williams and 6 more
Reacted by Danyal Aytekin, Charles Riley, Mauricio Melo, Dariusz Naploszek, Jarek Cichy and jm
it's possible when you don't want to work with older browser just turn off the warnings and errors on test ? or like android apps to specify the min. version supported ? or technically is not good idea? I think the idea to add polyfills when you dont' really need add more code to the build file ?
my build file have 1.6 Megabytes, i don't know why is so big
This issue is starting to get noisy with potentially incorrect advice so I'm locking this. If you experience problems please file a new issue.
Note that as of react-scripts@1.0.15 you shouldn't see this warning in tests. You would see it in older browsers (such as IE10) though. If you support those old browsers, you should add import 'raf/polyfill' as the first line of your src/index.js.
Activity
barraponto commentedon Sep 27, 2017
I know React 16 needs that polyfill, my point is that create-react-app could provide it by default, taking the burden out of its users shoulders. For instance, it could depend on the raf package and change the test script in
package.jsonto{ "scripts": { "test": "react-scripts test --env=jsdom --setupTestFrameworkScriptFile=raf/polyfill", }, }Timer commentedon Sep 27, 2017
Great point!
We know we need to start providing a Map and Set polyfill by default now, but we want to figure out a better story for including the polyfills (so they're not included for React 15 bundles, etc).
More to come on this soon, but happy to discuss further if you have some ideas!
lukerollans commentedon Sep 27, 2017
On the point of providing a Map and Set polyfill by default, my understanding is that
babel-coreloads said polyfill's automatically as per thebabel-polyfilldocsHappy to be proven wrong, though.
Timer commentedon Sep 27, 2017
@lukerollans I'm not sure what you're referring to, we do not depend on or include
babel-polyfillby default.Babel itself (
babel-core) does not concern itself with polyfilling anything except some language features it uses itself (likeObject.assign, via its_extendshelper).Polyfills wouldn't conflict with one another, so someone who uses
babel-polyfillin their application wouldn't experience any bad side-effect (but you should never use the entirety ofbabel-polyfillorcore-js).lukerollans commentedon Sep 27, 2017
I just double checked the source I linked to and I simply misread
babel-nodeforbabel-core, thanks for clearing it up!Timer commentedon Sep 27, 2017
Ah, no problem!
Timer commentedon Sep 27, 2017
x-ref: #3200
barraponto commentedon Sep 27, 2017
@Timer i meant specifically for testing. Map and Set are already supported in Node 0.12+, so I think we can leave this issue just for CRA default test setup.
Timer commentedon Sep 27, 2017
@barraponto correct! but we target IE 9 and Map and Set are not available in IE <11, so we'll just kill two birds with one stone! 😄
holman commentedon Sep 27, 2017
fwiw, I know the current idea mentioned in various docs is to put this in
src/setupTests.js:...but that doesn't seem to kill these warnings for me either after moving to 16.
gaearon commentedon Sep 27, 2017
We'll figure something out soon. Sorry about that. This was the biggest release we ever did, there's also a new website we're launching today, and between all that there's a few kinks we still need to iron out.
jameslockwood commentedon Sep 28, 2017
@holman FYI I had the same problem RE shim not working. The gotcha is that polyfill/shim needs to be in it's own file, and loaded before any dependencies. See jestjs/jest#4545 (comment).
holman commentedon Sep 28, 2017
Nice! Yeah that fixed it for me. Thanks for the heads-up @jameslockwood.
fix requestAnimationFrame error, also added Gift component test
13 remaining items
JamesTheHacker commentedon Oct 17, 2017
@unutoiul probably not the place for such questions but for making API calls, or dealing with side effects, you would want redux-thunk (Dan's project :p), or redux-sage. There's a lot of options tbh.
dnaploszek commentedon Oct 18, 2017
Sadly @unutoiul solution does not work for me :(. The only difference is i'm using react-scripts-ts - TypeScript.
When i had only polyfill in setupTests.ts it worked, but after i added Enzyme and separated polyfill to a new file i cannot get this to work:
tempPolyfill.ts
setupTests.ts
Any clues?
offero commentedon Oct 21, 2017
Except it exits with a non-zero exit code.
gaearon commentedon Oct 21, 2017
Can you provide a minimal example demonstrating this please? That sounds like a bug to me. It’s just a
console.error()call so I don’t see why it would be a non-zero exit.gaearon commentedon Oct 21, 2017
(If you configured your tests to fail on
console.errorthen of course it would be a non-zero code, but configuring them as such would be your decision, not our default.)offero commentedon Oct 21, 2017
I have recently found the CI=true option and it's now exiting correctly. Thanks.
danyalaytekin commentedon Oct 26, 2017
Looking forward to the fix for this, but no pressure. Hope you're feeling better @gaearon.
gaearon commentedon Oct 26, 2017
I think we'll fix this by updating to Jest version that already has a polyfill.
Or maybe we'll copy it over. I'll try to get it done today.
gaearon commentedon Oct 30, 2017
Should be fixed in
react-scripts@1.0.15.https://github.com/facebookincubator/create-react-app/releases/tag/v1.0.15
webmobiles commentedon Nov 15, 2017
it's possible when you don't want to work with older browser just turn off the warnings and errors on test ? or like android apps to specify the min. version supported ? or technically is not good idea? I think the idea to add polyfills when you dont' really need add more code to the build file ?
my build file have 1.6 Megabytes, i don't know why is so big
Arelav commentedon Nov 16, 2017
@dnaploszek
Not worked for me with latest Create React App
This is my solution:
setupTests.ts
gaearon commentedon Nov 17, 2017
This issue is starting to get noisy with potentially incorrect advice so I'm locking this. If you experience problems please file a new issue.
Note that as of
react-scripts@1.0.15you shouldn't see this warning in tests. You would see it in older browsers (such as IE10) though. If you support those old browsers, you should addimport 'raf/polyfill'as the first line of yoursrc/index.js.