Repository navigation
Conversation
…ader The /status endpoint percent-encodes the project root so the header stays a valid header value, but findDevServerPort still compared it against the raw root. Roots with a space, an accent or a non-latin script - and every Windows root, whose separators are rewritten - never matched, so run-ios/run-android treated the project's own dev server as a foreign process and offered to move to another port. Extract the normalization into a shared normalizeProjectRoot helper and use it in the middleware that produces the header and in both places that compare against it.
|
This shows end to end on Windows 11 with react-native 0.88.1 and Steps to reproduce, in cmd:
Actual result: in step 2, Expected result: step 3 prints This gist, |
Summary
run-ios/run-androidno longer recognise their own already-running dev server when the project path contains a character that has to be percent-encoded (a space, an accent, a non-latin script), or on Windows.Since #2491 the
/statusendpoint no longer sends the raw project root — it sends a normalized, percent-encoded value, because a raw path with non-ASCII characters is not a valid header value (#2279, #2449):That PR updated
getNextPortto apply the same transformation before comparing, butfindDevServerPort— the functionrun-iosandrun-androidactually call first — was left comparing against the raw root:So for a project at
/Users/me/my app, the header says/Users/me/my%20app, the comparison fails, and the CLI treats the user's own bundler as a foreign process. It falls through tohandlePortUnavailable, prompts "Another process is running on port 8081. Use port 8082 instead?", and if the user accepts it starts a second bundler on 8082 and builds the app against that port. The same mismatch happens for any Windows root, since the normalization also rewritesC:\Users\me\projecttoC:/Users/me/project.The normalization is now a single exported helper,
normalizeProjectRoot, used by the middleware that produces the header and by both places that compare against it, so the two sides cannot drift apart again.getNextPortandstatusPageMiddlewarekeep exactly the behaviour they have today — they just call the helper instead of inlining the expression.Note for reviewers: #2839 proposes the opposite change to
getNextPort(dropping the encoding there). That would makegetNextPortfail to match in exactly the cases described above, i.e. the bug this PR fixes, rather than fixing it.Test Plan
New unit tests, run with
yarn jest packages/cli-tools packages/cli-server-api:packages/cli-tools/src/__tests__/findDevServerPort.test.ts— three cases: a running dev server for a root containing a space (the regression), a running dev server for a plain ASCII root (unchanged behaviour), and a different project owning the port (still delegates tohandlePortUnavailable).packages/cli-tools/src/__tests__/normalizeProjectRoot.test.ts— posix path unchanged, space and Cyrillic percent-encoded, Windows path converted to forward slashes.Before the fix, with only the tests applied:
After the fix:
3 passed.The pre-existing
statusPageMiddlewaretests (which assert the encoded header value, including the Cyrillic case added in #2491) still pass unchanged, confirming the middleware refactor is behaviour-preserving.Whole suite:
yarn jest packages→ 57 suites, 319 passed, 1 todo.yarn buildandyarn build:tsare clean, andeslintreports no errors on the touched packages.Checklist
react-nativecheckout (instructions). — verification here was unit tests only; I did not link the change into a localreact-nativecheckout.