Re-use randomly selected dev server port for automatic restarts (#72771)
When `next dev` is started with `-p 0` or `PORT=0` – which is probably
unusual in userland, but is the default for our tests – a random port is
selected for the dev server. If the user, after starting the dev server,
then changes the `next.config.js` file, the dev server detects that and
automatically restarts. For the restart, the original port config is
used, resulting in a random port being selected again. This will most
likely be a different port than was selected before, and so reloads in
the browser won't work. It also results in `ERR_CONNECTION_REFUSED`
errors in our tests that use `patchFile` to change the `next.config.js`
content.
To fix that issue, we're now storing the automatically selected port
when the dev server has started initially, and are re-using it for any
subsequent automatic restarts.