Closed
Description
We need to pass some ruby context to the ruby racer engine during the server side rendering process. This is a very powerful capability which allows us to access server models during pre-rendering.
I propose the following solution:
-
in the prerendering options allow this:
prerender: {context: {some_context: some_object, other_context: some_other_object}, static: true}
-
each of the context values is sent to therubyracer(v8) engine using the context key.
Of course it requires therubyracer.
I have the following code in a branch that implements this and would be happy to do a PR:
module React
module ServerRendering
class SprocketsRenderer
...
def render(component_name, props, prerender_options)
if prerender_options.is_a? Hash
if ExecJS.runtime.name == "(V8)" and prerender_options[:context]
raise PrerenderError.new(component_name, props, "you must use 'therubyracer' with the prerender[:context] option") unless ExecJS.runtime.name == "(V8)"
else
prerender_options[:context].each { |key, value| @context.instance_variable_get("@v8_context")[key] = value }
prerender_options = prerender_options[:static] ? :static : true
end
end
...
Metadata
Metadata
Assignees
Labels
No labels