Skip to content

Commit b2cff47

Browse files
authored
[DevTools] feat: propagate fetchFileWithCaching from initialization options for Fusebox (facebook#34429)
Each integrator: browser extension, Chrome DevTools Frontend fork, Electron shell must define and provide `fetchFileWithCaching` in order for DevTools to be able to fetch application resources, such as scripts or source maps. More specifically, if this is available, React DevTools will be able to symbolicate source locations for component frames, owner stacks, "suspended by" Promises call frames. This will be available with the next release of React DevTools.
1 parent 8943025 commit b2cff47

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

packages/react-devtools-fusebox/src/frontend.d.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
export type MessagePayload = null | string | number | boolean | { [key: string]: MessagePayload } | MessagePayload[];
9-
export type Message = { event: string, payload?: MessagePayload };
8+
export type MessagePayload =
9+
| null
10+
| string
11+
| number
12+
| boolean
13+
| {[key: string]: MessagePayload}
14+
| MessagePayload[];
15+
export type Message = {event: string; payload?: MessagePayload};
1016

1117
export type WallListener = (message: Message) => void;
1218
export type Wall = {
13-
listen: (fn: WallListener) => Function,
14-
send: (event: string, payload?: MessagePayload) => void,
19+
listen: (fn: WallListener) => Function;
20+
send: (event: string, payload?: MessagePayload) => void;
1521
};
1622

1723
export type Bridge = {
@@ -22,7 +28,7 @@ export type Bridge = {
2228
export type Store = Object;
2329
export type BrowserTheme = 'dark' | 'light';
2430
export type Config = {
25-
supportsReloadAndProfile?: boolean,
31+
supportsReloadAndProfile?: boolean;
2632
};
2733

2834
export function createBridge(wall: Wall): Bridge;
@@ -55,15 +61,23 @@ export type CanViewElementSource = (
5561
source: ReactFunctionLocation | ReactCallSite,
5662
symbolicatedSource: ReactFunctionLocation | ReactCallSite | null,
5763
) => boolean;
64+
export type FetchFileWithCaching = (url: string) => Promise<string>;
5865

5966
export type InitializationOptions = {
60-
bridge: Bridge,
61-
store: Store,
62-
theme?: BrowserTheme,
63-
viewAttributeSourceFunction?: ViewAttributeSource,
64-
viewElementSourceFunction?: ViewElementSource,
65-
canViewElementSourceFunction?: CanViewElementSource,
67+
bridge: Bridge;
68+
store: Store;
69+
theme?: BrowserTheme;
70+
viewAttributeSourceFunction?: ViewAttributeSource;
71+
viewElementSourceFunction?: ViewElementSource;
72+
canViewElementSourceFunction?: CanViewElementSource;
73+
fetchFileWithCaching?: FetchFileWithCaching;
6674
};
6775

68-
export function initializeComponents(node: Element | Document, options: InitializationOptions): void;
69-
export function initializeProfiler(node: Element | Document, options: InitializationOptions): void;
76+
export function initializeComponents(
77+
node: Element | Document,
78+
options: InitializationOptions,
79+
): void;
80+
export function initializeProfiler(
81+
node: Element | Document,
82+
options: InitializationOptions,
83+
): void;

packages/react-devtools-fusebox/src/frontend.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
ViewAttributeSource,
2525
ViewElementSource,
2626
} from 'react-devtools-shared/src/devtools/views/DevTools';
27+
import type {FetchFileWithCaching} from 'react-devtools-shared/src/devtools/views/Components/FetchFileWithCachingContext';
2728
import type {Config} from 'react-devtools-shared/src/devtools/store';
2829

2930
export function createBridge(wall?: Wall): FrontendBridge {
@@ -50,6 +51,7 @@ type InitializationOptions = {
5051
viewAttributeSourceFunction?: ViewAttributeSource,
5152
viewElementSourceFunction?: ViewElementSource,
5253
canViewElementSourceFunction?: CanViewElementSource,
54+
fetchFileWithCaching?: FetchFileWithCaching,
5355
};
5456

5557
function initializeTab(
@@ -64,6 +66,7 @@ function initializeTab(
6466
viewAttributeSourceFunction,
6567
viewElementSourceFunction,
6668
canViewElementSourceFunction,
69+
fetchFileWithCaching,
6770
} = options;
6871
const root = createRoot(contentWindow);
6972

@@ -79,6 +82,7 @@ function initializeTab(
7982
viewAttributeSourceFunction={viewAttributeSourceFunction}
8083
viewElementSourceFunction={viewElementSourceFunction}
8184
canViewElementSourceFunction={canViewElementSourceFunction}
85+
fetchFileWithCaching={fetchFileWithCaching}
8286
/>,
8387
);
8488
}

0 commit comments

Comments
 (0)