Skip to content

Commit 2542c6a

Browse files
fix<material UI> (#79)
* fix<github-issue, mui>
1 parent 7accb05 commit 2542c6a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/click-to-react-component/src/getSourceForElement.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getReactInstanceForElement } from './getReactInstanceForElement.js'
2-
import { getSourceForInstance } from './getSourceForInstance.js'
1+
import { getReactInstanceForElement } from './getReactInstanceForElement'
2+
import { getSourceForInstance } from './getSourceForInstance'
33

44
/**
55
* @typedef {import('react-reconciler').Fiber} Fiber
@@ -16,5 +16,17 @@ export function getSourceForElement(
1616

1717
if (source) return source
1818

19-
console.warn("Couldn't find a React instance for the element", element)
19+
const fallbackSource = getFirstParentElementWithSource(element)
20+
return fallbackSource
21+
}
22+
23+
function getFirstParentElementWithSource(element) {
24+
const parentElement = element.parentElement
25+
if (parentElement === null) throw new Error('No parent found')
26+
27+
const instance = getReactInstanceForElement(parentElement)
28+
const source = getSourceForInstance(instance)
29+
30+
if (source) return source
31+
else return getFirstParentElementWithSource(element)
2032
}

0 commit comments

Comments
 (0)