Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit a279fa6

Browse files
committed
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.
1 parent 5a52406 commit a279fa6

File tree

1 file changed

+21
-23
lines changed
  • modules/builders/src/ssr-dev-server

1 file changed

+21
-23
lines changed

modules/builders/src/ssr-dev-server/index.ts

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,24 @@ export function execute(
9292
getAvailablePort(),
9393
).pipe(
9494
switchMap(([br, sr, nodeServerPort]) => {
95-
const server$ = sr.output.pipe(
96-
switchMap(s => {
97-
if (!s.success) {
98-
return of(s);
95+
return combineLatest([br.output, sr.output]).pipe(
96+
// This is needed so that if both server and browser emit close to each other
97+
// we only emit once. This typically happens on the first build.
98+
debounceTime(120),
99+
switchMap(([b, s]) => {
100+
if (!s.success || !b.success) {
101+
return of([b, s]);
99102
}
100103

101104
return startNodeServer(s, nodeServerPort, context.logger).pipe(
102-
mapTo(s),
105+
mapTo([b, s]),
103106
catchError(err => {
104107
context.logger.error(`A server error has occurred.\n${mapErrorToMessage(err)}`);
105108

106109
return EMPTY;
107110
}),
108111
);
109-
}));
110-
111-
return combineLatest([br.output, server$]).pipe(
112-
// This is needed so that if both server and browser emit close to each other
113-
// we only emit once. This typically happens on the first build.
114-
debounceTime(120),
112+
}),
115113
map(([b, s]) => ([
116114
{
117115
success: b.success && s.success,
@@ -265,18 +263,18 @@ async function initBrowserSync(
265263
if (hasPathname) {
266264
// Remove leading slash
267265
bsOptions.scriptPath = p => p.substring(1),
268-
bsOptions.middleware = [
269-
createProxyMiddleware(defaultSocketIoPath, {
270-
target: url.format({
271-
protocol: 'http',
272-
hostname: host,
273-
port: bsPort,
274-
pathname: path,
275-
}),
276-
ws: true,
277-
logLevel: 'silent',
278-
}) as any,
279-
];
266+
bsOptions.middleware = [
267+
createProxyMiddleware(defaultSocketIoPath, {
268+
target: url.format({
269+
protocol: 'http',
270+
hostname: host,
271+
port: bsPort,
272+
pathname: path,
273+
}),
274+
ws: true,
275+
logLevel: 'silent',
276+
}) as any,
277+
];
280278
}
281279
}
282280

0 commit comments

Comments
 (0)