Skip to content

fix(iframe): use window of current view in checking event instances - #5643

Closed
bilobom wants to merge 2 commits into
meta:mainfrom
bilobom:editor_window-on-iframe-portals
Closed

bilobom wants to merge 2 commits into
meta:mainfrom
bilobom:editor_window-on-iframe-portals

Conversation

@bilobom

@bilobom bilobom commented Feb 21, 2024 •

Copy link
Copy Markdown

conext

In checking for event prototype ancestry , lexical assumes the default window is the browser window.
example:

event instanceof DragEvent

this is like :

event instanceof window.DragEvent

This will fail and return false even thought the event is indeed a DragEvent because the event is an instance of the iframe window's DragEvent :

event instanceof iframe.contentWindow.DragEvent

instanceof checks for Prototype ancestry. When you ask is some event instanceof DragEvent it translate to

event.prototype === DragEvent

but

window.DragEvent !== iframe.contentWindow.DragEvent

PR

This pr tries to do the following:
1- Export getWindow function as utility throught @lexical/utils
2- Uses getWindow to access window whenever instanceof is used on constructor that belongs to window where editor resides

PoC maybe ??

Yes here is a link to code demonstating this :
https://stackblitz.com/edit/vitejs-vite-sfz7ft?file=src%2FApp.tsx

@vercel

vercel Bot commented Feb 21, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 11, 2024 3:03pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 11, 2024 3:03pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 21, 2024
Comment thread packages/lexical-utils/src/index.ts Outdated
* @param editor - The lexical editor
* @returns window of current default view
*/
export function getWindow(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of (or in addition to) this, we should just have something like our own implementation of instanceof:

function instanceOf(instance, target): boolean

which just gets the correct window in it's implementation.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how we can get the window from this function, we would need to get the target that blongs to window of current view beforehand :

function instanceOf(instance, target): boolean

usage:

const windowOfCurrentView =  getWindow(editor)
inctanceof(event, windowOfCurrentView.DrageEvent)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect, exporting the getWindow might help in other situations where properties of window/document are accessed .
examples:

window.getSelection()
document.caretRangeFromPoint
document.createRange()
window.createElement

we can see a number of PRs that addresses this issue and this function might help
see discussions here #4649
here also @zurfyx comment here #5547 (review)

I'm willing to go around and address this iframe issues and i believe this utility is usefull

@bilobom bilobom Mar 11, 2024 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acywatson I have used objectKlassEquals function introduced in #4649 , it's better than getWindow each time
can you review it again please ?

@bilobom

bilobom commented Mar 19, 2024 •

Copy link
Copy Markdown
Author

@acywatson , this is a gentle reminder of the fix, all comments been reviewed for a better solution by using objectKlassEquals.
can you review it please. we have paches that makes it hard to upgrade lexical .
thanks in advance

@etrepum etrepum added the stale-pr PRs that are closed due to staleness. Please reopen the PR if there are new updates label Dec 2, 2024
@etrepum

etrepum commented Dec 2, 2024

Copy link
Copy Markdown
Collaborator

Closing this PR due to staleness! If there are new updates, please reopen the PR.

@etrepum etrepum closed this Dec 2, 2024

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 393529ab Deployed Mar 11, 2024 by vercel[bot]
Preview – lexical — 393529ab Deployed Mar 11, 2024 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. stale-pr PRs that are closed due to staleness. Please reopen the PR if there are new updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants