-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement/issue 1088 refactor workers out of SSR builds (#1110)
* production SSR workers refactor WIP * initial draft refactoring for no Workers as part of serving SSR builds * decouple SSR module execution from Workers implementation * enable pre-compiled HTML for templates during SSR * ammed static router spec for execute-route-module * get SSR execution module from config * refactor executeRouteModule signature and fix all specs * update lit renderer per execute module refactoring * pre-bundle SSR entry points * refactor entry file to use runtime import.meta.url * use placholder for SSR page entry point path and replace at write with rollup * expand rollup and lit circular reference TODO comment * clean up console logs and track TODOs * update Renderer plugin docs
- Loading branch information
1 parent
0ff9554
commit 9086bba
Showing
22 changed files
with
202 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { renderToString, renderFromHTML } from 'wc-compiler'; | ||
|
||
async function executeRouteModule({ moduleUrl, compilation, page = {}, prerender = false, htmlContents = null, scripts = [] }) { | ||
const data = { | ||
template: null, | ||
body: null, | ||
frontmatter: null, | ||
html: null | ||
}; | ||
|
||
if (prerender) { | ||
const scriptURLs = scripts.map(scriptFile => new URL(scriptFile)); | ||
const { html } = await renderFromHTML(htmlContents, scriptURLs); | ||
|
||
data.html = html; | ||
} else { | ||
const module = await import(moduleUrl).then(module => module); | ||
const { getTemplate = null, getBody = null, getFrontmatter = null } = module; | ||
|
||
if (module.default) { | ||
const { html } = await renderToString(new URL(moduleUrl), false); | ||
|
||
data.body = html; | ||
} else { | ||
if (getBody) { | ||
data.body = await getBody(compilation, page); | ||
} | ||
} | ||
|
||
if (getTemplate) { | ||
data.template = await getTemplate(compilation, page); | ||
} | ||
|
||
if (getFrontmatter) { | ||
data.frontmatter = await getFrontmatter(compilation, page); | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
|
||
export { executeRouteModule }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,13 @@ | ||
// https://github.com/nodejs/modules/issues/307#issuecomment-858729422 | ||
import { parentPort } from 'worker_threads'; | ||
import { renderToString, renderFromHTML } from 'wc-compiler'; | ||
|
||
async function executeRouteModule({ moduleUrl, compilation, route, label, id, prerender, htmlContents, scripts }) { | ||
const parsedCompilation = JSON.parse(compilation); | ||
const data = { | ||
template: null, | ||
body: null, | ||
frontmatter: null, | ||
html: null | ||
}; | ||
|
||
if (prerender) { | ||
const scriptURLs = JSON.parse(scripts).map(scriptFile => new URL(scriptFile)); | ||
const { html } = await renderFromHTML(htmlContents, scriptURLs); | ||
|
||
data.html = html; | ||
} else { | ||
const module = await import(moduleUrl).then(module => module); | ||
const { getTemplate = null, getBody = null, getFrontmatter = null } = module; | ||
|
||
if (module.default) { | ||
const { html } = await renderToString(new URL(moduleUrl), false); | ||
|
||
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); | ||
} | ||
} | ||
async function executeModule({ executeModuleUrl, moduleUrl, compilation, page, prerender = false, htmlContents = null, scripts = '[]' }) { | ||
const { executeRouteModule } = await import(executeModuleUrl); | ||
const data = await executeRouteModule({ moduleUrl, compilation: JSON.parse(compilation), page: JSON.parse(page), prerender, htmlContents, scripts: JSON.parse(scripts) }); | ||
|
||
parentPort.postMessage(data); | ||
} | ||
|
||
parentPort.on('message', async (task) => { | ||
await executeRouteModule(task); | ||
await executeModule(task); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.