Correctly handle different javascript realms/documents#4330
Correctly handle different javascript realms/documents#4330
Conversation
3f369cf to
91c211e
Compare
For shadowDom compat, may later also be a ShadowRoot
91c211e to
903c913
Compare
|
I've marked this as open, since it can already be reviewed and tested, but keep in mind that the E2E test will fail in Firefox until parchment is updated. (slab/parchment#147) For local testing, the package.json can be modified to load parchment from a local checkout of that branch. |
|
This probably would finally let quill be used in SSR-based environments ( zenoamaro/react-quill#919 ). Any idea if @slab is still maintaining this project? Wondering if it should be forked instead. |
|
@jtomaszewski It definitly has some overlap with shadow DOM support. If there are changes that need to be done to get this merged, I'd be willing to make them. |
|
Currently this package can't be imported on SSR because it blows up with I wouldn't be surprised if your changes fixed the references to objects such as |
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.openor 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
documentcan lead to incorrect results andinstanceofunexpectedly returningfalse. 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,
nodesown references to theirownerDocument, which has a reference to theirdefaultView, making it possible to write code that survives these conditions.This PR removes the expectation that
documentis the only document that can exist and fixesinstanceofchecks.This requires slab/parchment#147 to work properly.
After this is merged, I will try to expand it to supporting shadowDOM as well, most of the basics are there, but it needs some bigger Emitter changes and don't really fit here. But this does already lay some groundwork and can clarify what tests will be needed for testing Quill in non-standard contexts.