Improve Vite resource timeouts

This commit is contained in:
Drew Powers 2021-10-28 13:20:14 -06:00
parent 577d912b8e
commit c4d7dcb7f6
2 changed files with 9 additions and 5 deletions

View file

@ -151,7 +151,6 @@ export class AstroDevServer {
info(this.logging, 'astro', msg.devHost({ host: `http://${this.hostname}:${this.port}` })); info(this.logging, 'astro', msg.devHost({ host: `http://${this.hostname}:${this.port}` }));
resolve(); resolve();
}); });
this.httpServer?.on('error', onError);
}; };
const onError = (err: NodeJS.ErrnoException) => { const onError = (err: NodeJS.ErrnoException) => {
@ -170,6 +169,7 @@ export class AstroDevServer {
}; };
listen(); listen();
this.httpServer?.on('error', onError);
}); });
} }

View file

@ -365,13 +365,17 @@ export async function renderToString(result: SSRResult, componentFactory: AstroC
const uniqueElements = (item: any, index: number, all: any[]) => { const uniqueElements = (item: any, index: number, all: any[]) => {
const props = JSON.stringify(item.props); const props = JSON.stringify(item.props);
const children = item.children; const children = item.children;
return index === all.findIndex(i => JSON.stringify(i.props) === props && i.children == children) return index === all.findIndex((i) => JSON.stringify(i.props) === props && i.children == children);
} };
export async function renderPage(result: SSRResult, Component: AstroComponentFactory, props: any, children: any) { export async function renderPage(result: SSRResult, Component: AstroComponentFactory, props: any, children: any) {
const template = await renderToString(result, Component, props, children); const template = await renderToString(result, Component, props, children);
const styles = Array.from(result.styles).filter(uniqueElements).map((style) => renderElement('style', style)); const styles = Array.from(result.styles)
const scripts = Array.from(result.scripts).filter(uniqueElements).map((script) => renderElement('script', script)); .filter(uniqueElements)
.map((style) => renderElement('style', style));
const scripts = Array.from(result.scripts)
.filter(uniqueElements)
.map((script) => renderElement('script', script));
return template.replace('</head>', styles.join('\n') + scripts.join('\n') + '</head>'); return template.replace('</head>', styles.join('\n') + scripts.join('\n') + '</head>');
} }