Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle different javascript realms/documents #147

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

edave64
Copy link

@edave64 edave64 commented Jul 18, 2024

In JavaScript, multiple different global contexts (realms) can exist with their own classes and document (https://tc39.es/ecma262/#realm) and they can access each others objects.

These realms are created by calls to window.open or when using <iframe>s. An application I am working on enables multi-monitor support by opening multiple browser windows that are all controlled from the primary tab. And Quill does not function correctly when initialized in one of these external windows.

This can lead to very unintuitive behavior, since using the global document can lead to incorrect results and instanceof unexpectedly returning false. And because of https://bugzilla.mozilla.org/show_bug.cgi?id=1470017 in FireFox, we cannot even control what realm our initial objects are part of.

Luckily, nodes own references to their ownerDocument, which has a reference to their defaultView, making it possible to write code that survives these conditions.

This PR removes the expectation that document is the only document that can exist and fixes an instanceof Element, that were hindering Quill from working correctly when initializing it in an iframe.

The Quill PR is prepared, but parchment needs to be updated for the E2E tests to pass in Firefox.

This does not support elements coming from a third realm, different from the one we are running and the one the document belongs to, but this is even less common than having to deal with crossrealm elements to begin with. (And impossible on Firefox)
@edave64 edave64 marked this pull request as ready for review July 25, 2024 07:19
@edave64 edave64 changed the title WIP: Correctly handle different javascript realms/documents Correctly handle different javascript realms/documents Jul 25, 2024
@luin luin self-requested a review July 25, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant