Skip to content

Commit eb99727

Browse files
huntiefacebook-github-bot
authored andcommitted
Fix start command exit behaviour (#39788)
Summary: Hotfix for exiting `npx react-native start` when a session is connected. Partially reverts D49422206. This lines back up with the original RN CLI and Expo implementations — explicitly calling `process.exit()`. We still aim to follow this up with graceful server shutdown. Changelog: [Internal] Reviewed By: lunaleaps Differential Revision: D49880226
1 parent 113de6e commit eb99727

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

packages/community-cli-plugin/src/commands/start/attachKeyHandlers.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@ import {logger} from '@react-native-community/cli-tools';
1515
import chalk from 'chalk';
1616
import execa from 'execa';
1717
import fetch from 'node-fetch';
18-
import readline from 'readline';
1918
import {KeyPressHandler} from '../../utils/KeyPressHandler';
2019

2120
const CTRL_C = '\u0003';
2221
const CTRL_D = '\u0004';
2322

2423
export default function attachKeyHandlers({
2524
cliConfig,
26-
serverInstance,
2725
devServerUrl,
2826
messageSocket,
2927
}: {
3028
cliConfig: Config,
3129
devServerUrl: string,
32-
serverInstance: http$Server | https$Server,
3330
messageSocket: $ReadOnly<{
3431
broadcast: (type: string, params?: Record<string, mixed> | null) => void,
3532
...
@@ -40,10 +37,6 @@ export default function attachKeyHandlers({
4037
return;
4138
}
4239

43-
readline.emitKeypressEvents(process.stdin);
44-
// $FlowIgnore[prop-missing]
45-
process.stdin.setRawMode(true);
46-
4740
const execaOptions = {
4841
env: {FORCE_COLOR: chalk.supportsColor ? 'true' : 'false'},
4942
};
@@ -88,16 +81,14 @@ export default function attachKeyHandlers({
8881
case CTRL_C:
8982
case CTRL_D:
9083
logger.info('Stopping server');
91-
listener?.({pause: true});
92-
serverInstance.close(() => {
93-
process.emit('SIGINT');
94-
process.exit();
95-
});
84+
keyPressHandler.stopInterceptingKeyStrokes();
85+
process.emit('SIGINT');
86+
process.exit();
9687
}
9788
};
9889

9990
const keyPressHandler = new KeyPressHandler(onPress);
100-
const listener = keyPressHandler.createInteractionListener();
91+
keyPressHandler.createInteractionListener();
10192
keyPressHandler.startInterceptingKeyStrokes();
10293

10394
logger.log(

packages/community-cli-plugin/src/commands/start/runServer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ async function runServer(
137137
attachKeyHandlers({
138138
cliConfig: ctx,
139139
devServerUrl,
140-
serverInstance,
141140
messageSocket: messageSocketEndpoint,
142141
});
143142
}

0 commit comments

Comments
 (0)