ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
96 stars 9 forks source link

Enhancement/issue 1088 refactor Workers out of SSR builds #1110

Closed thescientist13 closed 1 year ago

thescientist13 commented 1 year ago

Related Issue

resolves #1088

Summary of Changes

  1. Refactor Workers out of serving SSR pages
  2. Pre-compile static HTML templates as local variables at build time
  3. Refactor renderer plugin to just be a function (not tied to Workers implementation)

References

TODO

  1. [x] confirm static templating works, e.g. src/templates/
  2. [x] Will still need the concept of an executeModule for custom implementations like Lit (do we have to handle a renderer and an adapter plugin at the same time?) and for development
  3. [x] get executeRouteModule from config
  4. [x] simplify executeModule signature (pass in entire page)
  5. [x] Update static router serve spec per new implementation
  6. [x] refactor lit renderer and get all specs passing
  7. [x] Is it OK to reference executeModuleUrl in our wrapper bundles? Can we bundle down into one file instead?
  8. [x] Likely we don't need to output templates/ dir anymore?
  9. [x] What about os / thread pooling for prerendering? - deferred to https://github.com/ProjectEvergreen/greenwood/issues/970 and #1117
  10. [x] Docs
    • prerender plugin
    • getTemplate is a "static" function - deprecating anyways?
    • make a discussion for how best encapsulate SSR?
  11. [x] Test in adapter demo repos
  12. [x] Test in Benchmarking repo - deferred to https://github.com/ProjectEvergreen/greenwood/issues/970
  13. [x] Clean up TODOs / console logs

Questions

  1. [x] getTemplate has to be a "static" function (for now) but maybe we will deprecating anyways as part of #955 ? - deferred to https://github.com/ProjectEvergreen/greenwood/issues/1008
  2. [x] Create a discussion to evaluate alternatives to Workers, or making it opt-in? Or maybe I'm just over thinking it? Would be good to cross reference as part of #1008 - https://github.com/ProjectEvergreen/greenwood/discussions/1117
  3. [x] Can we ever "bundle down" to a single file executable for SSR pages? - https://github.com/ProjectEvergreen/greenwood/issues/1118
  4. [x] How to handle something like Netlify which needs custom handling for import.meta.url? - deferred to - https://github.com/ProjectEvergreen/greenwood/issues/1008#issuecomment-1606287535

    await fs.writeFile(outputUrl, `
      import 'wc-compiler/src/dom-shim.js';
      import Page from './_${filename}';
    
      export async function handler(request) {
        console.log('${JSON.stringify(page)}');          
    
        let initBody = ${body};
        let initHtml = \`${html}\`;
    
        if (!initBody) {
          const page = new Page();
          await page.connectedCallback();
    
          initHtml = initHtml.replace(\/\<content-outlet>(.*)<\\/content-outlet>\/s, page.innerHTML);
        }
    
        return new Response(initHtml);
      }
    `);