Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 68c4620

Browse files
Consider React dev server ready when it starts listening, not when (and if) it compiles successfully
1 parent 296435e commit 68c4620

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Microsoft.AspNetCore.SpaServices.Extensions/ReactDevelopmentServer/ReactDevelopmentServerMiddleware.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ private static async Task<int> StartCreateReactAppServerAsync(
6666
sourcePath, npmScriptName, null, envVars);
6767
npmScriptRunner.AttachToLogger(logger);
6868

69-
Match openBrowserLine;
7069
using (var stdErrReader = new EventedStreamStringReader(npmScriptRunner.StdErr))
7170
{
7271
try
7372
{
74-
openBrowserLine = await npmScriptRunner.StdOut.WaitForMatch(
75-
new Regex("Local:\\s*(http\\S+)", RegexOptions.None, RegexMatchTimeout),
73+
// Although the React dev server may eventually tell us the URL it's listening on,
74+
// it doesn't do so until it's finished compiling, and even then only if there were
75+
// no compiler warnings. So instead of waiting for that, consider it ready as soon
76+
// as it starts listening for requests.
77+
await npmScriptRunner.StdOut.WaitForMatch(
78+
new Regex("Starting the development server", RegexOptions.None, RegexMatchTimeout),
7679
StartupTimeout);
7780
}
7881
catch (EndOfStreamException ex)
@@ -91,8 +94,7 @@ private static async Task<int> StartCreateReactAppServerAsync(
9194
}
9295
}
9396

94-
var uri = new Uri(openBrowserLine.Groups[1].Value);
95-
return uri.Port;
97+
return portNumber;
9698
}
9799
}
98100
}

0 commit comments

Comments
 (0)