Skip to content

Commit

Permalink
fix<material UI> (#79)
Browse files Browse the repository at this point in the history
* fix<github-issue, mui>
  • Loading branch information
LeonMueller-OneAndOnly authored Dec 13, 2023
1 parent 7accb05 commit 2542c6a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/click-to-react-component/src/getSourceForElement.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getReactInstanceForElement } from './getReactInstanceForElement.js'
import { getSourceForInstance } from './getSourceForInstance.js'
import { getReactInstanceForElement } from './getReactInstanceForElement'
import { getSourceForInstance } from './getSourceForInstance'

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

if (source) return source

console.warn("Couldn't find a React instance for the element", element)
const fallbackSource = getFirstParentElementWithSource(element)
return fallbackSource
}

function getFirstParentElementWithSource(element) {
const parentElement = element.parentElement
if (parentElement === null) throw new Error('No parent found')

const instance = getReactInstanceForElement(parentElement)
const source = getSourceForInstance(instance)

if (source) return source
else return getFirstParentElementWithSource(element)
}

0 comments on commit 2542c6a

Please sign in to comment.