Skip to content

Commit bd1bb90

Browse files
committed
Inject react-art renderer into react-devtools
This commit makes react-art renderer to be injected to react-devtools, so that component tree of the renderer is presented on debug panel of browser.
1 parent 2a2ef7e commit bd1bb90

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

packages/react-art/src/ReactART.js

+9
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
*/
77

88
import React from 'react';
9+
import ReactVersion from 'shared/ReactVersion';
910
import * as ARTRenderer from 'react-reconciler/inline.art';
1011
import Transform from 'art/core/transform';
1112
import Mode from 'art/modes/current';
1213
import FastNoSideEffects from 'art/modes/fast-noSideEffects';
1314

1415
import {TYPES, childrenAsString} from './ReactARTInternals';
16+
import * as ReactARTComponentTree from './ReactARTComponentTree';
1517

1618
Mode.setCurrent(
1719
// Change to 'art/modes/dom' for easier debugging via SVG
@@ -131,6 +133,13 @@ class Text extends React.Component {
131133
}
132134
}
133135

136+
ARTRenderer.injectIntoDevTools({
137+
findFiberByHostInstance: ReactARTComponentTree.getClosestInstanceFromNode,
138+
bundleType: __DEV__ ? 1 : 0,
139+
version: ReactVersion,
140+
rendererPackageName: 'react-art-renderer',
141+
});
142+
134143
/** API */
135144

136145
export const ClippingRectangle = TYPES.CLIPPING_RECTANGLE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
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+
8+
import {HostComponent, HostText} from 'shared/ReactTypeOfWork';
9+
10+
const randomKey = Math.random()
11+
.toString(36)
12+
.slice(2);
13+
const internalInstanceKey = '__reactInternalInstance$' + randomKey;
14+
15+
export function precacheFiberNode(hostInst, node) {
16+
node[internalInstanceKey] = hostInst;
17+
}
18+
19+
export function getClosestInstanceFromNode(node) {
20+
if (node[internalInstanceKey]) {
21+
return node[internalInstanceKey];
22+
}
23+
24+
while (!node[internalInstanceKey]) {
25+
if (node.parentNode) {
26+
node = node.parentNode;
27+
} else {
28+
// Top of the tree. This node must not be part of a React tree (or is
29+
// unmounted, potentially).
30+
return null;
31+
}
32+
}
33+
34+
let inst = node[internalInstanceKey];
35+
if (inst.tag === HostComponent || inst.tag === HostText) {
36+
// In Fiber, this will always be the deepest root.
37+
return inst;
38+
}
39+
40+
return null;
41+
}

packages/react-art/src/ReactARTHostConfig.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
*/
77

88
import * as ReactScheduler from 'shared/ReactScheduler';
9+
import * as ReactARTComponentTree from './ReactARTComponentTree';
910
import Transform from 'art/core/transform';
1011
import Mode from 'art/modes/current';
1112
import invariant from 'shared/invariant';
1213

1314
import {TYPES, EVENT_TYPES, childrenAsString} from './ReactARTInternals';
1415

16+
const {precacheFiberNode} = ReactARTComponentTree;
1517
const pooledTransform = new Transform();
1618

1719
const NO_CONTEXT = {};
@@ -251,7 +253,13 @@ export function appendInitialChild(parentInstance, child) {
251253
child.inject(parentInstance);
252254
}
253255

254-
export function createInstance(type, props, internalInstanceHandle) {
256+
export function createInstance(
257+
type,
258+
props,
259+
rootContainerInstance,
260+
hostContext,
261+
internalInstanceHandle,
262+
) {
255263
let instance;
256264

257265
switch (type) {
@@ -281,13 +289,15 @@ export function createInstance(type, props, internalInstanceHandle) {
281289
invariant(instance, 'ReactART does not support the type "%s"', type);
282290

283291
instance._applyProps(instance, props);
292+
precacheFiberNode(internalInstanceHandle, instance);
284293

285294
return instance;
286295
}
287296

288297
export function createTextInstance(
289298
text,
290299
rootContainerInstance,
300+
hostContext,
291301
internalInstanceHandle,
292302
) {
293303
return text;

0 commit comments

Comments
 (0)