kvnang / workers-og

An `og:image` (social card) generator that is fast, browser-less (no Puppeteer), and capable of running on the edge. This package is designed to be used with Cloudflare Workers (but may be used elsewhere), with the simple API inspired by `@vercel/og`.
MIT License
194 stars 18 forks source link

Exception "The script will never generate a response" in Remix but not a "vanilla" worker #14

Open shayypy opened 3 months ago

shayypy commented 3 months ago

Hello, I'm getting this strange error from Miniflare when using Remix (classic compiler, template here, not Vite).

This is my entire loader (I just want to generate a small transparent image):

// route: routes/image.$width[.]png.ts
// visit url: /image/400.png
export const loader = async ({ request, params }: LoaderArgs) => {
  const { width } = zxParseParams(params, {
    width: zx.IntAsString.refine((v) => v >= 300 && v <= 400),
  });

  return new ImageResponse(`<div style="display:none"></div>`, {
    width,
    height: 1,
    format: "png",
  });
};

This works fine in a brand new worker with no framework installed, however:

export default {
  async fetch(request, env, ctx): Promise<Response> {
    return new ImageResponse(`<div style="display:none"></div>`, {
      width: 400,
      height: 1,
      format: "png",
    });
  },
}

You might think this is to do with some middleware from the Remix server, but I don't think so, as this also happens if you uproot everything in server.ts and replace it with the above "vanilla" code. What's going on? All I can glean from the error is that a promise is hanging and Miniflare has detected that, but I'm not sure how to prove/resolve that. Any help is greatly appreciated!

boehs commented 2 months ago

Did you figure it out?

shayypy commented 2 months ago

No unfortunately, I'm just hosting this route on a different worker instead. It actually makes more sense for my use case, but I kept this issue open since it's not actually resolved.