Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 0ceecdb

Browse files
mmcotejasonLaster
authored andcommitted
Added recognition of react version 16 and greater components, and mod... (#5734)
1 parent 9ba3d19 commit 0ceecdb

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/actions/preview.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import type { AstLocation } from "../workers/parser";
2828

2929
async function getReactProps(evaluate) {
3030
const reactDisplayName = await evaluate(
31-
"this._reactInternalInstance.getName()"
31+
"this.hasOwnProperty('_reactInternalFiber') ? " +
32+
"this._reactInternalFiber.type.name : " +
33+
"this._reactInternalInstance.getName()"
3234
);
3335

3436
return {

src/actions/tests/preview.spec.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ describe("setPreview", () => {
9191
it("react instance", async () => {
9292
await setup("foo.js");
9393
evaluationResult = {
94-
this: react,
95-
"this._reactInternalInstance.getName()": "Foo"
94+
this: react
9695
};
96+
evaluationResult[
97+
"this.hasOwnProperty('_reactInternalFiber') ? " +
98+
"this._reactInternalFiber.type.name : " +
99+
"this._reactInternalInstance.getName()"
100+
] =
101+
"Foo";
97102

98103
await dispatch(
99104
actions.setPreview(

src/utils/preview.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ export function isReactComponent(result: Grip) {
3333
return;
3434
}
3535

36-
return Object.keys(ownProperties).includes("_reactInternalInstance");
36+
return (
37+
Object.keys(ownProperties).includes("_reactInternalInstance") ||
38+
Object.keys(ownProperties).includes("_reactInternalFiber")
39+
);
3740
}

0 commit comments

Comments
 (0)