Skip to content

Commit d143839

Browse files
committed
Add getPublicInstance to support TestRenderer createNodeMock
1 parent 2c4500b commit d143839

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/renderers/shared/fiber/ReactFiberCommitWork.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ module.exports = function<T, P, I, TI, C, CX>(
8686
function attachRef(current : ?Fiber, finishedWork : Fiber, instance : any) {
8787
const ref = finishedWork.ref;
8888
if (ref && (!current || current.ref !== ref)) {
89-
ref(instance);
89+
if (typeof config.getPublicInstance === 'function') {
90+
ref(config.getPublicInstance(instance));
91+
} else {
92+
ref(instance);
93+
}
9094
}
9195
}
9296

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export type HostConfig<T, P, I, TI, C, CX> = {
4747

4848
getRootHostContext(rootContainerInstance : C) : CX,
4949
getChildHostContext(parentHostContext : CX, type : T) : CX,
50+
getPublicInstance(instance : I) : I | any,
5051

5152
createInstance(type : T, props : P, rootContainerInstance : C, hostContext : CX, internalInstanceHandle : OpaqueNode) : I,
5253
appendInitialChild(parentInstance : I, child : I | TI) : void,

src/renderers/testing/fiber/ReactTestFiberRenderer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ var TestRenderer = ReactFiberReconciler({
229229
scheduleDeferredCallback: window.requestIdleCallback,
230230

231231
useSyncScheduling: true,
232+
233+
getPublicInstance(ref) {
234+
const createNodeMock = ref.rootContainerInstance.createNodeMock;
235+
return createNodeMock(ref);
236+
},
237+
232238
});
233239

234240
var defaultTestOptions = {

0 commit comments

Comments
 (0)