-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: when creating root, check if canvas is rendered into another window
- Loading branch information
Showing
2 changed files
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function getIsCanvasElement(target: HTMLElement): target is HTMLCanvasElement { | ||
if (target instanceof HTMLCanvasElement) return true; | ||
|
||
/** | ||
* In case Application is rendered into another window (created with window.open() and rendered into it using React portal) | ||
* canvas is instance of openedWindow.HTMLCanvasElement, not global window.HTMLCanvasElement | ||
* | ||
* Thus we need to check for that. | ||
*/ | ||
const OwnerWindowHTMLCanvasElement = target?.ownerDocument?.defaultView?.HTMLCanvasElement; | ||
|
||
if (!OwnerWindowHTMLCanvasElement) return false; | ||
|
||
return target instanceof OwnerWindowHTMLCanvasElement; | ||
} |