@react-native/dev-middleware 0.77.0-nightly-20241121-550b0c0ed → 0.77.0-nightly-20241122-e4d8c9678

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,10 @@ declare class Device {
37
37
  handleDebuggerConnection(
38
38
  socket: WS,
39
39
  pageId: string,
40
- metadata: Readonly<{ userAgent: string | null }>
40
+ $$PARAM_2$$: Readonly<{
41
+ debuggerRelativeBaseUrl: URL;
42
+ userAgent: string | null;
43
+ }>
41
44
  ): void;
42
45
  dangerouslyGetSocket(): WS;
43
46
  }
@@ -167,6 +167,7 @@ class Device {
167
167
  oldDebugger.socket.removeAllListeners();
168
168
  this.#deviceSocket.close();
169
169
  this.handleDebuggerConnection(oldDebugger.socket, oldDebugger.pageId, {
170
+ debuggerRelativeBaseUrl: oldDebugger.debuggerRelativeBaseUrl,
170
171
  userAgent: oldDebugger.userAgent,
171
172
  });
172
173
  }
@@ -185,16 +186,19 @@ class Device {
185
186
  return [...this.#pages.values()];
186
187
  }
187
188
  }
188
- handleDebuggerConnection(socket, pageId, metadata) {
189
+ handleDebuggerConnection(
190
+ socket,
191
+ pageId,
192
+ { debuggerRelativeBaseUrl, userAgent }
193
+ ) {
189
194
  const page =
190
195
  pageId === REACT_NATIVE_RELOADABLE_PAGE_ID
191
196
  ? this.#createSyntheticPage()
192
197
  : this.#pages.get(pageId);
193
198
  if (!page) {
194
199
  debug(
195
- `Got new debugger connection for page ${pageId} of ${
196
- this.#name
197
- }, but no such page exists`
200
+ `Got new debugger connection via ${debuggerRelativeBaseUrl.href} for ` +
201
+ `page ${pageId} of ${this.#name}, but no such page exists`
198
202
  );
199
203
  socket.close();
200
204
  return;
@@ -203,17 +207,21 @@ class Device {
203
207
  this.#terminateDebuggerConnection();
204
208
  this.#deviceEventReporter?.logConnection("debugger", {
205
209
  pageId,
206
- frontendUserAgent: metadata.userAgent,
210
+ frontendUserAgent: userAgent,
207
211
  });
208
212
  const debuggerInfo = {
209
213
  socket,
210
214
  prependedFilePrefix: false,
211
215
  pageId,
212
- userAgent: metadata.userAgent,
216
+ userAgent: userAgent,
213
217
  customHandler: null,
218
+ debuggerRelativeBaseUrl,
214
219
  };
215
220
  this.#debuggerConnection = debuggerInfo;
216
- debug(`Got new debugger connection for page ${pageId} of ${this.#name}`);
221
+ debug(
222
+ `Got new debugger connection via ${debuggerRelativeBaseUrl.href} for ` +
223
+ `page ${pageId} of ${this.#name}`
224
+ );
217
225
  if (this.#debuggerConnection && this.#createCustomMessageHandler) {
218
226
  this.#debuggerConnection.customHandler = this.#createCustomMessageHandler(
219
227
  {
@@ -262,7 +270,7 @@ class Device {
262
270
  const debuggerRequest = JSON.parse(message);
263
271
  this.#deviceEventReporter?.logRequest(debuggerRequest, "debugger", {
264
272
  pageId: this.#debuggerConnection?.pageId ?? null,
265
- frontendUserAgent: metadata.userAgent,
273
+ frontendUserAgent: userAgent,
266
274
  prefersFuseboxFrontend: this.#isPageFuseboxFrontend(
267
275
  this.#debuggerConnection?.pageId
268
276
  ),
@@ -509,11 +517,14 @@ class Device {
509
517
  REWRITE_HOSTS_TO_LOCALHOST.has(this.#deviceRelativeBaseUrl.hostname)
510
518
  ) {
511
519
  const debuggerRelativeURL = new URL(sourceMapURL.href);
512
- debuggerRelativeURL.hostname = "localhost";
520
+ debuggerRelativeURL.host =
521
+ debuggerInfo.debuggerRelativeBaseUrl.host;
522
+ debuggerRelativeURL.protocol =
523
+ debuggerInfo.debuggerRelativeBaseUrl.protocol;
513
524
  serverRelativeUrl.host = this.#serverRelativeBaseUrl.host;
514
525
  serverRelativeUrl.protocol = this.#serverRelativeBaseUrl.protocol;
515
- debuggerInfo.originalSourceURLAddress =
516
- this.#deviceRelativeBaseUrl.hostname;
526
+ debuggerInfo.originalSourceURLOrigin =
527
+ this.#deviceRelativeBaseUrl.origin;
517
528
  payload.params.sourceMapURL = debuggerRelativeURL.href;
518
529
  }
519
530
  try {
@@ -529,18 +540,18 @@ class Device {
529
540
  }
530
541
  }
531
542
  if ("url" in params) {
532
- const originalParamsUrl = params.url;
533
- let serverRelativeUrl = originalParamsUrl;
534
- const parsedUrl = this.#tryParseHTTPURL(originalParamsUrl);
543
+ let serverRelativeUrl = params.url;
544
+ const parsedUrl = this.#tryParseHTTPURL(params.url);
535
545
  if (
536
546
  parsedUrl &&
537
547
  parsedUrl.origin === this.#deviceRelativeBaseUrl.origin &&
538
548
  REWRITE_HOSTS_TO_LOCALHOST.has(this.#deviceRelativeBaseUrl.hostname)
539
549
  ) {
540
- parsedUrl.hostname = "localhost";
550
+ parsedUrl.host = debuggerInfo.debuggerRelativeBaseUrl.host;
551
+ parsedUrl.protocol = debuggerInfo.debuggerRelativeBaseUrl.protocol;
541
552
  payload.params.url = parsedUrl.href;
542
- debuggerInfo.originalSourceURLAddress =
543
- this.#deviceRelativeBaseUrl.hostname;
553
+ debuggerInfo.originalSourceURLOrigin =
554
+ this.#deviceRelativeBaseUrl.origin;
544
555
  parsedUrl.host = this.#serverRelativeBaseUrl.host;
545
556
  parsedUrl.protocol = this.#serverRelativeBaseUrl.protocol;
546
557
  serverRelativeUrl = parsedUrl.href;
@@ -618,37 +629,44 @@ class Device {
618
629
  }
619
630
  }
620
631
  #processDebuggerSetBreakpointByUrl(req, debuggerInfo) {
621
- if (debuggerInfo.originalSourceURLAddress != null) {
622
- const processedReq = {
623
- ...req,
624
- params: {
625
- ...req.params,
626
- },
627
- };
628
- if (processedReq.params.url != null) {
629
- processedReq.params.url = processedReq.params.url.replace(
630
- "localhost",
631
- debuggerInfo.originalSourceURLAddress
632
- );
633
- if (
634
- processedReq.params.url &&
635
- processedReq.params.url.startsWith(FILE_PREFIX) &&
636
- debuggerInfo.prependedFilePrefix
637
- ) {
638
- processedReq.params.url = processedReq.params.url.slice(
639
- FILE_PREFIX.length
640
- );
641
- }
642
- }
643
- if (processedReq.params.urlRegex != null) {
644
- processedReq.params.urlRegex = processedReq.params.urlRegex.replace(
645
- /localhost/g,
646
- debuggerInfo.originalSourceURLAddress
632
+ const {
633
+ debuggerRelativeBaseUrl,
634
+ originalSourceURLOrigin,
635
+ prependedFilePrefix,
636
+ } = debuggerInfo;
637
+ const processedReq = {
638
+ ...req,
639
+ params: {
640
+ ...req.params,
641
+ },
642
+ };
643
+ if (originalSourceURLOrigin != null && processedReq.params.url != null) {
644
+ processedReq.params.url = processedReq.params.url.replace(
645
+ debuggerRelativeBaseUrl.origin,
646
+ originalSourceURLOrigin
647
+ );
648
+ if (
649
+ processedReq.params.url &&
650
+ processedReq.params.url.startsWith(FILE_PREFIX) &&
651
+ prependedFilePrefix
652
+ ) {
653
+ processedReq.params.url = processedReq.params.url.slice(
654
+ FILE_PREFIX.length
647
655
  );
648
656
  }
649
- return processedReq;
650
657
  }
651
- return req;
658
+ if (
659
+ REWRITE_HOSTS_TO_LOCALHOST.has(this.#deviceRelativeBaseUrl.hostname) &&
660
+ this.#deviceRelativeBaseUrl.port === debuggerRelativeBaseUrl.port &&
661
+ debuggerRelativeBaseUrl.hostname === "localhost" &&
662
+ processedReq.params.urlRegex != null
663
+ ) {
664
+ processedReq.params.urlRegex = processedReq.params.urlRegex.replaceAll(
665
+ "localhost",
666
+ this.#deviceRelativeBaseUrl.hostname.replaceAll(".", "\\.")
667
+ );
668
+ }
669
+ return processedReq;
652
670
  }
653
671
  #processDebuggerGetScriptSource(req, socket) {
654
672
  const sendSuccessResponse = (scriptSource) => {
@@ -40,7 +40,8 @@ declare export default class Device {
40
40
  handleDebuggerConnection(
41
41
  socket: WS,
42
42
  pageId: string,
43
- metadata: $ReadOnly<{
43
+ $ReadOnly<{
44
+ debuggerRelativeBaseUrl: URL,
44
45
  userAgent: string | null,
45
46
  }>
46
47
  ): void;
@@ -190,6 +190,8 @@ class InspectorProxy {
190
190
  const query = _url.default.parse(req.url || "", true).query || {};
191
191
  const deviceId = query.device;
192
192
  const pageId = query.page;
193
+ const debuggerRelativeBaseUrl =
194
+ (0, _getBaseUrlFromRequest.default)(req) ?? this.#serverBaseUrl;
193
195
  if (deviceId == null || pageId == null) {
194
196
  throw new Error("Incorrect URL - must provide device and page IDs");
195
197
  }
@@ -199,6 +201,7 @@ class InspectorProxy {
199
201
  }
200
202
  this.#startHeartbeat(socket, DEBUGGER_HEARTBEAT_INTERVAL_MS);
201
203
  device.handleDebuggerConnection(socket, pageId, {
204
+ debuggerRelativeBaseUrl,
202
205
  userAgent: req.headers["user-agent"] ?? query.userAgent ?? null,
203
206
  });
204
207
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native/dev-middleware",
3
- "version": "0.77.0-nightly-20241121-550b0c0ed",
3
+ "version": "0.77.0-nightly-20241122-e4d8c9678",
4
4
  "description": "Dev server middleware for React Native",
5
5
  "keywords": [
6
6
  "react-native",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "@isaacs/ttlcache": "^1.4.1",
26
- "@react-native/debugger-frontend": "0.77.0-nightly-20241121-550b0c0ed",
26
+ "@react-native/debugger-frontend": "0.77.0-nightly-20241122-e4d8c9678",
27
27
  "chrome-launcher": "^0.15.2",
28
28
  "chromium-edge-launcher": "^0.2.0",
29
29
  "connect": "^3.6.5",