Skip to content

Commit 0271476

Browse files
bvaughngaearon
authored andcommitted
Fiber devtools fixes (#755)
* Fix a crash due to facebook/react#9013 Not sure if that one gets merged but it fixes other issues so it's likely. * Fix editing host styles in RN Also switch it to use the same `updater` code path both in Stack and Fiber. This removes knowledge about internal data structure from the frontend. * Fully fix editing RN styles * We shouldn't rely on the assumption that we're operating on current Fiber * The idea to unify updaters with setInProps() was a bad one because setNativeProps() signature is too different * Flow fixes; I think the correct thing to do is to use Dom's newer code over Dan's older code for setupBackend.
1 parent 2fd530f commit 0271476

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

backend/getData.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ function getData(internalInstance: Object): DataType {
120120
}
121121
}
122122

123+
if (typeof internalInstance.setNativeProps === 'function') {
124+
// For editing styles in RN
125+
updater = {
126+
setNativeProps(nativeProps) {
127+
internalInstance.setNativeProps(nativeProps);
128+
},
129+
};
130+
}
131+
123132
return {
124133
nodeType,
125134
type,

backend/getDataFiber.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ function getDataFiber(fiber: Object, getOpaqueNode: (fiber: Object) => Object):
8080
break;
8181
case HostComponent:
8282
nodeType = 'Native';
83-
name = fiber.type;
83+
name = typeof fiber.type === 'string' ?
84+
fiber.type :
85+
// Necessary for React Native Fiber if host types are not strings.
86+
// https://github.com/facebook/react/pull/9013
87+
getDisplayName(fiber.type);
8488
publicInstance = fiber.stateNode;
8589
props = fiber.memoizedProps;
8690
if (
@@ -91,6 +95,14 @@ function getDataFiber(fiber: Object, getOpaqueNode: (fiber: Object) => Object):
9195
} else {
9296
children = [];
9397
}
98+
if (typeof fiber.stateNode.setNativeProps === 'function') {
99+
// For editing styles in RN
100+
updater = {
101+
setNativeProps(nativeProps) {
102+
fiber.stateNode.setNativeProps(nativeProps);
103+
},
104+
};
105+
}
94106
break;
95107
case HostText:
96108
nodeType = 'Text';
@@ -134,7 +146,14 @@ function getDataFiber(fiber: Object, getOpaqueNode: (fiber: Object) => Object):
134146
}
135147

136148
function setInProps(fiber, path: Array<string | number>, value: any) {
137-
fiber.pendingProps = copyWithSet(fiber.memoizedProps, path, value);
149+
const inst = fiber.stateNode;
150+
fiber.pendingProps = copyWithSet(inst.props, path, value);
151+
if (fiber.alternate) {
152+
// We don't know which fiber is the current one because DevTools may bail out of getDataFiber() call,
153+
// and so the data object may refer to another version of the fiber. Therefore we update pendingProps
154+
// on both. I hope that this is safe.
155+
fiber.alternate.pendingProps = fiber.pendingProps;
156+
}
138157
fiber.stateNode.forceUpdate();
139158
}
140159

backend/types.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
*/
1111
'use strict';
1212

13+
type CompositeUpdater = {
14+
setInProps: ?(path: Array<string>, value: any) => void,
15+
setInState: ?(path: Array<string>, value: any) => void,
16+
setInContext: ?(path: Array<string>, value: any) => void,
17+
forceUpdate: ?() => void,
18+
};
19+
20+
type NativeUpdater = {
21+
setNativeProps: ?(nativeProps: {[key: string]: any}) => void,
22+
};
23+
1324
export type DataType = {
1425
nodeType: 'Native' | 'Wrapper' | 'NativeWrapper' | 'Composite' | 'Text' | 'Portal' | 'Empty',
1526
type: ?(string | AnyFn),
@@ -22,13 +33,7 @@ export type DataType = {
2233
context: ?Object,
2334
children: ?(string | Array<OpaqueNodeHandle>),
2435
text: ?string,
25-
updater: ?{
26-
setInProps: ?(path: Array<string>, value: any) => void,
27-
setInState: ?(path: Array<string>, value: any) => void,
28-
setInContext: ?(path: Array<string>, value: any) => void,
29-
// setState: ?(newState: any) => void,
30-
forceUpdate: ?() => void,
31-
},
36+
updater: ?(CompositeUpdater | NativeUpdater),
3237
publicInstance: ?Object,
3338
};
3439

0 commit comments

Comments
 (0)