-
Notifications
You must be signed in to change notification settings - Fork 10
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
make sure to pass SSR page script as part of WCC script dependencies #989
make sure to pass SSR page script as part of WCC script dependencies #989
Conversation
Okay, so after noticing the above where the HTML for the page only was getting duplicated twice, I found out what was happening. When we prerender, we are doing the page SSR work twice unfortunately. async function preRenderCompilationWorker(compilation, workerPrerender) {
const pages = compilation.graph.filter(page => !page.isSSR);
const outputDir = compilation.context.scratchDir;
console.info('pages to generate', `\n ${pages.map(page => page.route).join('\n ')}`);
await Promise.all(pages.map(async (page) => {
const { outputPath, route } = page;
const outputPathDir = path.join(outputDir, route);
const htmlResource = compilation.config.plugins.filter((plugin) => {
return plugin.name === 'plugin-standard-html';
}).map((plugin) => {
return plugin.provider(compilation);
})[0];
let html;
html = (await htmlResource.serve(page.route)).body; // SSR runs once here already for the page itself
html = (await interceptPage(compilation, html, route)).body;
const root = htmlparser.parse(html, {
...
});
const headScripts = root.querySelectorAll('script')
...
});
await new Promise((resolve, reject) => {
const worker = new Worker(workerPrerender.workerUrl, {
workerData: {
modulePath: null,
compilation: JSON.stringify(compilation),
route,
prerender: true,
htmlContents: html,
scripts: JSON.stringify(headScripts)
}
});
worker.on('message', (result) => {
if (result.html) {
html = result.html; // and now will run again, with the page components already having been rendered once above already
}
resolve();
});
worker.on('error', reject);
worker.on('exit', (code) => {
if (code !== 0) {
reject(new Error(`Worker stopped with exit code ${code}`));
}
});
});
....
}));
} So technically, by withholding the src/pages/index.js from WCC, it was not allowing those page level scripts to register, so that they wouldn't re-render while inside WCC. The reason this seems to be setup this way is so that template level scripts, like
|
af27313
to
b87d512
Compare
this was resolved as part of #1212 |
Related Issue
resolves #988
Summary of Changes