Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eliminate SSR page instantiation during graph lifecycle #991

Open
thescientist13 opened this issue Oct 29, 2022 · 0 comments
Open

eliminate SSR page instantiation during graph lifecycle #991

thescientist13 opened this issue Oct 29, 2022 · 0 comments
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) SSR
Milestone

Comments

@thescientist13
Copy link
Member

thescientist13 commented Oct 29, 2022

Overview

In order to build a graph of all pages, Greenwood gets the metadata of SSR based pages, calling functions like getFrontmatter or reading page level configurations like prerender or isolation.

However the SSR route worker is not efficient as it could be since, it will just automatically run all the things, including just blindly generating the page using WCC

async function executeRouteModule({ modulePath, compilation, route, label, id, prerender, htmlContents, scripts }) {
  const parsedCompilation = JSON.parse(compilation);
  const data = {
    template: null,
    body: null,
    frontmatter: null,
    html: null
  };

  if (prerender) {
    ...
  } else {
    const module = await import(pathToFileURL(modulePath)).then(module => module);
    const { getTemplate = null, getBody = null, getFrontmatter = null } = module;

    if (module.default) {
      const { html } = await renderToString(pathToFileURL(modulePath));

      data.body = html;
    } else {
      if (getBody) {
        data.body = await getBody(parsedCompilation, route);
      }
    }

    if (getTemplate) {
      data.template = await getTemplate(parsedCompilation, route);
    }

    if (getFrontmatter) {
      data.frontmatter = await getFrontmatter(parsedCompilation, route, label, id);
    }
  }

  parentPort.postMessage(data);
}

executeRouteModule(workerData);

Details

Basically, all your pages will get alllllllll those functions called, making your API requests, etc. Just for building the graph, nothing other than frontmatter is needed. All this stuff will get built anyone during the build so this is just duplicate / wasted effort.

This is related to some other issues as well

How do we account for options coming out of a page though?
#1206

export const isolation = true;

So we'll definitely want to think of a way to refactor this so develop is a no-op, and this only happens once on build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI enhancement Improve something existing (e.g. no docs, new APIs, etc) SSR
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant