Skip to content

Commit

Permalink
refactor URL construction (facebook#42948)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#42948

Changelog: [Internal]

Refactor URL construction for DevTools.

Next diffs in the stack will add additional URL query params.

Support for both absolute and relative `devServerUrl`s maintained.

Reviewed By: hoxyq

Differential Revision: D53620915

fbshipit-source-id: 4a64c49c3479ede2add9f39a24448787d8609172
  • Loading branch information
EdmondChuiHW authored and facebook-github-bot committed Feb 12, 2024
1 parent 54ad5b9 commit 7e3e768
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/dev-middleware/src/utils/getDevToolsFrontendUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ export default function getDevToolsFrontendUrl(
devServerUrl: string,
): string {
const scheme = new URL(webSocketDebuggerUrl).protocol.slice(0, -1);
const appUrl = `${devServerUrl}/debugger-frontend/rn_inspector.html`;
const webSocketUrlWithoutProtocol = encodeURIComponent(
webSocketDebuggerUrl.replace(/^wss?:\/\//, ''),
);
const appUrl = `${devServerUrl}/debugger-frontend/rn_inspector.html`;

const devToolsUrl = `${appUrl}?${scheme}=${webSocketUrlWithoutProtocol}&sources.hide_add_folder=true`;
const searchParams = new URLSearchParams([
[scheme, webSocketUrlWithoutProtocol],
['sources.hide_add_folder', 'true'],
]);
if (experiments.enableNetworkInspector) {
searchParams.append('unstable_enableNetworkPanel', 'true');
}

return experiments.enableNetworkInspector
? `${devToolsUrl}&unstable_enableNetworkPanel=true`
: devToolsUrl;
return appUrl + '?' + searchParams.toString();
}

0 comments on commit 7e3e768

Please sign in to comment.