Skip to content

Caching of components with prerender:true #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amir20 opened this issue Nov 20, 2015 · 5 comments
Closed

Caching of components with prerender:true #407

amir20 opened this issue Nov 20, 2015 · 5 comments

Comments

@amir20
Copy link

amir20 commented Nov 20, 2015

I apologize if this question has been asked before. Does it make sense for prerender to take about 700ms locally but only 80ms when disabled?

I looked at the code and found that it doesn't look it is being cached. Could it be cached in production mode?

If it is already cached and I missed it, then D'OH!

@amir20
Copy link
Author

amir20 commented Nov 20, 2015

Hmm looks like there was some discussion at #156 (comment)

Would it make sense to just cache the output always? If parameters don't change then I think yes.

@rmosolgo
Copy link
Member

Make sure you have therubyracer, it's a much more efficient ExecJS backend than NodeJS.

Regarding caching, how about applying the cache in your view? For example:

<% cache ["v1", todo] do %>
  <%= react_component("Todo", {todo: todo}, prerender: true %>
<% end %>

(from DHH's key-based cache expiration)

I figure, if there's already a robust caching system in Rails, why add another (more bug-prone) one here?! 😬

@amir20
Copy link
Author

amir20 commented Nov 20, 2015

I completely agree. If the cache already exists in rails, then why recreate it.

Regarding your other suggestion...I did try therubyracer. However, I get a weird error that I have never seen before.

18:12:11 web.1     | ActionView::Template::Error (Encountered error "Error: Invariant Violation: renderToString(): You must pass a valid ReactElement." when prerendering PlayerPanel with {}
18:12:11 web.1     | invariant ((execjs):1094:16)
18:12:11 web.1     | Object.renderToString ((execjs):18767:84)
18:12:11 web.1     | (execjs):3:41
18:12:11 web.1     | (execjs):15:13

I googled for a while and I couldn't find anything. My project is open sourced at https://github.com/amir20/radiowitter so you could try adding therubyracer.

Meanwhile, I will use cache but if you know why that error happens, then I would really appreciate it!

@amir20
Copy link
Author

amir20 commented Nov 20, 2015

So I have removed every line until it worked and the culprit is import 'babel-polyfill'. However, I need it because I do use yield in my code. Has anybody else seen this with therubyracer?

@rmosolgo
Copy link
Member

rmosolgo commented Dec 9, 2016

Sorry about the incompatibility, I know ExecJS has some limitations! I hope you found something that worked for you.

@rmosolgo rmosolgo closed this as completed Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants