Skip to content

Commit 5854587

Browse files
author
Brian Vaughn
committed
Add stylex metadata to new plugins field
And display it separately in DevTools, as read-only (for now)
1 parent 578853e commit 5854587

File tree

7 files changed

+110
-1
lines changed

7 files changed

+110
-1
lines changed

packages/react-devtools-shared/src/backend/legacy/renderer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ export function attach(
838838
rootType: null,
839839
rendererPackageName: null,
840840
rendererVersion: null,
841+
842+
plugins: [],
841843
};
842844
}
843845

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import type {
102102
NativeType,
103103
PathFrame,
104104
PathMatch,
105+
Plugin,
105106
ProfilingDataBackend,
106107
ProfilingDataForRootBackend,
107108
ReactRenderer,
@@ -3238,12 +3239,17 @@ export function attach(
32383239
targetErrorBoundaryID = getNearestErrorBoundaryID(fiber);
32393240
}
32403241

3242+
const plugins: Array<Plugin> = [];
3243+
32413244
const modifiedProps = {
32423245
...memoizedProps,
32433246
};
32443247
if (enableStyleXFeatures) {
32453248
if (modifiedProps.hasOwnProperty('xstyle')) {
3246-
modifiedProps.xstyle = getStyleXValues(modifiedProps.xstyle);
3249+
plugins.push({
3250+
type: 'stylex',
3251+
data: getStyleXValues(modifiedProps.xstyle),
3252+
});
32473253
}
32483254
}
32493255

@@ -3306,6 +3312,8 @@ export function attach(
33063312
rootType,
33073313
rendererPackageName: renderer.rendererPackageName,
33083314
rendererVersion: renderer.version,
3315+
3316+
plugins,
33093317
};
33103318
}
33113319

packages/react-devtools-shared/src/backend/types.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ export type OwnersList = {|
213213
owners: Array<SerializedElement> | null,
214214
|};
215215

216+
// For now, let's only support a hard-coded set of plugins.
217+
type PluginType = 'stylex';
218+
219+
export type Plugin = {
220+
type: PluginType,
221+
data: any,
222+
};
223+
216224
export type InspectedElement = {|
217225
id: number,
218226

@@ -265,6 +273,9 @@ export type InspectedElement = {|
265273
// Meta information about the renderer that created this element.
266274
rendererPackageName: string | null,
267275
rendererVersion: string | null,
276+
277+
// Let's try this
278+
plugins: Array<Plugin>,
268279
|};
269280

270281
export const InspectElementErrorType = 'error';

packages/react-devtools-shared/src/backendAPI.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ export function convertInspectedElementBackendToFrontend(
208208
owners,
209209
context,
210210
hooks,
211+
plugins,
211212
props,
212213
rendererPackageName,
213214
rendererVersion,
@@ -233,6 +234,7 @@ export function convertInspectedElementBackendToFrontend(
233234
hasLegacyContext,
234235
id,
235236
key,
237+
plugins,
236238
rendererPackageName,
237239
rendererVersion,
238240
rootType,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
import * as React from 'react';
11+
import KeyValue from './KeyValue';
12+
import Store from '../../store';
13+
import styles from './InspectedElementSharedStyles.css';
14+
15+
import type {InspectedElement} from './types';
16+
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
17+
import type {Element} from 'react-devtools-shared/src/devtools/views/Components/types';
18+
19+
type Props = {|
20+
bridge: FrontendBridge,
21+
element: Element,
22+
inspectedElement: InspectedElement,
23+
store: Store,
24+
|};
25+
26+
export default function InspectedElementStyleXPlugin({
27+
bridge,
28+
element,
29+
inspectedElement,
30+
store,
31+
}: Props) {
32+
const styleXPlugin = inspectedElement.plugins.find(
33+
({type}) => type === 'stylex',
34+
);
35+
if (styleXPlugin == null || styleXPlugin.data == null) {
36+
return null;
37+
}
38+
39+
return (
40+
<div className={styles.InspectedElementTree}>
41+
<div className={styles.HeaderRow}>
42+
<div className={styles.Header}>stylex</div>
43+
</div>
44+
{Object.entries(styleXPlugin.data).map(([name, value]) => (
45+
<KeyValue
46+
key={name}
47+
alphaSort={true}
48+
bridge={bridge}
49+
canDeletePaths={false}
50+
canEditValues={false}
51+
canRenamePaths={false}
52+
depth={1}
53+
element={element}
54+
hidden={false}
55+
inspectedElement={inspectedElement}
56+
name={name}
57+
path={[name]}
58+
pathRoot="stylex"
59+
store={store}
60+
value={value}
61+
/>
62+
))}
63+
</div>
64+
);
65+
}

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementView.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import InspectedElementErrorsAndWarningsTree from './InspectedElementErrorsAndWa
2323
import InspectedElementHooksTree from './InspectedElementHooksTree';
2424
import InspectedElementPropsTree from './InspectedElementPropsTree';
2525
import InspectedElementStateTree from './InspectedElementStateTree';
26+
import InspectedElementStyleXPlugin from './InspectedElementStyleXPlugin';
2627
import InspectedElementSuspenseToggle from './InspectedElementSuspenseToggle';
2728
import NativeStyleEditor from './NativeStyleEditor';
2829
import Badge from './Badge';
@@ -31,6 +32,7 @@ import {
3132
copyInspectedElementPath as copyInspectedElementPathAPI,
3233
storeAsGlobal as storeAsGlobalAPI,
3334
} from 'react-devtools-shared/src/backendAPI';
35+
import {enableStyleXFeatures} from 'react-devtools-feature-flags';
3436

3537
import styles from './InspectedElementView.css';
3638

@@ -124,6 +126,15 @@ export default function InspectedElementView({
124126
store={store}
125127
/>
126128

129+
{enableStyleXFeatures && (
130+
<InspectedElementStyleXPlugin
131+
bridge={bridge}
132+
element={element}
133+
inspectedElement={inspectedElement}
134+
store={store}
135+
/>
136+
)}
137+
127138
<InspectedElementErrorsAndWarningsTree
128139
bridge={bridge}
129140
element={element}

packages/react-devtools-shared/src/devtools/views/Components/types.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ export type InspectedElementResponseType =
6464
| 'no-change'
6565
| 'not-found';
6666

67+
// For now, let's only support a hard-coded set of plugins.
68+
type PluginType = 'stylex';
69+
70+
export type Plugin = {
71+
type: PluginType,
72+
data: any,
73+
};
74+
6775
export type InspectedElement = {|
6876
id: number,
6977

@@ -114,6 +122,8 @@ export type InspectedElement = {|
114122
// Meta information about the renderer that created this element.
115123
rendererPackageName: string | null,
116124
rendererVersion: string | null,
125+
126+
plugins: Array<Plugin>,
117127
|};
118128

119129
// TODO: Add profiling type

0 commit comments

Comments
 (0)