Skip to content

Regression in fetch-event example using jco 1.10.2 and componentize-js 0.18.0 #625

@rajsite

Description

@rajsite

I had the following example working correctly with jco 1.9.1, componentize-js 0.16.0, wasmtime 31.0.0 in a WSL 2 ubuntu linux environment:

{
  const { addEventListener } = globalThis;

  addEventListener(
    "fetch", (event) =>
    event.respondWith(
      (async () => {
        try {
          console.log('start httpbin request');
          const request = await fetch('https://httpbin.org/json');
          const result = await request.text();
          console.log('finish httpbin request');
          return new Response(`Hello from TypeScript!, result: ${result}`);
        } catch (e) {
          console.error(e);
          return new Response('whoopsies');
        }
      })(),
    ),
  );
}

I could build the example, run with wasmtime serve --addr 0.0.0.0:8000 -S cli=y dist/main.wasm and see output like the following when visited in the browser:

Hello from TypeScript!, result: {
  "slideshow": {
    "author": "Yours Truly", 
    "date": "date of publication", 
    "slides": [
      {
        "title": "Wake up to WonderWidgets!", 
        "type": "all"
      }, 
      {
        "items": [
          "Why <em>WonderWidgets</em> are great", 
          "Who <em>buys</em> WonderWidgets"
        ], 
        "title": "Overview", 
        "type": "all"
      }
    ], 
    "title": "Sample Slide Show"
  }
}

When I upgrade to jco 1.10.2, componentize-js 0.18.0, and keep the same wasmtime 31.0.0 in a WSL 2 ubuntu linux environment I get the following console error when visiting the endpoint with wasmtime serve:

> wasmtime serve --addr 0.0.0.0:8000 -S cli=y dist/main.wasm

Serving HTTP on http://0.0.0.0:8000/
2025-04-02T02:30:26.260665Z ERROR wasmtime_cli::commands::serve: [0] :: error while executing at wasm backtrace:
    0: 0x80fb90 - <unknown>!environ_sizes_get
    1: 0x775799 - <unknown>!<wasm function 12652>
    2: 0x7a05be - <unknown>!<wasm function 12889>

Caused by:
    wasm trap: wasm `unreachable` instruction executed    
error: hyper::Error(User(Service), guest never invoked `response-outparam::set` method

Caused by:
    0: error while executing at wasm backtrace:
           0: 0x80fb90 - <unknown>!environ_sizes_get
           1: 0x775799 - <unknown>!<wasm function 12652>
           2: 0x7a05be - <unknown>!<wasm function 12889>
    1: wasm trap: wasm `unreachable` instruction executed)

I created a successful reproduction and a failing reproduction. In both examples:

  • npm install
  • npm run build
  • npm run start-wasmtime
  • Visit localhost:8000 in the browser

js-app.zip
js-app-fails.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions