fix<material UI> (#79)

* fix<github-issue, mui>
This commit is contained in:
Leonidas
2023-12-13 18:34:18 +01:00
committed by GitHub
parent 7accb05c0e
commit 2542c6af39

View File

@@ -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
@@ -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)
}