Skip to content

Commit 42bf35f

Browse files
committed
fix(runtime): revert LogBox and dev-server changes
Restore runtime startup behavior from main and remove the playground LogBox regression test that depended on the reverted runtime API.
1 parent 581a5b9 commit 42bf35f

8 files changed

Lines changed: 26 additions & 217 deletions

File tree

apps/playground/src/__tests__/logbox-disabled.harness.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

packages/runtime/src/__tests__/logbox.test.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

packages/runtime/src/hmr.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/runtime/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import './globals.js';
33

44
export { createElement } from './jsx/jsx-runtime.js';
55
export { UI as ReactNativeHarness } from './ui/index.js';
6-
export { disableLogBoxUI, isLogBoxSuppressed } from './logbox.js';
76
export * from './spy/index.js';
87
export * from './expect/index.js';
98
export * from './collector/index.js';

packages/runtime/src/initialize.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { getDeviceDescriptor } from './client/getDeviceDescriptor.js';
22
import { getClient } from './client/index.js';
33
import { disableHMRWhenReady } from './disableHMRWhenReady.js';
4-
import { disableHMR } from './hmr.js';
5-
import { disableLogBoxUI } from './logbox.js';
64
import { setupJestMock } from './jest-mock.js';
75

86
// Polyfill for EventTarget on runtimes that don't ship one (RN's JSC).
@@ -22,13 +20,20 @@ if (typeof globalThis.EventTarget !== 'function') {
2220
// Setup jest mock to warn users about using Jest APIs
2321
setupJestMock();
2422

25-
disableLogBoxUI();
23+
// Turn off LogBox
24+
const { LogBox } = require('react-native');
25+
LogBox.ignoreAllLogs(true);
26+
27+
// Turn off HMR
28+
const HMRClientModule = require('react-native/Libraries/Utilities/HMRClient');
29+
const HMRClient =
30+
'default' in HMRClientModule ? HMRClientModule.default : HMRClientModule;
2631

2732
// Wait for HMRClient to be initialized
2833
setTimeout(() => {
2934
void (async () => {
3035
try {
31-
await disableHMRWhenReady(disableHMR, 50);
36+
await disableHMRWhenReady(() => HMRClient.disable(), 50);
3237
const handle = await getClient();
3338

3439
const deviceDescriptor = getDeviceDescriptor();

packages/runtime/src/logbox.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/runtime/src/react-native.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
declare module 'react-native/Libraries/Core/Devtools/getDevServer' {
2+
export type DevServerInfo = {
3+
url: string;
4+
fullBundleUrl?: string;
5+
bundleLoadedFromServer: boolean;
6+
};
7+
export default function getDevServer(): DevServerInfo;
8+
}
9+
110
declare module 'react-native/Libraries/Core/Devtools/parseErrorStack' {
211
export type StackFrame = {
312
column: number | null | undefined;
Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
import { Platform, TurboModuleRegistry } from 'react-native';
2-
3-
type SourceCodeModule = {
4-
getConstants: () => {
5-
scriptURL?: string;
6-
};
7-
};
8-
9-
const FALLBACK_DEV_SERVER_URL = 'http://localhost:8081/';
10-
11-
const getScriptURL = (): string | null => {
12-
const sourceCode = TurboModuleRegistry.get<SourceCodeModule>('SourceCode');
13-
return sourceCode?.getConstants()?.scriptURL ?? null;
14-
};
1+
import { Platform } from 'react-native';
2+
import getDevServer from 'react-native/Libraries/Core/Devtools/getDevServer';
153

164
export const getDevServerUrl = (): string => {
175
if (Platform.OS === 'web') {
18-
return `${window.location.origin}/`;
6+
// This is going to be the same as the current URL
7+
return window.location.origin + '/';
198
}
20-
21-
const scriptUrl = getScriptURL();
22-
const match = scriptUrl?.match(/^https?:\/\/.*?\//);
23-
return match?.[0] ?? FALLBACK_DEV_SERVER_URL;
9+
10+
11+
const devServer = getDevServer();
12+
return devServer.url;
2413
};

0 commit comments

Comments
 (0)