airbnb / hypernova

A service for server-side rendering your JavaScript views
MIT License
5.82k stars 207 forks source link

Rails Action Cache with Hypernova #122

Open gbateman opened 6 years ago

gbateman commented 6 years ago

I was trying to implement action caching using actionpack-action_caching but because of how hypernova works with render tokens, the cached result is just the render token. Furthermore, it is clearly useless to call the after action after returning such a result, because there were no calls to render_react_component if the result was cached. It would be nice if there was a supported way to enable caching on hypernova rendered components.

Currently I am storing the results of @hypernova_batch.submit! in the rails cache and then manually replacing the batch tokens from the cached results in an after action, but this method is not easy to abstract, and feels unclean.

ljharb commented 6 years ago

I'm not familiar with how action caching works, but I'd assume it would need to run after all filters - and hypernova runs in an around_filter. If it's not doing that, then it's probably caching the wrong thing in a number of cases.

gbateman commented 6 years ago

Yeah, it seems like action caching takes the result from before after_filters though - not what hypernova could do to get around that if anything

ljharb commented 6 years ago

I don't think there's anything; it seems like a flaw/bug in action cache, tbh.