Comments (13)
This is a general issue:
If we have an error when server rendering, should we:
- Log the messages to the client and/or server console. (current behavior of gem, and probably the react-rails gem).
- Throw an error on the server side so rails sees the error.
- 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.
I opened this issue to find out what react-rails is doing: reactjs/react-rails#386
from react_on_rails.
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.
This is what react-rails is doing:
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.
@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.
@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.
@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.
@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.
@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.
@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.
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.
I like the idea of an html error.
from react_on_rails.
Implemented in #68
from react_on_rails.
Related Issues (20)
- `react_component` and `react_component_hash` raises pack not found warning even when corresponding chunks are present in `manifest`
- Refactor `lib/react_on_rails/helper.rb` HOT 1
- ./bin/dev is not executable in default HOT 1
- How to create Procfile.dev? HOT 2
- bin/dev: Please ensure `Procfile.dev` exist in your project! HOT 3
- How do I stop react_on_rails from generating packs? HOT 12
- How to disable sourcemap? HOT 1
- Update documentation based on Shakapacker 7 HOT 1
- Outdated link in the documentation redirects to Non-Found Page HOT 1
- Client rendering crashes when configuring `optimization.runtimeChunk` to `multiple` HOT 3
- Include Ruby 3 and node 18 to CI workflows HOT 2
- Pack generation runs with nil components_subdirectory HOT 3
- Concurrency performance HOT 3
- When server-bundle.js register a lot of server render components making the server render performance reduce big HOT 2
- Remove `request_digest` from `render_options` for version 14 HOT 1
- Convert spec/dummy/client to Typescript
- Change primary branch name from `master` to `main` HOT 2
- Add support for Vite
- Fix CI failure
- Server side rendering window behaves differently than Node.js? HOT 7
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_on_rails.