jspm / generator

JSPM Import Map Generator
Apache License 2.0
165 stars 21 forks source link

Parallel htmlInject would fail #201

Closed Aslemammad closed 1 year ago

Aslemammad commented 1 year ago

While doing the deno fresh workflow, this handler would fail when requesting the page multiple times:

// await generator.reinstall();

export const handler: Handlers = {
  async GET(req, ctx) {
    const response = await ctx.render();
    const html = (await response.body?.getReader().read())?.value;
    const htmlString = new TextDecoder().decode(html);
    console.log('inject')
    const injectedHtml = await generator.htmlInject(htmlString, {});
    return new Response(injectedHtml, {
      headers: { 'content-type': 'text/html' },
    });
  },
};

By giving this error:

An error occurred during route handling or page rendering. Error: htmlGenerate cannot run alongside
 other install ops
    at Generator.htmlInject (https://ga.jspm.io/npm:@jspm/generator@1.0.2/_/2a0f1be2.js:79:323)
    at GET (file:///home/bagher/oss/jspm/examples/fresh-deno/routes/index.tsx:24:42)
    at async https://deno.land/x/rutt@0.0.13/mod.ts:228:22
    at async Server.#respond (https://deno.land/std@0.150.0/http/server.ts:298:18)

But when I uncomment the first line, it works. I'd like to see the first line removed so we increase the page load speed and cold start.