{"id":18714939,"url":"https://github.com/griffio/spring-boot-web-nashorn","last_synced_at":"2025-04-12T13:05:24.032Z","repository":{"id":29727573,"uuid":"33270799","full_name":"griffio/spring-boot-web-nashorn","owner":"griffio","description":"Feasibility of rendering React 16.x templates from Nashorn with babel-standalone, with Spring Boot and Kotlin","archived":false,"fork":false,"pushed_at":"2018-02-21T11:55:34.000Z","size":372,"stargazers_count":26,"open_issues_count":0,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-26T07:42:49.226Z","etag":null,"topics":["kotlin","nashorn","react","rendering-react","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/griffio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-01T20:25:22.000Z","updated_at":"2024-08-14T15:09:13.000Z","dependencies_parsed_at":"2022-08-27T16:23:18.128Z","dependency_job_id":null,"html_url":"https://github.com/griffio/spring-boot-web-nashorn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griffio%2Fspring-boot-web-nashorn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griffio%2Fspring-boot-web-nashorn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griffio%2Fspring-boot-web-nashorn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/griffio%2Fspring-boot-web-nashorn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/griffio","download_url":"https://codeload.github.com/griffio/spring-boot-web-nashorn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248571885,"owners_count":21126522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kotlin","nashorn","react","rendering-react","spring-boot"],"created_at":"2024-11-07T13:06:55.415Z","updated_at":"2025-04-12T13:05:23.976Z","avatar_url":"https://github.com/griffio.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Render React template from Nashorn\n\nThis is just an experiment tracking the feasibility of using v.latest React in Nashorn.\n\nRecent Spring Developer presentation: [isomorphic-templating-with-spring-boot-nashorn-and-react](http://www.slideshare.net/SpringCentral/isomorphic-templating-with-spring-boot-nashorn-and-react)\n\nReact 16.1.x\n\n0.13.x leaned on JSX Transformer to perform standalone JSX translation; this was removed in current React versions.\nA BabelJs environment is needed to compile JSX.\nHowever, BabelJs also needs NodeJs environment, so use a babel-standalone that bundles all required modules.\n\n### Now in 4.2.0.RELEASE\n\n[Jira SPR-12266](https://jira.spring.io/browse/SPR-12266)\n[Spring Framework SPR-12266](https://github.com/sdeleuze/spring-framework/tree/SPR-12266)\n\nUse jdk-8u72-ea or higher. https://jdk8.java.net/download.html\n\nEarly access fix for: Method code too large in Babel - https://bugs.openjdk.java.net/browse/JDK-8135190\n\nNote:- this is also the case with Typescript https://github.com/Microsoft/TypeScript/issues/1789\n\n### Spring Boot with ReactJs templates with Nashorn and Kotlin 1.2.x\n\nReact 16.1.x requires BabelJs environment to compile JSX\nBabelJs requires nodejs api dependencies.\n\nHowever, a stand-alone build of Babel for use in non-Node.js environments used as https://babeljs.io/docs/usage/browser/ now removed.\nhttps://github.com/Daniel15/babel-standalone\n\nThe package create-react-class is used as Java8 Nashorn is ECMAScript 5.x as per https://reactjs.org/docs/react-without-es6.html\n\n[Nashorn Extensions](https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions) - allow map support\n\n~~~javascript\n\nglobal = {};\nconsole = {};\nconsole.debug = print;\nconsole.warn = print;\nconsole.log = print;\nconsole.error = print;\n\nfunction render(template, model) {\n    var data = {};\n    for (var k in model) {\n        if (model[k] instanceof Java.type(\"java.lang.Iterable\")) {\n             data[k] = Java.from(model[k]);\n        } else {\n            data[k] = model[k];\n        }\n    }\n    var element = React.createElement(eval(template), data);\n    return ReactDOMServer.renderToStaticMarkup(element);\n}\n\nfunction renderJsx(template, model) {\n    var jsTemplate = Babel.transform(template, { presets: ['react'] }).code;\n    return render(jsTemplate, model);\n}\n\n~~~\n\n[Notes on Spring Boot](http://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-boot-application.html)\n\nTest with JDK \n\n~~~\n./gradlew test\n~~~\n\nApplication\n\n~~~\n./gradlew bootRun\n~~~\n\nRoute\n\nhttp://localhost:8080/about.html\n\nRendered from\n\nhttps://github.com/griffio/spring-boot-web-nashorn/blob/master/src/main/resources/templates/about.jsx\n\n==============\n\n### Kotlin 1.2.x\n\nkotlin_version=1.2.21\n\nbasic gradle (4.x) build template for Java 8\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgriffio%2Fspring-boot-web-nashorn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgriffio%2Fspring-boot-web-nashorn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgriffio%2Fspring-boot-web-nashorn/lists"}