GithubHelp home page GithubHelp logo

Comments (13)

justin808 avatar justin808 commented on July 23, 2024

This is a general issue:

If we have an error when server rendering, should we:

  1. Log the messages to the client and/or server console. (current behavior of gem, and probably the react-rails gem).
  2. Throw an error on the server side so rails sees the error.
  3. Make the choice of #1 or #2 configurable? with the default being?
    config.throw_on_server_render_error = true

Can anybody confirm the react-rails gem behavior?

CC: @korbin, @lfittl, @andreasklinger, @jbhatab

from react_on_rails.

justin808 avatar justin808 commented on July 23, 2024

I opened this issue to find out what react-rails is doing: reactjs/react-rails#386

from react_on_rails.

justin808 avatar justin808 commented on July 23, 2024

Also, could we release the gem as 1.0 with the current behavior (logging, either on server or both server/client) and then change that to throw on the server side?

from react_on_rails.

justin808 avatar justin808 commented on July 23, 2024

This is what react-rails is doing:

https://github.com/reactjs/react-rails/blob/master/lib/react/server_rendering/exec_js_renderer.rb#L13

      def render(component_name, props, prerender_options)
        render_function = prerender_options.fetch(:render_function, "renderToString")
        js_code = <<-JS
          (function () {
            #{before_render(component_name, props, prerender_options)}
            var result = ReactDOMServer.#{render_function}(React.createElement(#{component_name}, #{props}));
            #{after_render(component_name, props, prerender_options)}
            return result;
          })()
        JS
        @context.eval(js_code).html_safe
      rescue ExecJS::ProgramError => err
        raise React::ServerRendering::PrerenderError.new(component_name, props, err)
      end

We're wrapping the code in a try block and logging errors nicely.

from react_on_rails.

lfittl avatar lfittl commented on July 23, 2024

@justin808 Just a heads up - we've moved to a different setup that uses a node server for server-side rendering, communicating through a unix domain socket as needed (@korbin has all the details if you're curious).

So it probably doesn't make sense to keep CCing us on this repository, although I appreciate you working on this! :)

from react_on_rails.

justin808 avatar justin808 commented on July 23, 2024

@lfittl @korbin mentioned that to me. Ideally, we'll be able to make execjs swappable with the node technique. When you get an error in server rendering using your technique, do you convert the JS error to throw an exception in Ruby?

from react_on_rails.

lfittl avatar lfittl commented on July 23, 2024

@justin808 I think in the context of this PR, we're not doing this right now (since almost none/none of our code is using the react router yet).

We do log errors to an external provider, but we don't do any special logic based on the type of error.

from react_on_rails.

jbhatab avatar jbhatab commented on July 23, 2024

@justin808 So the default behavior is throwing a client side error and you'd like to add a ruby side error?

from react_on_rails.

justin808 avatar justin808 commented on July 23, 2024

@jbhatab We are only logging right now. Trivial for us to have an option to throw if there's an error in server rendering.

from react_on_rails.

jbhatab avatar jbhatab commented on July 23, 2024

@justin808 logging on the ruby side? I think logging the issue on ruby and javascript side is ideal without breaking things. Now does the component still render client side if it breaks server side?

from react_on_rails.

justin808 avatar justin808 commented on July 23, 2024

We log to server log and client console. Also, I think we display the error message in html anyway to make it super obvious. Some people might want to do a redirect and have other error handling. There's a slight security risk in that error could contain sensitive data and we shouldn't be sending it to the client.

from react_on_rails.

jbhatab avatar jbhatab commented on July 23, 2024

I like the idea of an html error.

from react_on_rails.

robwise avatar robwise commented on July 23, 2024

Implemented in #68

from react_on_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.