Я пытаюсь использовать параметр prerender для реагирования на компоненты рельсов, как это:
<%= react_component("Welcome", props: @welcome_props, prerender: true) %>
, но возвращается следующее:
12:56:37 web.1 | ActionView::Template::Error (ERROR in SERVER PRERENDERING
12:56:37 web.1 | Encountered error: "uninitialized constant #<Class:0x000055590018f6d8>::ExecJS"
12:56:37 web.1 | when prerendering Welcome with props: { name: Oussama }
12:56:37 web.1 |
12:56:37 web.1 | code:
12:56:37 web.1 |
12:56:37 web.1 | (function() {
12:56:37 web.1 | var railsContext = {"railsEnv":"development","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":"11.3.0","rorPro":false,"href":"https://reynhal.local:3000/","location":"/","scheme":"https","host":"reynhal.local","port":3000,"pathname":"/","search":null,"httpAcceptLanguage":"en-US,en;q=0.5","serverSide":true};
12:56:37 web.1 | ReactOnRails.clearHydratedStores();
12:56:37 web.1 |
12:56:37 web.1 | var props = {};
12:56:37 web.1 | return ReactOnRails.serverRenderReactComponent({
12:56:37 web.1 | name: 'Welcome',
12:56:37 web.1 | domNodeId: 'Welcome-react-component-fe389b96-5b9c-4161-af32-0c81ffb2f2bf',
12:56:37 web.1 | props: props,
12:56:37 web.1 | trace: true,
12:56:37 web.1 | railsContext: railsContext
12:56:37 web.1 | });
12:56:37 web.1 | })()
, когда я поворачиваю параметр prerender выключен, все работает. код компонента такой:
import PropTypes from 'prop-types';
import React from 'react';
export default class Welcome extends React.Component {
static propTypes = {
name: PropTypes.string.isRequired, // this is passed from the Rails view
};
/**
* @param props - Comes from your rails view.
*/
constructor(props) {
super(props);
// How to set initial state in ES6 class syntax
// https://reactjs.org/docs/state-and-lifecycle.html#adding-local-state-to-a-class
this.state = { name: 'Hello' };
}
updateName = (name) => {
this.setState({ name });
};
render() {
return (
<div>
<h3>
Hello, {this.state.name}!
</h3>
<hr />
<form >
<label htmlFor="name">
Say hello to:
</label>
<input
id="name"
type="text"
value={this.state.name}
onChange={(e) => this.updateName(e.target.value)}
/>
</form>
</div>
);
}
}
и код контроллера такой:
class HomeController < ApplicationController
layout "welcome"
def index
@welcome_props = {}
end
end
код основан на коде по умолчанию, созданном response_on_rails, версия узла 13.3 и gemfile of response_on_rails у меня есть 11.3.0 и npm версия 6.4.0