From a279fa64daaa21033309d850f358d4e8e4e7e066 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 10 Mar 2020 09:39:08 +0100 Subject: [PATCH] fix(builders): don't spawn server until browser build finishes In some cases, we spawned the server to early, which caused the views not to be found. This happened when the browser build too a long time. With this change we spawn the server only after both browser and server have emitted. --- modules/builders/src/ssr-dev-server/index.ts | 44 ++++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/modules/builders/src/ssr-dev-server/index.ts b/modules/builders/src/ssr-dev-server/index.ts index e55188275..7c032b4f5 100644 --- a/modules/builders/src/ssr-dev-server/index.ts +++ b/modules/builders/src/ssr-dev-server/index.ts @@ -92,26 +92,24 @@ export function execute( getAvailablePort(), ).pipe( switchMap(([br, sr, nodeServerPort]) => { - const server$ = sr.output.pipe( - switchMap(s => { - if (!s.success) { - return of(s); + return combineLatest([br.output, sr.output]).pipe( + // This is needed so that if both server and browser emit close to each other + // we only emit once. This typically happens on the first build. + debounceTime(120), + switchMap(([b, s]) => { + if (!s.success || !b.success) { + return of([b, s]); } return startNodeServer(s, nodeServerPort, context.logger).pipe( - mapTo(s), + mapTo([b, s]), catchError(err => { context.logger.error(`A server error has occurred.\n${mapErrorToMessage(err)}`); return EMPTY; }), ); - })); - - return combineLatest([br.output, server$]).pipe( - // This is needed so that if both server and browser emit close to each other - // we only emit once. This typically happens on the first build. - debounceTime(120), + }), map(([b, s]) => ([ { success: b.success && s.success, @@ -265,18 +263,18 @@ async function initBrowserSync( if (hasPathname) { // Remove leading slash bsOptions.scriptPath = p => p.substring(1), - bsOptions.middleware = [ - createProxyMiddleware(defaultSocketIoPath, { - target: url.format({ - protocol: 'http', - hostname: host, - port: bsPort, - pathname: path, - }), - ws: true, - logLevel: 'silent', - }) as any, - ]; + bsOptions.middleware = [ + createProxyMiddleware(defaultSocketIoPath, { + target: url.format({ + protocol: 'http', + hostname: host, + port: bsPort, + pathname: path, + }), + ws: true, + logLevel: 'silent', + }) as any, + ]; } }