Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/graaljs-micronaut-react-ssr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test GraalJS React SSR with Micronaut

on:
push:
paths:
- 'graaljs/graaljs-micronaut-react-ssr/**'
- '.github/workflows/graaljs-micronaut-react-ssr.yml'
pull_request:
paths:
- 'graaljs/graaljs-micronaut-react-ssr/**'
- '.github/workflows/graaljs-micronaut-react-ssr.yml'
workflow_dispatch:

permissions:
contents: read

jobs:
run:
name: 'graaljs-micronaut-react-ssr'
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v4

- uses: graalvm/setup-graalvm@v1
with:
java-version: '24.0.2'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'maven'

- name: Build, test, and run Micronaut app
run: |
cd graaljs/graaljs-micronaut-react-ssr
./mvnw --no-transfer-progress clean package
./mvnw --no-transfer-progress mn:run &
mnpid="$!"
sleep 30
curl --fail-with-body --silent --dump-header - -o /dev/null http://localhost:8080
kill $mnpid
3 changes: 2 additions & 1 deletion graaljs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ This directory contains demo applications and guides for [GraalJS](https://www.g
## Demos

- [Minimal Java application that embeds GraalJS](graaljs-starter/)
- [Embed SVG charting library D3.js with GraalJS in Spring Boot](graaljs-spring-boot-d3/)
- [Render SVG charts with D3.js and GraalJS in Spring Boot](graaljs-spring-boot-d3/)
- [Render SVG charts with Recharts, React, and GraalJS in Micronaut](graaljs-micronaut-react-ssr/)

## Guides

Expand Down
16 changes: 16 additions & 0 deletions graaljs/graaljs-micronaut-react-ssr/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Thumbs.db
.DS_Store
.gradle
build/
target/
out/
.micronaut/
.idea
*.iml
*.ipr
*.iws
.project
.settings
.classpath
.factorypath
src/js/node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
31 changes: 31 additions & 0 deletions graaljs/graaljs-micronaut-react-ssr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# React SSR with Micronaut

This project demonstrates how to render [various Recharts examples](https://recharts.org/en-US/examples) in a [Micronaut](https://micronaut.io/) application.
For this, it uses the [React view feature](https://micronaut-projects.github.io/micronaut-views/latest/guide/#react) in Micronaut that enables Server-Side Rendering (SSR) of React components using [GraalJS](https://www.graalvm.org/javascript/).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For this, it uses the [React view feature](https://micronaut-projects.github.io/micronaut-views/latest/guide/#react) in Micronaut that enables Server-Side Rendering (SSR) of React components using [GraalJS](https://www.graalvm.org/javascript/).
It uses the [React view feature](https://micronaut-projects.github.io/micronaut-views/latest/guide/#react) in Micronaut, which enable Server-Side Rendering (SSR) of React components using [GraalJS](https://www.graalvm.org/javascript/).


## Prerequisites

Before you begin, make sure you have the following:

* A bit of time to explore and experiment
* Your favorite text editor or IDE
* JDK 21 or later

## Run the Application

1. Clone the repository:

```bash
git clone https://github.com/graalvm/graal-languages-demos.git
cd graaljs/graaljs-micronaut-react-ssr
```

2. Build and run the Micronaut application:

```bash
./mvnw mn:run
```

3. Open your browser and go to [http://localhost:8080](http://localhost:8080) to view the Recharts examples.
Since the charts are rendered on the server, they work even with JavaScript disabled in the browser.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Since the charts are rendered on the server, they work even with JavaScript disabled in the browser.
As the charts are rendered on the server, they work even if JavaScript is disabled in your browser.


37 changes: 37 additions & 0 deletions graaljs/graaljs-micronaut-react-ssr/aot-jar.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# AOT configuration properties for jar packaging
# Please review carefully the optimizations enabled below
# Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details

# Caches environment property values: environment properties will be deemed immutable after application startup.
cached.environment.enabled=true

# Precomputes Micronaut configuration property keys from the current environment variables
precompute.environment.properties.enabled=true

# Replaces logback.xml with a pure Java configuration
logback.xml.to.java.enabled=true

# Converts YAML configuration files to Java configuration
yaml.to.java.config.enabled=true

# Scans for service types ahead-of-time, avoiding classpath scanning at startup
serviceloading.jit.enabled=true

# Scans reactive types at build time instead of runtime
scan.reactive.types.enabled=true

# Deduces the environment at build time instead of runtime
deduce.environment.enabled=true

# Checks for the existence of some types at build time instead of runtime
known.missing.types.enabled=true

# Precomputes property sources at build time
sealed.property.source.enabled=true

# The list of service types to be scanned (comma separated)
service.types=io.micronaut.context.env.PropertySourceLoader,io.micronaut.inject.BeanConfiguration,io.micronaut.inject.BeanDefinitionReference,io.micronaut.http.HttpRequestFactory,io.micronaut.http.HttpResponseFactory,io.micronaut.core.beans.BeanIntrospectionReference,io.micronaut.core.convert.TypeConverterRegistrar,io.micronaut.context.env.PropertyExpressionResolver

# A list of types that the AOT analyzer needs to check for existence (comma separated)
known.missing.types.list=io.reactivex.Observable,reactor.core.publisher.Flux,kotlinx.coroutines.flow.Flow,io.reactivex.rxjava3.core.Flowable,io.reactivex.rxjava3.core.Observable,io.reactivex.Single,reactor.core.publisher.Mono,io.reactivex.Maybe,io.reactivex.rxjava3.core.Single,io.reactivex.rxjava3.core.Maybe,io.reactivex.Completable,io.reactivex.rxjava3.core.Completable,io.methvin.watchservice.MacOSXListeningWatchService,io.micronaut.core.async.publisher.CompletableFuturePublisher,io.micronaut.core.async.publisher.Publishers.JustPublisher,io.micronaut.core.async.subscriber.Completable

6 changes: 6 additions & 0 deletions graaljs/graaljs-micronaut-react-ssr/micronaut-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
applicationType: default
defaultPackage: com.example
testFramework: junit
sourceLanguage: java
buildTool: maven
features: [app-name, http-client-test, java, java-application, junit, logback, maven, maven-enforcer-plugin, micronaut-aot, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, static-resources, views-react]
Loading
Loading