GithubHelp home page GithubHelp logo

Comments (7)

zpao avatar zpao commented on July 27, 2024

My comment on stack overflow: http://stackoverflow.com/questions/24438996/react-rails-component-with-prerender-true-in-options-hash-gives-a-v8error#comment37857875_24438996

I suspect maybe we have a bug about when we load components.js into the VM. Can anybody test this out?

from react-rails.

johnthethird avatar johnthethird commented on July 27, 2024

I have set up a Runnable with a sample server rendered component, and it is working on react-rails master with Ruby 1.9.3-p194 and TheRubyRacer gem.

http://runnable.com/U87J_K82JzoNLOzT/react-rails-server-rendering-example-for-reactjs

@KurtRMueller Im not sure this is your problem, but the CS file of yours needs to somehow attach AssignmentWindowProgressBar to the global object (unless you have turned off the protective function wrapper that CS usually uses). In the browser that is window and in V8 it is global. So in my example CS I have at the end of my component definition:

window.FancyBox = FancyBox if window?
global.FancyBox = FancyBox if global?

We need some conventions on how to best do this so everything works on client and server. Im sure nodejs has this figured out, how do they do it?

from react-rails.

jtmalinowski avatar jtmalinowski commented on July 27, 2024

AFAIK the standard is to wrap the JS file in one huge immediately invoked function and then pass window or global to it as a scope or whatever argument - based on what is undefined
But we have to decide on one system for DI and embrace it everywhere in react-rails!

The problem here is with coffeescript / (c)jsx compilation not with the global scope - putting on my TODO.

from react-rails.

chellberg avatar chellberg commented on July 27, 2024

Is there a workaround for this? I got my global scope issue sorted with components.js and global.Component = Component, but I'm now having this V8::Error. Mine is _ is not defined, which may have something to do with Underscore.js.

Update: I was able to get past that error, but only by requiring the underscore library in components.js. The next errors were related to more libraries referenced in components, and the one I'm stuck on now is Encountered error "ReferenceError: App is not defined" when prerendering...

Are React components supposed to avoid using third party libraries/shared application js code? These components work fine when rendered clientside - is there maybe a better way to give the prerender VM access to the application pipeline javascripts?

from react-rails.

zkilgore avatar zkilgore commented on July 27, 2024

@chellberg I am getting the exact same V8::Error, only with document is not defined instead of the libraries you are talking about.

Would love to hear if anyone has any insight. Thanks!

from react-rails.

chellberg avatar chellberg commented on July 27, 2024

@zkilgore That's one of the ones we ran into - I wanna say it was related to jQuery being unavailable but I'm not 100% sure. The sum of the problems I've encountered makes it seem like the prerenderer is trying to execute the javascript in isolation rather than simulating an actual browser (with a document object, etc) - but then again, I did have to set window.Component = Component to get to this error, so I guess there's at least a window.

from react-rails.

rmosolgo avatar rmosolgo commented on July 27, 2024

I hope this issue was worked out! Server rendering is very different now, please open another issue if you're having a problem with it!

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.