Skip to content

*WIP* Feature Proposal Prototype Hono JS, Svelte, NextJs (Cloudflare Worker) ,Website SSR support using StarlingMonkey, Javy - #439

Open
dywongcloud wants to merge 26 commits into
taubyte:mainfrom
dywongcloud:feature/ssr-javy
Open

*WIP* Feature Proposal Prototype Hono JS, Svelte, NextJs (Cloudflare Worker) ,Website SSR support using StarlingMonkey, Javy#439
dywongcloud wants to merge 26 commits into
taubyte:mainfrom
dywongcloud:feature/ssr-javy

Conversation

@dywongcloud

@dywongcloud dywongcloud commented Jun 3, 2026

Copy link
Copy Markdown

Adds a prototype SSR, /api and Svelte, NextJs and Hono adapter that compiles JavaScript and Hono request handlers into Javy/StarlingMonkey WASI modules, packaged as Taubyte SSR handler bundles and executed through the new wasi-stdio ABI.
Streaming, pooling, and env/KV bindings are committed
Adds experimental support for running SvelteKit Cloudflare SSR output through the Taubyte Javy/StarlingMonkey SSR adapter.

This shims the Cloudflare Workers virtual module/runtime globals, passes a Workers-style env/context into fetch-mode apps, and validates dynamic SvelteKit server routes as runnable WASI modules. Static asset serving is currently stubbed via ASSETS and should be wired to Taubyte asset storage separately.
SSR Javy Diagram
This also provides minimal runtime support for Bun and NodeJs
You can try expressjs , Bun.serve() (GET,POST) , need to test and add support for PATCH, DELETE, PUT

Capability Status
Static / prerendered pages ✅ served by the static layer
Dynamic SSR (Web-standard fetch) ✅ Hono, SvelteKit
/api server routes (GET/POST, request.json())
Form actions + cookies
CSRF (Host/scheme forwarding) ✅ same-origin 200 / cross-site 403
Deployable build.zip assembly (--site)
Runtime breadth ✅ URL (incl. opaque), Headers, Request/Response, FormData, Cache API, cloudflare:workers, node:* shims, AsyncLocalStorage
dylanwong@DYWONG-MC0 tau-2 % cd /tmp/exapp && npm i express@4 && cd -
go run ./tools/taubyte-ssr-adapter --mode node --engine starlingmonkey \
  --framework express --entry /tmp/exapp/app.js --out /tmp/express.wasm
wasmtime serve -S cli=y --addr 127.0.0.1:8081 /tmp/express.wasm

added 7 packages, removed 5 packages, and changed 20 packages in 730ms
~/tau-2

  ../../../var/folders/dn/771h7y4j4032nwvhbj8p8hzw0000gn/T/tb-ssr-819668000/bundle.js  1.1mb ⚠️

⚡ Done in 30ms
warning Falling back to componentize-js 0.19.3 because this component requests Preview 2 WASI packages older than 0.2.10. See https://bytecodealliance.github.io/jco/troubleshooting/common-issues.html#componentize-js-0193-fallback for details and upgrade steps.
listening
OK Successfully written /var/folders/dn/771h7y4j4032nwvhbj8p8hzw0000gn/T/tb-ssr-819668000/handler.component.wasm.
taubyte-ssr-adapter: wrote handler (component) /tmp/express.wasm (18697512 bytes)
Serving HTTP on http://127.0.0.1:8081/

Summary

Adds end-to-end support for v8 JavaScript and others like NodeJs and Bun SSR server bundles on Taubyte through a Javy/StarlingMonkey + WASI-stdio execution path, with prototype support for Web-standard frameworks like Hono and the foundation for Next.js edge-style handlers.

This PR wires the SSR framework builder to emit wasi-stdio manifests, packages JS server handlers as handler.wasm.zip, and updates the substrate website runtime path so SSR requests are normalized correctly before being passed into the WASI handler. It also adds a Javy-based adapter mode for app.fetch(Request) -> Response frameworks by injecting minimal Web API polyfills, plus optional Node-compat shims needed by Next.js-style bundles.

What changed

  • Added a shim for the Cloudflare Workers virtual module:

    cloudflare:workers
  • Added an esbuild alias so SvelteKit’s generated Cloudflare worker can resolve cloudflare:workers during bundling.

  • Added minimal Cloudflare runtime compatibility for:

    • env
    • ctx.waitUntil
    • ctx.passThroughOnException
    • caches
    • env.ASSETS
  • Updated fetch-mode bridging so Cloudflare-style handlers receive:

    app.fetch(request, env, ctx)
    WORKER=/Users/dylanwong/Documents/sveltekit/.svelte-kit/cloudflare/_worker.js
    
    go run ./tools/taubyte-ssr-adapter \
      --mode fetch \
      --node \
      --framework sveltekit \
      --entry "$WORKER" \
      --out /tmp/sk.zip
    
    unzip -o /tmp/sk.zip main.wasm -d /tmp
     
    echo '{"method":"GET","url":"/hello"}' | wasmtime /tmp/main.wasm

SSR runtime and request path handling

  • Adds a shared cleanRequestPath helper for SSR website requests.
  • Preserves / correctly instead of accidentally producing //.
  • Supports mounted website paths such as /app by stripping the mount prefix before dispatching to the SSR handler.
  • Preserves meaningful trailing slashes.
  • Adds unit coverage for root, nested, mount-root, and double-slash path cases.

Framework builder integration

  • Marks JavaScript SSR framework manifests as wasi-stdio, matching the Javy runtime model.

  • Updates SSR generation to call the Taubyte SSR adapter to produce both:

    • __taubyte__/handler.wasm.zip
    • __taubyte__/ssr.json
  • Ensures the generated manifest is valid and parseable by the website runtime.

  • Keeps static generation behavior separate from SSR generation.

Next.js asset assembly fixes

  • Refactors zip assembly through a small de-duplicating assetZip helper.

  • Normalizes zip paths to slash-separated clean paths.

  • Adds clean URL support for prerendered Next.js HTML by writing both:

    • about.html
    • about/index.html
  • This lets /about resolve through the existing static directory-index lookup path.

  • Keeps index.html unchanged and avoids duplicate zip entries.

Javy adapter improvements

  • Adds --mode fetch for Web-standard handlers that expose app.fetch(Request) -> Response, such as Hono.

  • Keeps the existing plain JSON handler mode for lightweight polyfill-free handlers.

  • Embeds and injects a minimal Web API runtime for Javy/StarlingMonkey:

    • URL
    • URLSearchParams
    • Headers
    • Request
    • Response
  • Adds serveFetch dispatch in the shim to translate Taubyte’s WASI-stdio request envelope into a Web-standard Request, then serialize the Response back to stdout.

  • Adds a runnable Hono example with static HTML, JSON API, route params, and POST body handling.

Async / event-loop support

  • Updates Javy compilation to prefer event-loop-enabled builds so async handlers and app.fetch() promises drain before the module exits.

  • Tries multiple Javy CLI variants for compatibility across versions:

    • modern javy build -J event-loop=y
    • experimental event-loop flags
    • legacy compile
  • Adds TAUBYTE_JAVY_ARGS override support for custom local Javy invocations.

Node compatibility shims

  • Adds optional --node mode to inject lightweight Node compatibility before the Web API polyfill and app bundle.

  • Provides prototype shims for common edge-runtime expectations:

    • process
    • global
    • Buffer
    • timers
    • queueMicrotask
  • This does not attempt full Node compatibility; it is intended as a bridge for edge-style SSR bundles.

End-to-end Hono runtime coverage

  • Adds a dreaming integration test for a real Hono server bundle running through the substrate SSR path.

  • Verifies:

    • dynamic SSR route rendering
    • /api route rendering
    • static asset serving alongside dynamic SSR routes
  • Includes fixture documentation for rebuilding the Hono main.wasm bundle with the adapter.

Validation

Tested the Hono Javy bundle directly with wasmtime:

go run ./tools/taubyte-ssr-adapter --mode fetch --framework hono \
  --entry ./tools/taubyte-ssr-adapter/example/hono-app.js \
  --out /tmp/h.zip

unzip -o /tmp/h.zip main.wasm -d /tmp

echo '{"method":"GET","url":"/"}' | wasmtime /tmp/main.wasm
echo '{"method":"GET","url":"/api/ping"}' | wasmtime /tmp/main.wasm
echo '{"method":"POST","url":"/api/echo","body":"hi there"}' | wasmtime /tmp/main.wasm

Verified responses include:

{"status":200,"headers":{"content-type":"text/html; charset=UTF-8"},"body":"<h1>Hello from Hono on Taubyte</h1>"}
{"status":200,"headers":{"content-type":"application/json"},"body":"{\"ok\":true,\"runtime\":\"javy\"}"}
{"status":200,"headers":{"content-type":"application/json"},"body":"{\"youSent\":\"hi there\"}"}

Also ran the dreaming integration test:

go test -tags dreaming -run TestWebsiteHono_Dreaming -v ./services/monkey/fixtures/compile/

Result:

--- PASS: TestWebsiteHono_Dreaming
PASS

Notes / limitations

This is still prototype-level framework support. The Web API and Node shims target the common SSR path needed for Hono and edge-style handlers, not full WHATWG or Node conformance. Outbound fetch, streams, filesystem, sockets, and broader Node APIs are intentionally not implemented here and should be added only as real framework requirements appear.

dylanwong@DYWONG-MC0 tau-2 % go test -tags dreaming -run TestWebsiteHono_Dreaming -v ./services/monkey/fixtures/compile/

=== RUN   TestWebsiteHono_Dreaming
 INFO  Stashing assets/QmTMuUb1PHntSwh5Ng6GAA1gP2Aw8rXCvAp2cyKejkYnQv asset as bafybeiczmn5xhod3qn5xnqzexa3ifavqyvk7dzem2oco2rqsiw2nzikwb4
--- PASS: TestWebsiteHono_Dreaming (2.47s)
PASS
ok      github.com/taubyte/tau/services/monkey/fixtures/compile 3.250s

go run ./tools/taubyte-ssr-adapter --mode fetch --framework hono \
  --entry ./tools/taubyte-ssr-adapter/example/hono-app.js --out /tmp/h.zip
unzip -o /tmp/h.zip main.wasm -d /tmp
echo '{"method":"GET","url":"/"}'           | wasmtime /tmp/main.wasm
echo '{"method":"GET","url":"/api/ping"}'   | wasmtime /tmp/main.wasm

  ../../../var/folders/dn/771h7y4j4032nwvhbj8p8hzw0000gn/T/tb-ssr-568520338/bundle.js  67.6kb

⚡ Done in 14ms
taubyte-ssr-adapter: wrote /tmp/h.zip (574212 bytes)
Archive:  /tmp/h.zip
  inflating: /tmp/main.wasm          
{"status":200,"headers":{"content-type":"text/html; charset=UTF-8"},"body":"<h1>Hello from Hono on Taubyte</h1>"}{"status":200,"headers":{"content-type":"application/json"},"body":"{\"ok\":true,\"runtime\":\"javy\"}"}%                                                                      
dylanwong@DYWONG-MC0 tau-2 % git apply runtimebatch.patch                                      
dylanwong@DYWONG-MC0 tau-2 % go run ./tools/taubyte-ssr-adapter --mode fetch --framework hono \
  --entry ./tools/taubyte-ssr-adapter/example/hono-app.js --out /tmp/h.zip
unzip -o /tmp/h.zip main.wasm -d /tmp
echo '{"method":"GET","url":"/blog/hello"}'                  | wasmtime /tmp/main.wasm
echo '{"method":"POST","url":"/api/echo","body":"hi there"}' | wasmtime /tmp/main.wasm

  ../../../var/folders/dn/771h7y4j4032nwvhbj8p8hzw0000gn/T/tb-ssr-691990352/bundle.js  68.2kb

⚡ Done in 16ms
taubyte-ssr-adapter: wrote /tmp/h.zip (574580 bytes)
Archive:  /tmp/h.zip
  inflating: /tmp/main.wasm          
{"status":200,"headers":{},"body":"post: hello"}{"status":200,"headers":{"content-type":"application/json"},"body":"{\"youSent\":\"hi there\"}"}%           

dylanwongtencent added 6 commits June 2, 2026 17:10
…ming tests A real Javy-compiled JS module rendered through Taubyte (static + dynamic + /api).
@dywongcloud dywongcloud changed the title Prototype JavaScript SSR support using Javy, QuickJS, and wazero *WIP* Prototype Hono JS ,Website SSR support using Javy, QuickJS Jun 3, 2026
dylanwongtencent added 3 commits June 2, 2026 21:08
… through the Taubyte Javy/QuickJS SSR adapter.

This shims the Cloudflare Workers virtual module/runtime globals, passes a Workers-style env/context into fetch-mode apps, and validates dynamic SvelteKit server routes as runnable WASI modules. Static asset serving is currently stubbed via ASSETS and should be wired to Taubyte asset storage separately.
@dywongcloud dywongcloud changed the title *WIP* Prototype Hono JS ,Website SSR support using Javy, QuickJS *WIP* Feature Proposal Prototype Hono JS ,Website SSR support using Javy, QuickJS Jun 3, 2026
@dywongcloud dywongcloud changed the title *WIP* Feature Proposal Prototype Hono JS ,Website SSR support using Javy, QuickJS *WIP* Feature Proposal Prototype Hono JS, Svelte (Cloudflare Worker) ,Website SSR support using Javy, QuickJS Jun 3, 2026
@dywongcloud dywongcloud changed the title *WIP* Feature Proposal Prototype Hono JS, Svelte (Cloudflare Worker) ,Website SSR support using Javy, QuickJS *WIP* Feature Proposal Prototype Hono JS, Svelte (Cloudflare Worker) ,Website SSR support using StarlingMonkey, Javy, QuickJS Jun 3, 2026
@dywongcloud dywongcloud changed the title *WIP* Feature Proposal Prototype Hono JS, Svelte (Cloudflare Worker) ,Website SSR support using StarlingMonkey, Javy, QuickJS *WIP* Feature Proposal Prototype Hono JS, Svelte (Cloudflare Worker) ,Website SSR support using StarlingMonkey, Javy Jun 3, 2026
@dywongcloud dywongcloud changed the title *WIP* Feature Proposal Prototype Hono JS, Svelte (Cloudflare Worker) ,Website SSR support using StarlingMonkey, Javy *WIP* Feature Proposal Prototype Hono JS, Svelte, NextJs (Cloudflare Worker) ,Website SSR support using StarlingMonkey, Javy Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant