GithubHelp home page GithubHelp logo

Comments (27)

jtmalinowski avatar jtmalinowski commented on July 27, 2024

Hey!,
It seems that phantomjs cannot run React code, I'll post the issue in React repo.

Thanks for that.

from react-rails.

jtmalinowski avatar jtmalinowski commented on July 27, 2024

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.

tomelm avatar tomelm commented on July 27, 2024

Thanks for this @JakubMal!

from react-rails.

jtmalinowski avatar jtmalinowski commented on July 27, 2024

As suggested in the PR, just use polyfill for Function.prototype.bind

from react-rails.

zpao avatar zpao commented on July 27, 2024

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.

tomelm avatar tomelm commented on July 27, 2024

@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.

daGrevis avatar daGrevis commented on July 27, 2024

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.

daGrevis avatar daGrevis commented on July 27, 2024

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.

jtmalinowski avatar jtmalinowski commented on July 27, 2024

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.

zpao avatar zpao commented on July 27, 2024

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.

jtmalinowski avatar jtmalinowski commented on July 27, 2024

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.

zpao avatar zpao commented on July 27, 2024

@JakubMal I don't know yet where we'll end up with built-in polyfill support for ES*

from react-rails.

Loremaster avatar Loremaster commented on July 27, 2024

@daGrevis Did you just add es5-shim.js and tests started to work?

from react-rails.

daGrevis avatar daGrevis commented on July 27, 2024

@Loremaster Sure. Doesn't it for you?

from react-rails.

Loremaster avatar Loremaster commented on July 27, 2024

@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.

daGrevis avatar daGrevis commented on July 27, 2024

@Loremaster Sorry, mate. Maybe you are mising some other required shims.

from react-rails.

Loremaster avatar Loremaster commented on July 27, 2024

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.

daGrevis avatar daGrevis commented on July 27, 2024

Of course you should use it before. Glad it works now. ;)

from react-rails.

mockdeep avatar mockdeep commented on July 27, 2024

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.

feifanzhou avatar feifanzhou commented on July 27, 2024

👍 Thanks guys! Spent three hours trying to figure this out, glad I found this thread

from react-rails.

tirdadc avatar tirdadc commented on July 27, 2024

Thanks for this. I think it might be worth adding a note about this to README.md.

from react-rails.

daGrevis avatar daGrevis commented on July 27, 2024

Feels good to help others! I'm glad I wrote how I solved it here! 👍

from react-rails.

rmosolgo avatar rmosolgo commented on July 27, 2024

glad to hear this was solved!

from react-rails.

ygt-mikekchar avatar ygt-mikekchar commented on July 27, 2024

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.

loretoparisi avatar loretoparisi commented on July 27, 2024

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.

abreckner avatar abreckner commented on July 27, 2024

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.

loretoparisi avatar loretoparisi commented on July 27, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.