Java8 Nashorn failed on React

After my last post about Nashorn and React I ran into some strange problem:

To reproduce it you can checkout this changeset when you look into „src/main/javascript/ui/examples.jsx“ you see some commented out code that fixes the problem. Just comment it in. To start the application, just run „mvn spring-boot:run“ in the root folder.

I have a simple react component:

  1. var FromModel = React.createClass({
  2. getInitialState: function () {
  3. return {msg: 'loading ...'};
  4. },
  5. render: function () {
  6. return (
  7. <div>
  8. <h1>String from model</h1>
  9. <p>BROKEN! :(</p>
  10. </div>
  11. );
  12. }
  13. });

If you try to render this component, Nashorn will correctly check for the „render“ function but then execute the „getInitialState“ function and complain that no valid React component is returned. I tried various variants and can’t find any mistake. So my conclusion is that something internally of React is handled wrong by Nashorn.

2 thoughts on “Java8 Nashorn failed on React

Schreib einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *