Comments (27)
Hey!,
It seems that phantomjs cannot run React code, I'll post the issue in React repo.
Thanks for that.
from react-rails.
Will let you know here as soon as it is pulled in and published to rubygems, in the meantime if you need a workaround, you would have to create a copy of react.js and apply the required change (it's in the PR).
from react-rails.
Thanks for this @JakubMal!
from react-rails.
As suggested in the PR, just use polyfill for Function.prototype.bind
from react-rails.
Hey, sorry if I came off a bit harsh there. Let me know if that's an option for you @tomelm and if not I'll definitely take it into consideration. I've been a bit dogmatic but I'm open to reason :)
from react-rails.
@zpao no problem! I totally understand where you're coming from. I will try the es5-shim and see if that might help the headless browsers with the tests. I don't need anything crazy as long as I can get the tests passing appropriately :p
from react-rails.
Bump!
I'm trying to test React using CasperJS (it's based on PhantomJS) and React is not defined. Other libraries I include the same way as React (Lo-Dash, for example) are found.
Can this be related? What's the current status?
from react-rails.
This issue is closely related. facebook/react#347
tl;dr Use https://github.com/es-shims/es5-shim/blob/master/es5-shim.js or don't use PhantomJS/CasperJS at all, but go for Selenium.
from react-rails.
I think we could add es5-shim when test environment is present. Put on my TODO list to rethink or close this issue.
from react-rails.
We're going to need more than es5-shim for React soon, so our story around polyfills in React may change. Follow along in facebook/react#1998
from react-rails.
How about we display a warning when poltergeist is detected? (phantomjs has been stuck at the shitty version of webkit for quite a time now) On the other hand it looks like ES 6+ features will be shimmed on your side - due to the browser support?
from react-rails.
@JakubMal I don't know yet where we'll end up with built-in polyfill support for ES*
from react-rails.
@daGrevis Did you just add es5-shim.js and tests started to work?
from react-rails.
@Loremaster Sure. Doesn't it for you?
from react-rails.
@daGrevis Yes, it doesn't. :( I added es5-shim.js
to the vendor folder. Then I required it in application.js
:
//= require jquery
...
//= require es5-shim
I restarted rails server and I can see that new file appeared. But when I try to run tests again then I see the error:
One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).
TypeError: 'undefined' is not a function (evaluating 'RegExp.prototype.test.bind(
/^(data|aria)-[a-z_][a-z\d_.\-]*$/
)')
TypeError: 'undefined' is not a function (evaluating 'RegExp.prototype.test.bind(
/^(data|aria)-[a-z_][a-z\d_.\-]*$/
)')
at http://127.0.0.1:54587/assets/application.js:32342
at http://127.0.0.1:54587/assets/application.js:28807 in s
at http://127.0.0.1:54587/assets/application.js:28807
at http://127.0.0.1:54587/assets/application.js:37581
at http://127.0.0.1:54587/assets/application.js:28807 in s
at http://127.0.0.1:54587/assets/application.js:28807
at http://127.0.0.1:54587/assets/application.js:32910
at http://127.0.0.1:54587/assets/application.js:28807 in s
at http://127.0.0.1:54587/assets/application.js:28807 in e
at http://127.0.0.1:54587/assets/application.js:47260
at http://127.0.0.1:54587/assets/application.js:28807
at http://127.0.0.1:54587/assets/application.js:47262 (Capybara::Poltergeist::JavascriptError)
./features/step_definitions/service.steps.rb:16:in `/^the individual user$/'
features/service/new.feature:10:in `Given the individual user'
Any ideas what to do?
from react-rails.
@Loremaster Sorry, mate. Maybe you are mising some other required shims.
from react-rails.
Hey, I found the solution! I should set es5-shim
BEFORE the react init:
application.js
//= require es5-shim
//= require react
//= require react_ujs
Now it works, awesome!
from react-rails.
Of course you should use it before. Glad it works now. ;)
from react-rails.
I ran into this problem today. Adding es5-shim
did the trick. @Loremaster you can use rails-assets-es5-shim
so you don't have to put the code in your repo's vendor directory.
from react-rails.
👍 Thanks guys! Spent three hours trying to figure this out, glad I found this thread
from react-rails.
Thanks for this. I think it might be worth adding a note about this to README.md.
from react-rails.
Feels good to help others! I'm glad I wrote how I solved it here! 👍
from react-rails.
glad to hear this was solved!
from react-rails.
Yes, please put a pointer in the README. We spent ages on this too (and didn't think to look at a closed issue).
Thank you for figuring this out! You saved out lives ;-)
from react-rails.
I have tried to inject the shim script through page.injectJS
, but it didn't work, I guess since page.injectJS
does not support closures:
page.open(url, function(status) {
if (status === "success") {
if (page.injectJs('es5-shim.js')) {
page.render(pageCaptureFileName, {
format: Settings.pageCaptureFileType,
quality: Settings.pageCaptureQuality
})
}
}
});
http://phantomjs.org/api/webpage/method/inject-js.html
from react-rails.
Just wanted to mention that with PhantomJS 2 out (which is ES5 compliant) you no longer need the Es5 shim to get Poltergeist working...
from react-rails.
@abreckner that is a great news, but I was using PhantomJS
that version already:
macbookproloreto:async-example admin$ phantomjs -v
2.1.1
from react-rails.
Related Issues (20)
- `ReactDOM.version?.split` not transpiled? HOT 3
- Can't resolve 'react-dom/client' HOT 3
- Import react_component but it' shown HOT 2
- compare/contrast and migration steps to react_on_rails HOT 5
- Component doesn't render on jsbundling-rails webpacker HOT 5
- Component not loading in rails app HOT 5
- react-rails v3.1.0 is broken HOT 1
- server_rendering.js not found following README HOT 8
- Re-organize documentations in docs folder
- server_rendering.js not found following README HOT 1
- How do I handle styling?
- esbuild HOT 1
- Error related to server_rendering.js not found with SSR HOT 3
- Setup StrictMode for components HOT 2
- get started docs r-r version HOT 1
- Rails 7.1 Renders Partial Header HOT 1
- Server side rendering `window` behaves differently than Node.js? HOT 4
- Issues with Loading React Component for Cuprite in Rails 7.1
- Hooks not working due to Invalid Hook Call HOT 2
- Move react_ujs to es module flow
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-rails.